TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Improving Security in the Latest C Programming Language Standard

39 pointsby m0nasticalmost 13 years ago

6 comments

revelationalmost 13 years ago
The _s family of functions is what MSVC has been forcing upon people by claiming all other functions deprecated.<p>So now the standard is lending nomenclatura and possibly implementation from the company that stoically refuses to implement C99.
评论 #4153037 未加载
kmmalmost 13 years ago
Using <i>strncpy</i> is not a remedy at all. The function was never designed for safe string copying, but for copying fixed-width inode names[1]. The fact that is protects against buffer overflows is pure coincidence.<p>[1]: <a href="http://stackoverflow.com/a/1454071" rel="nofollow">http://stackoverflow.com/a/1454071</a>
评论 #4152158 未加载
comexalmost 13 years ago
The only difference between strcpy_s and strlcpy, other than taking arguments in a different order and being more annoying to type, is that if an overflow would occur, it sets destination[0] to 0 rather than truncating. This is probably an improvement, since truncation can cause security problems if you're building filenames and such (though, should you fail the test accidentally, I suspect it's much harder to track down why a string somewhere in your app became empty than why it was truncated)... but is it really worth switching to yet another string copy function?<p>(well, from a BSD perspective. Apparently strcpy_s has been around on Windows since Windows 95.)
评论 #4153994 未加载
mjcohenwalmost 13 years ago
For years, I have been saying "In C, an array is a pointer, an offset, and a prayer."<p>Looks like I might have to change this.
TwoBitalmost 13 years ago
The author/site mentions that in practice snprintf isn't portable on Unix platforms because a number of implementations of it are botched. I have to say that one of the best things we did was implement our own conforming printf/scanf family of functions. They act the same everywhere, which isn't possible even with the existing conforming C library implementations, as the Standard is not precise about the specification.
reirobalmost 13 years ago
Does anybody know when GCC will support which features of C11?
评论 #4158880 未加载