09cb9f3
diff -up Python-2.6.2/Doc/c-api/init.rst.CVE-2008-5983 Python-2.6.2/Doc/c-api/init.rst
09cb9f3
--- Python-2.6.2/Doc/c-api/init.rst.CVE-2008-5983	2009-04-05 17:26:31.000000000 -0400
09cb9f3
+++ Python-2.6.2/Doc/c-api/init.rst	2010-06-04 11:19:30.750199971 -0400
09cb9f3
@@ -22,6 +22,7 @@ Initialization, Finalization, and Thread
09cb9f3
       module: sys
09cb9f3
       triple: module; search; path
09cb9f3
       single: PySys_SetArgv()
09cb9f3
+      single: PySys_SetArgvEx()
09cb9f3
       single: Py_Finalize()
09cb9f3
 
09cb9f3
    Initialize the Python interpreter.  In an application embedding  Python, this
09cb9f3
@@ -31,7 +32,7 @@ Initialization, Finalization, and Thread
09cb9f3
    the table of loaded modules (``sys.modules``), and creates the fundamental
09cb9f3
    modules :mod:`__builtin__`, :mod:`__main__` and :mod:`sys`.  It also initializes
09cb9f3
    the module search path (``sys.path``). It does not set ``sys.argv``; use
09cb9f3
-   :cfunc:`PySys_SetArgv` for that.  This is a no-op when called for a second time
09cb9f3
+   :cfunc:`PySys_SetArgvEx` for that.  This is a no-op when called for a second time
09cb9f3
    (without calling :cfunc:`Py_Finalize` first).  There is no return value; it is a
09cb9f3
    fatal error if the initialization fails.
09cb9f3
 
09cb9f3
@@ -346,7 +347,7 @@ Initialization, Finalization, and Thread
09cb9f3
    ``sys.version``.
09cb9f3
 
09cb9f3
 
09cb9f3
-.. cfunction:: void PySys_SetArgv(int argc, char **argv)
09cb9f3
+.. cfunction:: void PySys_SetArgvEx(int argc, char **argv, int updatepath)
09cb9f3
 
09cb9f3
    .. index::
09cb9f3
       single: main()
09cb9f3
@@ -361,14 +362,41 @@ Initialization, Finalization, and Thread
09cb9f3
    string.  If this function fails to initialize :data:`sys.argv`, a fatal
09cb9f3
    condition is signalled using :cfunc:`Py_FatalError`.
09cb9f3
 
09cb9f3
-   This function also prepends the executed script's path to :data:`sys.path`.
09cb9f3
-   If no script is executed (in the case of calling ``python -c`` or just the
09cb9f3
-   interactive interpreter), the empty string is used instead.
09cb9f3
+   If *updatepath* is zero, this is all the function does.  If *updatepath*
09cb9f3
+   is non-zero, the function also modifies :data:`sys.path` according to the
09cb9f3
+   following algorithm:
09cb9f3
+
09cb9f3
+   - If the name of an existing script is passed in ``argv[0]``, the absolute
09cb9f3
+     path of the directory where the script is located is prepended to
09cb9f3
+     :data:`sys.path`.
09cb9f3
+   - Otherwise (that is, if *argc* is 0 or ``argv[0]`` doesn't point
09cb9f3
+     to an existing file name), an empty string is prepended to
09cb9f3
+     :data:`sys.path`, which is the same as prepending the current working
09cb9f3
+     directory (``"."``).
09cb9f3
+
09cb9f3
+   .. note::
09cb9f3
+      It is recommended that applications embedding the Python interpreter
09cb9f3
+      for purposes other than executing a single script pass 0 as *updatepath*,
09cb9f3
+      and update :data:`sys.path` themselves if desired.
09cb9f3
+      See `CVE-2008-5983 <http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2008-5983>`_.
09cb9f3
+
09cb9f3
+      On versions before 2.6.6, you can achieve the same effect by manually
09cb9f3
+      popping the first :data:`sys.path` element after having called
09cb9f3
+      :cfunc:`PySys_SetArgv`, for example using::
09cb9f3
+
09cb9f3
+         PyRun_SimpleString("import sys; sys.path.pop(0)\n");
09cb9f3
+
09cb9f3
+   .. versionadded:: 2.6.6
09cb9f3
 
09cb9f3
    .. XXX impl. doesn't seem consistent in allowing 0/NULL for the params;
09cb9f3
       check w/ Guido.
09cb9f3
 
09cb9f3
 
09cb9f3
+.. cfunction:: void PySys_SetArgv(int argc, char **argv)
09cb9f3
+
09cb9f3
+   This function works like :cfunc:`PySys_SetArgv` with *updatepath* set to 1.
09cb9f3
+
09cb9f3
+
09cb9f3
 .. cfunction:: void Py_SetPythonHome(char *home)
