fixed strlen-bomb in run_command

This commit is contained in:
Aaron Marcher 2016-08-15 12:59:45 +02:00 committed by Aaron Marcher (drkhsh)
parent 086a70cde0
commit df928892e8

View File

@ -453,6 +453,7 @@ ram_used(const char *null)
char * char *
run_command(const char* command) run_command(const char* command)
{ {
int good;
FILE *fp; FILE *fp;
char buffer[64]; char buffer[64];
@ -469,7 +470,15 @@ run_command(const char* command)
pclose(fp); pclose(fp);
/* add nullchar at the end */ /* add nullchar at the end */
for (int i = 0 ; i != sizeof(buffer) ; i++) {
if (buffer[i] == '\0') {
good = 1;
break;
}
}
if (good) {
buffer[strlen(buffer) - 1] = '\0'; buffer[strlen(buffer) - 1] = '\0';
}
/* return the output */ /* return the output */
return smprintf("%s", buffer); return smprintf("%s", buffer);