mirror of
https://github.com/python/cpython.git
synced 2025-08-15 06:10:47 +00:00
Merged revisions 81398 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r81398 | antoine.pitrou | 2010-05-21 19:12:38 +0200 (ven., 21 mai 2010) | 6 lines Issue #5753: A new C API function, :cfunc:`PySys_SetArgvEx`, allows embedders of the interpreter to set sys.argv without also modifying sys.path. This helps fix `CVE-2008-5983 <http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2008-5983>`_. ........
This commit is contained in:
parent
0a3b69ef0a
commit
52ca516cac
4 changed files with 50 additions and 7 deletions
|
@ -22,6 +22,7 @@ Initialization, Finalization, and Threads
|
||||||
module: sys
|
module: sys
|
||||||
triple: module; search; path
|
triple: module; search; path
|
||||||
single: PySys_SetArgv()
|
single: PySys_SetArgv()
|
||||||
|
single: PySys_SetArgvEx()
|
||||||
single: Py_Finalize()
|
single: Py_Finalize()
|
||||||
|
|
||||||
Initialize the Python interpreter. In an application embedding Python, this
|
Initialize the Python interpreter. In an application embedding Python, this
|
||||||
|
@ -31,7 +32,7 @@ Initialization, Finalization, and Threads
|
||||||
the table of loaded modules (``sys.modules``), and creates the fundamental
|
the table of loaded modules (``sys.modules``), and creates the fundamental
|
||||||
modules :mod:`__builtin__`, :mod:`__main__` and :mod:`sys`. It also initializes
|
modules :mod:`__builtin__`, :mod:`__main__` and :mod:`sys`. It also initializes
|
||||||
the module search path (``sys.path``). It does not set ``sys.argv``; use
|
the module search path (``sys.path``). It does not set ``sys.argv``; use
|
||||||
:cfunc:`PySys_SetArgv` for that. This is a no-op when called for a second time
|
:cfunc:`PySys_SetArgvEx` for that. This is a no-op when called for a second time
|
||||||
(without calling :cfunc:`Py_Finalize` first). There is no return value; it is a
|
(without calling :cfunc:`Py_Finalize` first). There is no return value; it is a
|
||||||
fatal error if the initialization fails.
|
fatal error if the initialization fails.
|
||||||
|
|
||||||
|
@ -338,7 +339,7 @@ Initialization, Finalization, and Threads
|
||||||
``sys.version``.
|
``sys.version``.
|
||||||
|
|
||||||
|
|
||||||
.. cfunction:: void PySys_SetArgv(int argc, char **argv)
|
.. cfunction:: void PySys_SetArgvEx(int argc, char **argv, int updatepath)
|
||||||
|
|
||||||
.. index::
|
.. index::
|
||||||
single: main()
|
single: main()
|
||||||
|
@ -353,14 +354,41 @@ Initialization, Finalization, and Threads
|
||||||
string. If this function fails to initialize :data:`sys.argv`, a fatal
|
string. If this function fails to initialize :data:`sys.argv`, a fatal
|
||||||
condition is signalled using :cfunc:`Py_FatalError`.
|
condition is signalled using :cfunc:`Py_FatalError`.
|
||||||
|
|
||||||
This function also prepends the executed script's path to :data:`sys.path`.
|
If *updatepath* is zero, this is all the function does. If *updatepath*
|
||||||
If no script is executed (in the case of calling ``python -c`` or just the
|
is non-zero, the function also modifies :data:`sys.path` according to the
|
||||||
interactive interpreter), the empty string is used instead.
|
following algorithm:
|
||||||
|
|
||||||
|
- If the name of an existing script is passed in ``argv[0]``, the absolute
|
||||||
|
path of the directory where the script is located is prepended to
|
||||||
|
:data:`sys.path`.
|
||||||
|
- Otherwise (that is, if *argc* is 0 or ``argv[0]`` doesn't point
|
||||||
|
to an existing file name), an empty string is prepended to
|
||||||
|
:data:`sys.path`, which is the same as prepending the current working
|
||||||
|
directory (``"."``).
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
It is recommended that applications embedding the Python interpreter
|
||||||
|
for purposes other than executing a single script pass 0 as *updatepath*,
|
||||||
|
and update :data:`sys.path` themselves if desired.
|
||||||
|
See `CVE-2008-5983 <http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2008-5983>`_.
|
||||||
|
|
||||||
|
On versions before 2.6.6, you can achieve the same effect by manually
|
||||||
|
popping the first :data:`sys.path` element after having called
|
||||||
|
:cfunc:`PySys_SetArgv`, for example using::
|
||||||
|
|
||||||
|
PyRun_SimpleString("import sys; sys.path.pop(0)\n");
|
||||||
|
|
||||||
|
.. versionadded:: 2.6.6
|
||||||
|
|
||||||
.. XXX impl. doesn't seem consistent in allowing 0/NULL for the params;
|
.. XXX impl. doesn't seem consistent in allowing 0/NULL for the params;
|
||||||
check w/ Guido.
|
check w/ Guido.
|
||||||
|
|
||||||
|
|
||||||
|
.. cfunction:: void PySys_SetArgv(int argc, char **argv)
|
||||||
|
|
||||||
|
This function works like :cfunc:`PySys_SetArgv` with *updatepath* set to 1.
|
||||||
|
|
||||||
|
|
||||||
.. cfunction:: void Py_SetPythonHome(char *home)
|
.. cfunction:: void Py_SetPythonHome(char *home)
|
||||||
|
|
||||||
Set the default "home" directory, that is, the location of the standard
|
Set the default "home" directory, that is, the location of the standard
|
||||||
|
|
|
@ -11,6 +11,7 @@ PyAPI_FUNC(PyObject *) PySys_GetObject(char *);
|
||||||
PyAPI_FUNC(int) PySys_SetObject(char *, PyObject *);
|
PyAPI_FUNC(int) PySys_SetObject(char *, PyObject *);
|
||||||
PyAPI_FUNC(FILE *) PySys_GetFile(char *, FILE *);
|
PyAPI_FUNC(FILE *) PySys_GetFile(char *, FILE *);
|
||||||
PyAPI_FUNC(void) PySys_SetArgv(int, char **);
|
PyAPI_FUNC(void) PySys_SetArgv(int, char **);
|
||||||
|
PyAPI_FUNC(void) PySys_SetArgvEx(int, char **, int);
|
||||||
PyAPI_FUNC(void) PySys_SetPath(char *);
|
PyAPI_FUNC(void) PySys_SetPath(char *);
|
||||||
|
|
||||||
PyAPI_FUNC(void) PySys_WriteStdout(const char *format, ...)
|
PyAPI_FUNC(void) PySys_WriteStdout(const char *format, ...)
|
||||||
|
|
|
@ -44,6 +44,14 @@ Core and Builtins
|
||||||
|
|
||||||
- Issue #7072: isspace(0xa0) is true on Mac OS X
|
- Issue #7072: isspace(0xa0) is true on Mac OS X
|
||||||
|
|
||||||
|
C-API
|
||||||
|
-----
|
||||||
|
|
||||||
|
- Issue #5753: A new C API function, :cfunc:`PySys_SetArgvEx`, allows
|
||||||
|
embedders of the interpreter to set sys.argv without also modifying
|
||||||
|
sys.path. This helps fix `CVE-2008-5983
|
||||||
|
<http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2008-5983>`_.
|
||||||
|
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
|
|
@ -1528,7 +1528,7 @@ makeargvobject(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PySys_SetArgv(int argc, char **argv)
|
PySys_SetArgvEx(int argc, char **argv, int updatepath)
|
||||||
{
|
{
|
||||||
#if defined(HAVE_REALPATH)
|
#if defined(HAVE_REALPATH)
|
||||||
char fullpath[MAXPATHLEN];
|
char fullpath[MAXPATHLEN];
|
||||||
|
@ -1541,7 +1541,7 @@ PySys_SetArgv(int argc, char **argv)
|
||||||
Py_FatalError("no mem for sys.argv");
|
Py_FatalError("no mem for sys.argv");
|
||||||
if (PySys_SetObject("argv", av) != 0)
|
if (PySys_SetObject("argv", av) != 0)
|
||||||
Py_FatalError("can't assign sys.argv");
|
Py_FatalError("can't assign sys.argv");
|
||||||
if (path != NULL) {
|
if (updatepath && path != NULL) {
|
||||||
char *argv0 = argv[0];
|
char *argv0 = argv[0];
|
||||||
char *p = NULL;
|
char *p = NULL;
|
||||||
Py_ssize_t n = 0;
|
Py_ssize_t n = 0;
|
||||||
|
@ -1631,6 +1631,12 @@ PySys_SetArgv(int argc, char **argv)
|
||||||
Py_DECREF(av);
|
Py_DECREF(av);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PySys_SetArgv(int argc, char **argv)
|
||||||
|
{
|
||||||
|
PySys_SetArgvEx(argc, argv, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* APIs to write to sys.stdout or sys.stderr using a printf-like interface.
|
/* APIs to write to sys.stdout or sys.stderr using a printf-like interface.
|
||||||
Adapted from code submitted by Just van Rossum.
|
Adapted from code submitted by Just van Rossum.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue