banned.h: mark strncat() as banned
PATCH 1/1 banned.h: mark strncat() as banned
strncat() has the same quadratic behavior as strcat() and is difficult-to-read and bug-prone. While it hasn't yet been a problem in git iself, strncat() found it's way into 'master' of cgit and caused segfaults on my system.
--- banned.h | 2 ++ 1 file changed, 2 insertions(+)
banned.h +2 -0
@@ -16,6 +16,8 @@#define strcat (x,y) BANNED(strcat)#undef strncpy#define strncpy (x,y,n) BANNED(strncpy) +#undef strncat +#define strncat (x,y,n) BANNED(strncat)#undef sprintf#undef vsprintf
Signature · 1 line
EW
Quoted 4 lines · Eric Wong
strncat()has the same quadratic behavior asstrcat()and is difficult-to-read and bug-prone. While it hasn't yet been a problem in git iself,strncat()found it's way into 'master'
s/iself/itself/
Quoted 3 lines
of cgit and caused segfaults on my system.
Signed-off-by Eric Wong <[email protected]>
Quoted 4 lines · Eric Wong
strncat()has the same quadratic behavior asstrcat()and is difficult-to-read and bug-prone. While it hasn't yet been a problem in git iself,strncat()found it's way into 'master' of cgit and caused segfaults on my system.
I'm in favor of this.
It doesn't have the "oops, I didn't NUL-terminate for you" problem that strncpy() has. But it actually has the opposite problem! It will always place a NUL, and you have to feed it sizeof(dst)-1 to avoid an overflow.
So I think it's important for safety (though I'd be fine banning it on the quadratic grounds alone ;) ).
-Peff