From 67834978a6abdfb790dac165b8b1f1c93648e624 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Mon, 31 Jul 2023 16:22:06 +0200 Subject: [PATCH] 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. Fixes: #2310 --- src/browse.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/browse.cc b/src/browse.cc index 76bee070d8..ac54207800 100644 --- a/src/browse.cc +++ b/src/browse.cc @@ -71,8 +71,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);