apitrace / apitrace

Tools for tracing OpenGL, Direct3D, and other graphics APIs

Home Page:https://apitrace.github.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Commit cff22f0 Introduces Segfault

michaelkorenchan opened this issue · comments

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.

Thanks for the report.

@DziubanMaciej, could you please look into this?

Thanks for detailed report! I quickly reproduced it locally. This should fix the issue: #908

Sorry for inconvenience.

Merged. Thanks