OSDN Git Service

Append null byte to exPath.
authorRajeev Kumar <rajekumar@google.com>
Tue, 8 May 2018 21:14:30 +0000 (14:14 -0700)
committerRajeev Kumar <rajekumar@google.com>
Tue, 8 May 2018 22:16:09 +0000 (15:16 -0700)
Note: Without this fix on Android Go device exPath gets some junk chars at the end of exPath because readlink() does not append a null byte to buf.

Bug: 79430762
Test: Tested manually by running alloc-stress on Android Go device.

Change-Id: I8e09d8c6d670b7d29e7f98c00dd8e9e9c5492169

alloc-stress/alloc-stress.cpp

index fcb074b..1cd8fdd 100644 (file)
@@ -124,6 +124,9 @@ pid_t createProcess(Pipe pipe, const char *exName,
         ssize_t exPathLen = readlink("/proc/self/exe", exPath, sizeof(exPath));
         bool isExPathAvailable =
             exPathLen != -1 && exPathLen < static_cast<ssize_t>(sizeof(exPath));
+        if (isExPathAvailable) {
+          exPath[exPathLen] = '\0';
+        }
         execl(isExPathAvailable ? exPath : exName, exName, "--worker", arg, readFdStr, writeFdStr,
             use_memcg ? "1" : "0", nullptr);
         ASSERT_TRUE(0);