Mercurial > cpython-lru_cache-weakref
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 61778:6fe260bc0987 | 61788:c2917ac5d526 |
|---|---|
| 1647 } | 1647 } |
| 1648 return av; | 1648 return av; |
| 1649 } | 1649 } |
| 1650 | 1650 |
| 1651 void | 1651 void |
| 1652 PySys_SetArgv(int argc, char **argv) | 1652 PySys_SetArgvEx(int argc, char **argv, int updatepath) |
| 1653 { | 1653 { |
| 1654 #if defined(HAVE_REALPATH) | 1654 #if defined(HAVE_REALPATH) |
| 1655 char fullpath[MAXPATHLEN]; | 1655 char fullpath[MAXPATHLEN]; |
| 1656 #elif defined(MS_WINDOWS) && !defined(MS_WINCE) | 1656 #elif defined(MS_WINDOWS) && !defined(MS_WINCE) |
| 1657 char fullpath[MAX_PATH]; | 1657 char fullpath[MAX_PATH]; |
| 1660 PyObject *path = PySys_GetObject("path"); | 1660 PyObject *path = PySys_GetObject("path"); |
| 1661 if (av == NULL) | 1661 if (av == NULL) |
| 1662 Py_FatalError("no mem for sys.argv"); | 1662 Py_FatalError("no mem for sys.argv"); |
| 1663 if (PySys_SetObject("argv", av) != 0) | 1663 if (PySys_SetObject("argv", av) != 0) |
| 1664 Py_FatalError("can't assign sys.argv"); | 1664 Py_FatalError("can't assign sys.argv"); |
| 1665 if (path != NULL) { | 1665 if (updatepath && path != NULL) { |
| 1666 char *argv0 = argv[0]; | 1666 char *argv0 = argv[0]; |
| 1667 char *p = NULL; | 1667 char *p = NULL; |
| 1668 Py_ssize_t n = 0; | 1668 Py_ssize_t n = 0; |
| 1669 PyObject *a; | 1669 PyObject *a; |
| 1670 #ifdef HAVE_READLINK | 1670 #ifdef HAVE_READLINK |
| 1750 Py_DECREF(a); | 1750 Py_DECREF(a); |
| 1751 } | 1751 } |
| 1752 Py_DECREF(av); | 1752 Py_DECREF(av); |
| 1753 } | 1753 } |
| 1754 | 1754 |
| 1755 void | |
| 1756 PySys_SetArgv(int argc, char **argv) | |
| 1757 { | |
| 1758 PySys_SetArgvEx(argc, argv, 1); | |
| 1759 } | |
| 1760 | |
| 1755 | 1761 |
| 1756 /* APIs to write to sys.stdout or sys.stderr using a printf-like interface. | 1762 /* APIs to write to sys.stdout or sys.stderr using a printf-like interface. |
| 1757 Adapted from code submitted by Just van Rossum. | 1763 Adapted from code submitted by Just van Rossum. |
| 1758 | 1764 |
| 1759 PySys_WriteStdout(format, ...) | 1765 PySys_WriteStdout(format, ...) |
