[Python-checkins] cpython (3.2): Issue #3367: NULL-terminate argv[] copies to prevent an invalid access

stefan.krah python-checkins at python.org
Mon Mar 26 15:15:14 CEST 2012


http://hg.python.org/cpython/rev/c0900fd6e4b3
changeset:   75944:c0900fd6e4b3
branch:      3.2
parent:      75941:66117d4bb586
user:        Stefan Krah <skrah at bytereef.org>
date:        Mon Mar 26 15:05:22 2012 +0200
summary:
  Issue #3367: NULL-terminate argv[] copies to prevent an invalid access
in sys_update_path().

files:
  Modules/python.c |  6 ++++--
  1 files changed, 4 insertions(+), 2 deletions(-)


diff --git a/Modules/python.c b/Modules/python.c
--- a/Modules/python.c
+++ b/Modules/python.c
@@ -22,9 +22,9 @@
 int
 main(int argc, char **argv)
 {
-    wchar_t **argv_copy = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*argc);
+    wchar_t **argv_copy = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*(argc+1));
     /* We need a second copies, as Python might modify the first one. */
-    wchar_t **argv_copy2 = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*argc);
+    wchar_t **argv_copy2 = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*(argc+1));
     int i, res;
     char *oldloc;
     /* 754 requires that FP exceptions run in "no stop" mode by default,
@@ -58,6 +58,8 @@
         }
         argv_copy2[i] = argv_copy[i];
     }
+    argv_copy2[argc] = argv_copy[argc] = NULL;
+
     setlocale(LC_ALL, oldloc);
     free(oldloc);
     res = Py_Main(argc, argv_copy);

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list