Commit cff22f0 Introduces Segfault
michaelkorenchan opened this issue · comments
Michael Korenchan commented
The commit "Fake command line arguments during replay, so they match traced program's arguments (#904)" introduced a segfault in a path I encountered in the following code it adds:
String
getProcessCommandLine(void)
{
String path;
size_t size = PATH_MAX;
char buf[size];
int fd = open("/proc/self/cmdline", O_RDONLY);
if (fd >= 0) {
size_t len = read(fd, buf, size);
close(fd);
if (len > 0) {
size_t start = strlen(buf) + 1;
size_t cmdlineLen = len - start;
char *pathBuf = path.buf(cmdlineLen);
for (size_t i = 0; i < cmdlineLen - 1; i++) {
char character = buf[start + i];
if (character == '\0') character = ' ';
pathBuf[i] = character;
}
}
}
return path;
}
In my case, the contents of /proc/self/cmdline
is a single string, leading len
and start
to be the same, so cmdlineLen
is 0 and the for loop goes forever until segfault.
José Fonseca commented
Thanks for the report.
@DziubanMaciej, could you please look into this?
Maciej commented
Thanks for detailed report! I quickly reproduced it locally. This should fix the issue: #908
Sorry for inconvenience.
José Fonseca commented
Merged. Thanks