C Valgrind:未初始化的值是由堆栈分配创建的

时间:2019-05-19 08:36:14

标签: c valgrind

我用Valgrind查看我的代码是否有内存不足,但在passwdfkt函数中遇到了此错误。我不知道问题是什么或如何解决。该功能只应检查给定的密码是否正确,然后再检查另一个功能。

void passwdfkt(FILE **fpp, unsigned int process,unsigned int lines, struct passwdin **allocin, char ***arr)
{
    //----------------------------------------------
    //check password if $number$salt$hash correct
    //----------------------------------------------
    struct passwd *pwd = NULL;
    while((pwd = fgetpwent(*fpp))!= NULL)
    {
        char buffpwd[strlen(pwd->pw_passwd)];
        char *ret = strncpy(buffpwd, pwd->pw_passwd, strlen(pwd->pw_passwd));
        assert(*ret == buffpwd[0]);


        char *pass = NULL;
        pass = strtok(buffpwd,"$");

        char number[4][2]= {"1", "2a", "5", "6" };
        for(int j = 0; j < 4; j++)
        {
            if(strncmp(pass, number[j], sizeof (number [j]))== 0)
            {
                for(int i = 0; i<2; i++)
                {
                    pass = strtok(NULL,"$");
                    static int saltleng = 0;
                    if(i == 0 )
                    {
                        if(pass == NULL)
                            continue;
                       char * buff = &pass[0];
                        saltleng = 0;
                        while(*(buff+saltleng) != '\0')
                        {
                            saltleng++;
                        }
                    }
                    if(i == 1)
                    {
                        if(pass == NULL)
                            continue;
                        if(saltleng < 16)
                        {
                            createproc (process,lines,pwd, &allocin, &arr, fpp);
                        }
                    }
                }
            }
        }
    }
}

这是我从Valgrind得到的错误:

==2272== 1 errors in context 1 of 2:
==2272== Conditional jump or move depends on uninitialised value(s)
==2272==    at 0x492B78F: strtok_r (in /usr/lib64/libc-2.28.so)
==2272==    by 0x402A1D: passwdfkt (in /home/fhtw/Documents/FSST/passwd_crack/passwd)
==2272==    by 0x401D1B: main (in /home/fhtw/Documents/FSST/passwd_crack/passwd)
==2272== 
==2272== 
==2272== 1 errors in context 2 of 2:
==2272== Conditional jump or move depends on uninitialised value(s)
==2272==    at 0x4840CA8: strcspn (vg_replace_strmem.c:1736)
==2272==    by 0x492B788: strtok_r (in /usr/lib64/libc-2.28.so)
==2272==    by 0x402A1D: passwdfkt (in /home/fhtw/Documents/FSST/passwd_crack/passwd)
==2272==    by 0x401D1B: main (in /home/fhtw/Documents/FSST/passwd_crack/passwd)
==2272== 

==2553==  Uninitialised value was created by a stack allocation
==2553==    at 0x402901: passwdfkt (in /home/fhtw/Documents/FSST/passwd_crack/passwd)

0 个答案:

没有答案