Live data from Hacker News

Banned C standard library functions in Git source code

github.com

21–30 of 329 posts

Re: Banned C standard library functions in Git source code

#25

Why is there no brief explanations in this code why each function is banned?

None are properly length checked. strncpy() is for "binary" strings and can omit the NUL in addition to excessive zero padding large buffers.

Re: Banned C standard library functions in Git source code

#26
I'm glad to see that setjmp() and longjmp() are still allowed.

I'm just kidding by the way. For those C programmers who haven't encountered these before, it is a powerful way to do a "goto" in C. Powerful in the sense that you can jump anywhere, not limited to the same function. If it's used at all these days, it's used for exception handling.

More info: https://en.wikipedia.org/wiki/Setjmp.h

Re: Banned C standard library functions in Git source code

#27
post #11

Looks like Git has its own string type: https://github.com/git/git/blob/master/strbuf.h https://github.com/git/git/blob/master/strbuf.c See this for the story of why strncpy/strncat are insecure: https://en.wikipedia.org/wiki/C_string_handling#Replacements

Like essentially all C programs.

Re: Banned C standard library functions in Git source code

#28
post #5
post #2

I guess they care too much about portability to use "pragma GCC poison"?

Wanting code to compile on something other than gcc is not "caring too much", it's being responsible

For this particular case it wouldn't be a big deal. The code is still valid C, it's just that GCC makes sure that you don't use the poisoned values.

Re: Banned C standard library functions in Git source code

#30

For anybody else: Why is strncpy insecure? https://stackoverflow.com/questions/869883/why-is-strncpy-in... > strncpy() doesn't require NUL termination, and is therefore susceptible to a variety of exploits.

It also fills all remaining bytes (if any) with nuls. ‘N’ in its name is not the same ‘n’ as in snprintf etc. It could be named fldcpy, as it works with 0-padded fixed-width fields rather than 0-terminated strings.
Post reply on HN