系统(命令)以C语言返回2304。但为什么?

系统(命令)以C语言返回2304。但为什么?,c,system,C,System,我正试图编写一个程序,用蛮力打开zip文件。 然而,我有一个问题,我一直从系统调用中获取代码:2304。但我看不出为什么会这样,为什么没有执行命令。我的代码是C。所以有人能指导我找到解决方案吗 #include <stdio.h> #include <string.h> #include <stdlib.h> #include <unistd.h> // For checking file exist int crack(char* cmd, c

我正试图编写一个程序,用蛮力打开zip文件。 然而,我有一个问题,我一直从系统调用中获取代码:2304。但我看不出为什么会这样,为什么没有执行命令。我的代码是C。所以有人能指导我找到解决方案吗

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h> // For checking file exist

int crack(char* cmd, char* pass, char* file){
    int size = strlen(cmd) + strlen(pass) -1 + strlen(file) + 2;
    int result = -1;
    char* fullcmd = malloc(size);
    strcpy(fullcmd, cmd);
    strncat(fullcmd, " ", 1);
    strncat(fullcmd, pass, strlen(pass) -1 );
    strncat(fullcmd, " ", 1);
    strcat(fullcmd, file);
    //printf("Full Command: %s\n", fullcmd);
    result = system(fullcmd);
    //printf("Result: %d\n", (int) system(fullcmd));
    free(fullcmd);
    return result;
}


void setup(char* cmd, char* file){

    //Read passwords
    FILE* fp;
    char* pass = NULL;
    size_t len = 0;
    ssize_t read;

    fp = fopen("passwords.txt", "r");
    if(fp == NULL){
        exit(EXIT_FAILURE);
    }

    while((read = getline(&pass, &len, fp)) != -1){
        printf("trying password: %s\n", pass);
        if(crack(cmd, pass, file) != -1){
            printf("FILE cracked\n");
            //break;
        }

    }

    fclose(fp);
    if(pass){
        free(pass);
    }
}

//unzip -p password filename

int main(int argc, char *argv[]){
    char *file = argv[1];

    if(access(file, F_OK) == -1){
        printf("Something went wrong \n");
        exit(EXIT_FAILURE);
    }
    setup("unzip -p", file);

    exit(EXIT_SUCCESS);
}
password.txt文件包含0000到9999之间的所有数字组合

谢谢
阅读可能会有帮助。@JoachimPileborg我读过,应该写下抱歉。我仍然不知道我的系统调用失败了什么。虽然我可能错过了什么。但是从网络上的不同例子来看,我认为我做的是正确的,错误似乎是正在执行的命令返回。您是否可以尝试打印完整命令,尝试手动执行并检查结果状态?您没有占用足够的空间,因此导致缓冲区溢出,从而导致未定义的行为。使用snprintf代替所有的计算和strncat垃圾。您应该改变状态以获取返回的实际值,因为1位用于核心转储状态,在这种情况下,返回的值是9 2304>>8,这在解压帮助页面中意味着:找不到指定的zipfiles。