Tainted string in C

前端 未结 3 1599
孤独总比滥情好
孤独总比滥情好 2021-01-19 02:18

I\'m running Coverity tool in my file operation function and getting the following error.

As you can see below, I\'m using an snprintf() before passing this variable

3条回答
  •  心在旅途
    2021-01-19 02:54

    Try the following:

    char* id_str = getenv("ID");
    if (id_str) {
       id_str = strdup(id_str);
       id = atoi(id_str);
       free( id_str );
    }
    

    The fn string passed to fopen is tainted by an environment variable. Using strdup may act as "sanitizing".

提交回复
热议问题