From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Thu, 21 Dec 2023 19:44:15 +0000 (+0100) Subject: [3.12] gh-113343: Fix error check on mmap(2) (GH-113342) (#113374) X-Git-Tag: v3.12.2~281 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c38ebb40d195c0ed910c7d4a2f352676f64fa371;p=thirdparty%2FPython%2Fcpython.git [3.12] gh-113343: Fix error check on mmap(2) (GH-113342) (#113374) gh-113343: Fix error check on mmap(2) (GH-113342) Fix error check on mmap(2) It should check MAP_FAILED instead of NULL for error. On mmap(2) man page: RETURN VALUE On success, mmap() returns a pointer to the mapped area. On error, the value MAP_FAILED (that is, (void *) -1) is returned, and errno is set to indicate the error. (cherry picked from commit 6b70c3dc5ab2f290fcdbe474bcb7d6fdf29eae4c) Co-authored-by: Namhyung Kim --- diff --git a/Python/perf_trampoline.c b/Python/perf_trampoline.c index a91f4f82877b..ea9dc83dd0fd 100644 --- a/Python/perf_trampoline.c +++ b/Python/perf_trampoline.c @@ -247,7 +247,7 @@ new_code_arena(void) mem_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, // fd (not used here) 0); // offset (not used here) - if (!memory) { + if (memory == MAP_FAILED) { PyErr_SetFromErrno(PyExc_OSError); _PyErr_WriteUnraisableMsg( "Failed to create new mmap for perf trampoline", NULL);