facebook / infer

A static analyzer for Java, C, C++, and Objective-C
http://fbinfer.com/
MIT License
14.83k stars 2k forks source link

Strncpy buffer overflow not detected #1714

Open tiwns opened 1 year ago

tiwns commented 1 year ago

include

include

char *src="demo";

int main(){ char dest[4]; strncpy(dest,src,sizeof(dest)); printf("str=%s\n",dest); }

I cannot get Infer to find the buffer overflow caused in strncpy(). Please advise.

mulle-kybernetik-tv commented 1 year ago

To be pedantic, technically there is no buffer overflow in strncpy here. The problem is that the code will pass a non \0 terminated string to printf( "%s") as strncpy won't append it, if there is no space.