相关疑难解决方法(0)

C中的污点字符串

我正在我的文件操作函数中运行Coverity工具并收到以下错误.

正如您在下面看到的,我在将有问题的变量传递给错误消息中显示的行号之前使用了snprintf().我想这个字符串的一些清理必须作为snprintf()的一部分来完成.但仍然显示警告.

Error:TAINTED_STRING (TAINTED string "fn" was passed to a tainted string sink content.) [coverity]

char fn[100]; int id = 0;
char* id_str = getenv("ID");
if (id_str) {
    id = atoi(id_str);
}
memset(fn, '\0', sizeof(fn));
snprintf(fn, 100, LOG_FILE, id);
if(fn[100-1] != '\0') {
     fn[100-1] = '\0';
}
log_fp = fopen (fn, "a");
Run Code Online (Sandbox Code Playgroud)

任何帮助将受到高度赞赏.

c string coverity

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

c ×1

coverity ×1

string ×1