09cb9f3
 
09cb9f3
    Set the default "home" directory, that is, the location of the standard
09cb9f3
diff -up Python-2.6.2/Include/sysmodule.h.CVE-2008-5983 Python-2.6.2/Include/sysmodule.h
09cb9f3
--- Python-2.6.2/Include/sysmodule.h.CVE-2008-5983	2008-04-12 19:44:07.000000000 -0400
09cb9f3
+++ Python-2.6.2/Include/sysmodule.h	2010-06-04 11:19:30.747199764 -0400
09cb9f3
@@ -11,6 +11,7 @@ PyAPI_FUNC(PyObject *) PySys_GetObject(c
09cb9f3
 PyAPI_FUNC(int) PySys_SetObject(char *, PyObject *);
09cb9f3
 PyAPI_FUNC(FILE *) PySys_GetFile(char *, FILE *);
09cb9f3
 PyAPI_FUNC(void) PySys_SetArgv(int, char **);
09cb9f3
+PyAPI_FUNC(void) PySys_SetArgvEx(int, char **, int);
09cb9f3
 PyAPI_FUNC(void) PySys_SetPath(char *);
09cb9f3
 
09cb9f3
 PyAPI_FUNC(void) PySys_WriteStdout(const char *format, ...)
09cb9f3
diff -up Python-2.6.2/Misc/NEWS.CVE-2008-5983 Python-2.6.2/Misc/NEWS
09cb9f3
--- Python-2.6.2/Misc/NEWS.CVE-2008-5983	2010-06-04 11:19:30.730199353 -0400
09cb9f3
+++ Python-2.6.2/Misc/NEWS	2010-06-04 11:19:30.749199965 -0400
09cb9f3
@@ -111,6 +111,14 @@ Core and Builtins
09cb9f3
   Valgrind.  This gives improved memory leak detection when running
09cb9f3
   under Valgrind, while taking advantage of pymalloc at other times.
09cb9f3
 
09cb9f3
+C-API
09cb9f3
+-----
09cb9f3
+
09cb9f3
+- Issue #5753: A new C API function, :cfunc:`PySys_SetArgvEx`, allows
09cb9f3
+  embedders of the interpreter to set sys.argv without also modifying
09cb9f3
+  sys.path.  This helps fix `CVE-2008-5983
09cb9f3
+  <http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2008-5983>`_.
09cb9f3
+
09cb9f3
 Library
09cb9f3
 -------
09cb9f3
 
09cb9f3
diff -up Python-2.6.2/Python/sysmodule.c.CVE-2008-5983 Python-2.6.2/Python/sysmodule.c
09cb9f3
--- Python-2.6.2/Python/sysmodule.c.CVE-2008-5983	2009-01-13 19:08:09.000000000 -0500
09cb9f3
+++ Python-2.6.2/Python/sysmodule.c	2010-06-04 11:20:18.931825713 -0400
09cb9f3
@@ -1528,7 +1528,7 @@ makeargvobject(int argc, char **argv)
09cb9f3
 }
09cb9f3
 
09cb9f3
 void
09cb9f3
-PySys_SetArgv(int argc, char **argv)
09cb9f3
+PySys_SetArgvEx(int argc, char **argv, int updatepath)
09cb9f3
 {
09cb9f3
 #if defined(HAVE_REALPATH)
09cb9f3
 	char fullpath[MAXPATHLEN];
09cb9f3
@@ -1541,7 +1541,7 @@ PySys_SetArgv(int argc, char **argv)
09cb9f3
 		Py_FatalError("no mem for sys.argv");
09cb9f3
 	if (PySys_SetObject("argv", av) != 0)
09cb9f3
 		Py_FatalError("can't assign sys.argv");
09cb9f3
-	if (path != NULL) {
09cb9f3
+	if (updatepath && path != NULL) {
09cb9f3
 		char *argv0 = argv[0];
09cb9f3
 		char *p = NULL;
09cb9f3
 		Py_ssize_t n = 0;
09cb9f3
@@ -1631,6 +1631,12 @@ PySys_SetArgv(int argc, char **argv)
09cb9f3
 	Py_DECREF(av);
09cb9f3
 }
09cb9f3
 
09cb9f3
+void
09cb9f3
+PySys_SetArgv(int argc, char **argv)
09cb9f3
+{
09cb9f3
+    PySys_SetArgvEx(argc, argv, 1);
09cb9f3
+}
09cb9f3
+
09cb9f3
 
09cb9f3
 /* APIs to write to sys.stdout or sys.stderr using a printf-like interface.
09cb9f3
    Adapted from code submitted by Just van Rossum.