Properly null-terminate the argv list created by sh.

This commit is contained in:
Andreas Kling 2018-10-26 15:04:20 +02:00
parent 1c45b28da6
commit 63e5583c18
2 changed files with 4 additions and 4 deletions

Binary file not shown.

View file

@ -74,19 +74,19 @@ static int runcmd(char* cmd)
memcpy(buf, cmd, 128);
const char* argv[32];
size_t argi = 1;
size_t argc = 1;
argv[0] = &buf[0];
size_t buflen = strlen(buf);
for (size_t i = 0; i < buflen; ++i) {
if (buf[i] == ' ') {
buf[i] = '\0';
argv[argi++] = &buf[i + 1];
argv[argc++] = &buf[i + 1];
}
}
argv[argi + 1] = nullptr;
argv[argc] = nullptr;
int retval = 0;
if (handle_builtin(argi, argv, retval)) {
if (handle_builtin(argc, argv, retval)) {
return 0;
}