Skip to content

segmentation fault when execute_command and the stack overflow caused by parameters #40

Closed
@firmianay

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;
	}

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions