From: Ronald Oussoren <ronaldoussoren@mac.com>
Date: Wed, 22 Aug 2012 12:24:14 +0000 (+0200)
Subject: Fix for issue 15716: interpreter could crash when PYTHONEXECUTABLE was set on Mac... 
X-Git-Tag: v3.3.0rc1~43^2
X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=eb61f8b3a726a8cd1ae3bc3794623e7fe4dd5703;p=python

Fix for issue 15716: interpreter could crash when PYTHONEXECUTABLE was set on Mac OS X.

This is due to an off-by-one error: the allocated buffer didn't have room for a NUL
character at the end of the mbstowcs result.
---

diff --git a/Misc/NEWS b/Misc/NEWS
index 87a89fbbc1..a9c96950f8 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,8 @@ What's New in Python 3.2.4
 Core and Builtins
 -----------------
 
+- Issue #15761: Fix crash when PYTHONEXECUTABLE is set on Mac OS X.
+
 - Issue #15726: Fix incorrect bounds checking in PyState_FindModule.
   Patch by Robin Schreiber.
 
diff --git a/Modules/main.c b/Modules/main.c
index 5b4a7e2e64..5d1d8964bf 100644
--- a/Modules/main.c
+++ b/Modules/main.c
@@ -616,7 +616,7 @@ Py_Main(int argc, wchar_t **argv)
        script. */
     if ((p = Py_GETENV("PYTHONEXECUTABLE")) && *p != '\0') {
         wchar_t* buffer;
-        size_t len = strlen(p);
+        size_t len = strlen(p) + 1;
         size_t r;
 
         buffer = malloc(len * sizeof(wchar_t));