Mercurial > cpython-lru_cache-weakref
diff Python/sysmodule.c @ 61788:c2917ac5d526 legacy-trunk
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>`_.
| author | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| date | Fri, 21 May 2010 17:12:38 +0000 |
| parents | fd25030223b0 |
| children | b36cb4602e21 |
line wrap: on
line diff
--- a/Python/sysmodule.c Thu May 20 22:23:37 2010 +0000 +++ b/Python/sysmodule.c Fri May 21 17:12:38 2010 +0000 @@ -1649,7 +1649,7 @@ } void -PySys_SetArgv(int argc, char **argv) +PySys_SetArgvEx(int argc, char **argv, int updatepath) { #if defined(HAVE_REALPATH) char fullpath[MAXPATHLEN]; @@ -1662,7 +1662,7 @@ Py_FatalError("no mem for sys.argv"); if (PySys_SetObject("argv", av) != 0) Py_FatalError("can't assign sys.argv"); - if (path != NULL) { + if (updatepath && path != NULL) { char *argv0 = argv[0]; char *p = NULL; Py_ssize_t n = 0; @@ -1752,6 +1752,12 @@ 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. Adapted from code submitted by Just van Rossum.
