Closed
Description
hi, great project!
I think it's better to limit the size of res, otherwise it may cause the program to crash, such as performing "cat /dev/random | od -x", which maybe unlikely in reality.
char *execute_command(char *command) {
FILE *fp;
char *res = calloc(4096, sizeof(char));
char buf[1024];
fp = popen(command, "r");
if (fp == NULL) {
perror("Failed to run command");
return NULL;
}
while (fgets(buf, sizeof(buf), fp) != NULL) {
strcat(res, buf);
}
// printf("RESULT OF COMMAND: %s\n", res);
pclose(fp);
return res;
}