aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2023-07-31 16:22:06 +0200
committerColin Cross <ccross@android.com>2023-10-27 10:13:10 -0700
commita8cf756c56884b8f5c1151b888ca0386cefadcb0 (patch)
treed285bb48b7e2f2d64e45820c3ae130739ffe4e4e
parentefbceece33817facf746ddc378f33ae4cc602788 (diff)
downloadninja-a8cf756c56884b8f5c1151b888ca0386cefadcb0.tar.gz
UPSTREAM: Fix browse to work with Python 3.11+
Python sources should not contain null bytes, so don't pass the final string null terminator character to the python interpreter. Test: builds Bug: 307946202 (cherry picked from commit 67834978a6abdfb790dac165b8b1f1c93648e624) Change-Id: I9b205ae8137955c1841b1b56297e86a79ac550a1
-rw-r--r--src/browse.cc9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/browse.cc b/src/browse.cc
index c08c9f4..84026a6 100644
--- a/src/browse.cc
+++ b/src/browse.cc
@@ -69,8 +69,13 @@ void RunBrowsePython(State* state, const char* ninja_command,
close(pipefd[0]);
// Write the script file into the stdin of the Python process.
- ssize_t len = write(pipefd[1], kBrowsePy, sizeof(kBrowsePy));
- if (len < (ssize_t)sizeof(kBrowsePy))
+ // Only write n - 1 bytes, because Python 3.11 does not allow null
+ // bytes in source code anymore, so avoid writing the null string
+ // terminator.
+ // See https://github.com/python/cpython/issues/96670
+ auto kBrowsePyLength = sizeof(kBrowsePy) - 1;
+ ssize_t len = write(pipefd[1], kBrowsePy, kBrowsePyLength);
+ if (len < (ssize_t)kBrowsePyLength)
perror("ninja: write");
close(pipefd[1]);
exit(0);