Open x14ngch3n opened 1 year ago
Fortunately format string is not externally controlled, but should be fixed. Could you test the following code and tell me the infer command you used? It should have the same issue. I could not reproduce it on Ubuntu 20.0.4 File: test.c
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
void showVerbose(char *format,...)
{
va_list
args;
va_start(args,format);
vfprintf(stdout,format,args);
(void) fflush(stdout);
va_end(args);
va_start(args,format);
vfprintf(stdout,format,args);
(void) fflush(stdout);
va_end(args);
}
int main(int argc, char *argv[])
{
char
buf[1024];
(void) strncpy(buf,"this is a test\n",sizeof(buf)-1);
showVerbose(buf);
return(0);
}
infer --version
Infer version v1.1.0
Copyright 2009 - present Facebook. All Rights Reserved.
infer run -- gcc -g -Wall test.c
Capturing in make/cc mode...
Found 1 source file to analyze in /home/muquit/junk/infer-out
1/1 [################################################################################] 100% 56.294ms
No issues found
Thanks.
Hi, I'm currently trying to use the static analysis tool Infer to find uncatched API-misuse bugs in OpenWrt packages, and I find a potential Format String bug in your project, version 1.19.
The bug located in smtp.c. Firstly, the program read bytes from
fp
tobuf
usingfread()
in line 638, andbuf
is later used as the parameter ofshowVerbose()
in line 650, as shown in the following code:Inside
showVerbose()
, it directly callsvprintf()
twice time with the controlled buffer, which violates CWE134 and can cause undefined behavior.I also attached the analysis trace given by Infer FYI: