churchyard / rpms / python38

Forked from rpms/python38 5 years ago
Clone
5c9590b
diff -up Python-3.1.2/Doc/c-api/init.rst.CVE-2008-5983 Python-3.1.2/Doc/c-api/init.rst
5c9590b
--- Python-3.1.2/Doc/c-api/init.rst.CVE-2008-5983	2010-01-09 13:48:46.000000000 -0500
5c9590b
+++ Python-3.1.2/Doc/c-api/init.rst	2010-06-04 15:19:26.724089244 -0400
5c9590b
@@ -22,6 +22,7 @@ Initialization, Finalization, and Thread
5c9590b
       module: sys
5c9590b
       triple: module; search; path
5c9590b
       single: PySys_SetArgv()
5c9590b
+      single: PySys_SetArgvEx()
5c9590b
       single: Py_Finalize()
5c9590b
 
5c9590b
    Initialize the Python interpreter.  In an application embedding  Python, this
5c9590b
@@ -31,7 +32,7 @@ Initialization, Finalization, and Thread
5c9590b
    the table of loaded modules (``sys.modules``), and creates the fundamental
5c9590b
    modules :mod:`builtins`, :mod:`__main__` and :mod:`sys`.  It also initializes
5c9590b
    the module search path (``sys.path``). It does not set ``sys.argv``; use
5c9590b
-   :cfunc:`PySys_SetArgv` for that.  This is a no-op when called for a second time
5c9590b
+   :cfunc:`PySys_SetArgvEx` for that.  This is a no-op when called for a second time
5c9590b
    (without calling :cfunc:`Py_Finalize` first).  There is no return value; it is a
5c9590b
    fatal error if the initialization fails.
5c9590b
 
5c9590b
@@ -344,7 +345,7 @@ Initialization, Finalization, and Thread
5c9590b
    ``sys.version``.
5c9590b
 
5c9590b
 
5c9590b
-.. cfunction:: void PySys_SetArgv(int argc, wchar_t **argv)
5c9590b
+.. cfunction:: void PySys_SetArgvEx(int argc, wchar_t **argv, int updatepath)
5c9590b
 
5c9590b
    .. index::
5c9590b
       single: main()
5c9590b
@@ -359,14 +360,41 @@ Initialization, Finalization, and Thread
5c9590b
    string.  If this function fails to initialize :data:`sys.argv`, a fatal
5c9590b
    condition is signalled using :cfunc:`Py_FatalError`.
5c9590b
 
5c9590b
-   This function also prepends the executed script's path to :data:`sys.path`.
5c9590b
-   If no script is executed (in the case of calling ``python -c`` or just the
5c9590b
-   interactive interpreter), the empty string is used instead.
5c9590b
+   If *updatepath* is zero, this is all the function does.  If *updatepath*
5c9590b
+   is non-zero, the function also modifies :data:`sys.path` according to the
5c9590b
+   following algorithm:
5c9590b
+
5c9590b
+   - If the name of an existing script is passed in ``argv[0]``, the absolute
5c9590b
+     path of the directory where the script is located is prepended to
5c9590b
+     :data:`sys.path`.
5c9590b
+   - Otherwise (that is, if *argc* is 0 or ``argv[0]`` doesn't point
5c9590b
+     to an existing file name), an empty string is prepended to
5c9590b
+     :data:`sys.path`, which is the same as prepending the current working
5c9590b
+     directory (``"."``).
5c9590b
+
5c9590b
+   .. note::
5c9590b
+      It is recommended that applications embedding the Python interpreter
5c9590b
+      for purposes other than executing a single script pass 0 as *updatepath*,
5c9590b
+      and update :data:`sys.path` themselves if desired.
5c9590b
+      See `CVE-2008-5983 <http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2008-5983>`_.
5c9590b
+
5c9590b
+      On versions before 3.1.3, you can achieve the same effect by manually
5c9590b
+      popping the first :data:`sys.path` element after having called
5c9590b
+      :cfunc:`PySys_SetArgv`, for example using::
5c9590b
+
5c9590b
+         PyRun_SimpleString("import sys; sys.path.pop(0)\n");
5c9590b
+
5c9590b
+   .. versionadded:: 3.1.3
5c9590b
 
5c9590b
    .. XXX impl. doesn't seem consistent in allowing 0/NULL for the params;
5c9590b
       check w/ Guido.
5c9590b
 
5c9590b
 
5c9590b
+.. cfunction:: void PySys_SetArgv(int argc, wchar_t **argv)
5c9590b
+
5c9590b
+   This function works like :cfunc:`PySys_SetArgv` with *updatepath* set to 1.
5c9590b
+
5c9590b
+
5c9590b
 .. cfunction:: void Py_SetPythonHome(wchar_t *home)
5c9590b
 
5c9590b
    Set the default "home" directory, that is, the location of the standard
5c9590b
diff -up Python-3.1.2/Include/sysmodule.h.CVE-2008-5983 Python-3.1.2/Include/sysmodule.h
5c9590b
--- Python-3.1.2/Include/sysmodule.h.CVE-2008-5983	2008-04-13 09:53:33.000000000 -0400
5c9590b
+++ Python-3.1.2/Include/sysmodule.h	2010-06-04 15:19:26.721088968 -0400
5c9590b
@@ -10,6 +10,7 @@ extern "C" {
5c9590b
 PyAPI_FUNC(PyObject *) PySys_GetObject(const char *);
5c9590b
 PyAPI_FUNC(int) PySys_SetObject(const char *, PyObject *);
5c9590b
 PyAPI_FUNC(void) PySys_SetArgv(int, wchar_t **);
5c9590b
+PyAPI_FUNC(void) PySys_SetArgvEx(int, wchar_t **, int);
5c9590b
 PyAPI_FUNC(void) PySys_SetPath(const wchar_t *);
5c9590b
 
5c9590b
 PyAPI_FUNC(void) PySys_WriteStdout(const char *format, ...)
5c9590b
diff -up Python-3.1.2/Misc/NEWS.CVE-2008-5983 Python-3.1.2/Misc/NEWS
5c9590b
diff -up Python-3.1.2/Python/sysmodule.c.CVE-2008-5983 Python-3.1.2/Python/sysmodule.c
5c9590b
--- Python-3.1.2/Python/sysmodule.c.CVE-2008-5983	2010-06-04 15:19:26.000000000 -0400
5c9590b
+++ Python-3.1.2/Python/sysmodule.c	2010-06-04 15:20:59.932964188 -0400
5c9590b
@@ -1561,7 +1561,7 @@ _wrealpath(const wchar_t *path, wchar_t 
5c9590b
 #endif
5c9590b
 
5c9590b
 void
5c9590b
-PySys_SetArgv(int argc, wchar_t **argv)
5c9590b
+PySys_SetArgvEx(int argc, wchar_t **argv, int updatepath)
5c9590b
 {
5c9590b
 #if defined(HAVE_REALPATH)
5c9590b
 	wchar_t fullpath[MAXPATHLEN];
5c9590b
@@ -1574,7 +1574,7 @@ PySys_SetArgv(int argc, wchar_t **argv)
5c9590b
 		Py_FatalError("no mem for sys.argv");
5c9590b
 	if (PySys_SetObject("argv", av) != 0)
5c9590b
 		Py_FatalError("can't assign sys.argv");
5c9590b
-	if (path != NULL) {
5c9590b
+	if (updatepath && path != NULL) {
5c9590b
 		wchar_t *argv0 = argv[0];
5c9590b
 		wchar_t *p = NULL;
5c9590b
 		Py_ssize_t n = 0;
5c9590b
@@ -1661,6 +1661,12 @@ PySys_SetArgv(int argc, wchar_t **argv)
5c9590b
 	Py_DECREF(av);
5c9590b
 }
5c9590b
 
5c9590b
+void
5c9590b
+PySys_SetArgv(int argc, wchar_t **argv)
5c9590b
+{
5c9590b
+	PySys_SetArgvEx(argc, argv, 1);
5c9590b
+}
5c9590b
+
5c9590b
 
5c9590b
 /* APIs to write to sys.stdout or sys.stderr using a printf-like interface.
5c9590b
    Adapted from code submitted by Just van Rossum.