This post originated from an RSS feed registered with Ruby Buzz
by Daniel Berger.
Original Post: Security enhancements in the CRT
Feed Title: Testing 1,2,3...
Feed URL: http://djberg96.livejournal.com/data/rss
Feed Description: A blog on Ruby and other stuff.
It appears that Microsoft's VC++ 8 adds some handy functions to the CRT. Namely, it provides safe versions of standard CRT functions, such as strcpy().
The MSDN docs sum it up nicely:
For example, the strcpy function has no way of telling if the string that it is copying is too big for its destination buffer. However, its secure counterpart, strcpy_s, takes the size of the buffer as a parameter, so it can determine if a buffer overrun will occur. If you use strcpy_s to copy eleven characters into a ten-character buffer, that is an error on your part; strcpy_s cannot correct your mistake, but it can detect your error and inform you by invoking the invalid parameter handler.
So, now you can do stuff like this without having to add extra security code: