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
Banned C standard library functions in Git source code
41–50 of 329 posts
Re: Banned C standard library functions in Git source code
#42Why is there no brief explanations in this code why each function is banned?
I believe they're all vulnerable to overflows and easy to exploit. https://pointerless.wordpress.com/2012/02/26/strcpy-security...
strncpy pretends to be safe but fails to NULL-terminate and has other performance issues that generally lead me to believe it’s a security placebo. I would recommend using snprintf instead.
Re: Banned C standard library functions in Git source code
#43Looks like the second vsprintf definition should be "BANNED(vsprintf)", not "BANNED(sprintf)". Not that it matters much, as it only affects the error message.
> Git Source Code Mirror - This is a publish-only repository and all pull requests are ignored. Please follow https://github.com/git/git/blob/master/Documentation/Submitt... procedure for any of your improvements.
Re: Banned C standard library functions in Git source code
#44> strcpy ... BANNED But they cannot ban while (* p++ = * q++); now can they.
Re: Banned C standard library functions in Git source code
#45musl libc (an alternative libc) provides implementations of these functions that are memory-safe. (It only works on Linux though.)
Re: Banned C standard library functions in Git source code
#46Looks like the second vsprintf definition should be "BANNED(vsprintf)", not "BANNED(sprintf)". Not that it matters much, as it only affects the error message.
Re: Banned C standard library functions in Git source code
#47Looks like the second vsprintf definition should be "BANNED(vsprintf)", not "BANNED(sprintf)". Not that it matters much, as it only affects the error message.
Nice catch! You can send a "PR", but note that they have their own custom "PR" procedure, not the standard "PR" procedure in GitHub. > Git Source Code Mirror - This is a publish-only repository and all pull requests are ignored. Please follow https://github.com/git/git/blob/master/Documentation/Submitt... procedure for any of your improvements.
Re: Banned C standard library functions in Git source code
#48Earlier quoted context omitted.
I'm not an expert in C, but then what's the issue with strncpy() or any "n" functions? It prevents overflow AFAIK. Also what is the alternative (memcpy?) and why?
strncpy() does not guarantee that the copied string would be terminated with a null byte ('\0'). For a call that looks like strncpy(dst, src, n), if there is no null byte in the first n bytes of src, the string copied to dst would also not contain a null byte. Here is an example code to demonstrate the problem: #include #include int main() { char a[] = "01234567"; strncpy(a, "foobar", 4); printf("%.8s\n", a); return…
Re: Banned C standard library functions in Git source code
#49Re: Banned C standard library functions in Git source code
#50Why is there no brief explanations in this code why each function is banned?