[英]Segmentation Fault in C while using crypt function
I am new to programming in CI am trying to make a simple password cracking program but when I try to run it I get Segmentation Fault as an error. 我刚开始使用CI进行编程,试图制作一个简单的密码破解程序,但是当我尝试运行它时,我得到了Segmentation Fault作为错误。 Can someone solve the issue. 有人可以解决这个问题吗? Thanks in advance. 提前致谢。
#define _XOPEN_SOURCE
#include<stdio.h>
#include<crypt.h>
#include<unistd.h>
#include<string.h>
int main(int argc, char *argv[])
{
if(argc != 3)
{
printf("Usage: ./craken salt hash\n");
return 0;
}
FILE *fPointer;
fPointer = fopen("wordlist.txt", "r");
char singleLine[150];
while(fgets(singleLine, 150, fPointer) != NULL)
{
if(!strcmp(argv[2], crypt(singleLine, argv[1])))
{
printf("Password found! %s is the password\n", singleLine);
fclose(fPointer);
return 0;
}
}
printf("Not found\n");
fclose(fPointer);
return 0;
}
I guess the problem is that if you read out possible passwords out of you're file there is an newline at the end. 我想问题是,如果您从文件中读出可能的密码,则末尾会有换行符。 The crypt() function as I understand can only handle the set [a-zA-Z0-9./] ( crypt man page ) that might result in an NULL pointer being returned. 据我了解,crypt()函数只能处理可能导致返回NULL指针的[a-zA-Z0-9./](crypt 手册页 )集。 This NULL pointer than leads to a segmentation fault inside the strcmp() function. 然后,此NULL指针会导致strcmp()函数内部出现分段错误。 So try to remove that newline char at the end of each input line. 因此,请尝试在每个输入行的末尾删除该换行符。 Hope this works 希望这行得通
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.