mirror of https://github.com/python/cpython.git
It turns out that modifying the environment strings is not safe.
Treat them as read-only, and make a copy as appropriately. This was first reported by Bill Janssend and later by Craig Rowland and Ron Sedlmeyer. This fix is mine.
This commit is contained in:
parent
46ab6dfa89
commit
6a619f44c5
|
@ -290,19 +290,29 @@ convertenviron()
|
||||||
return NULL;
|
return NULL;
|
||||||
if (environ == NULL)
|
if (environ == NULL)
|
||||||
return d;
|
return d;
|
||||||
/* XXX This part ignores errors */
|
/* This part ignores errors */
|
||||||
for (e = environ; *e != NULL; e++) {
|
for (e = environ; *e != NULL; e++) {
|
||||||
|
PyObject *k;
|
||||||
PyObject *v;
|
PyObject *v;
|
||||||
char *p = strchr(*e, '=');
|
char *p = strchr(*e, '=');
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
continue;
|
continue;
|
||||||
v = PyString_FromString(p+1);
|
k = PyString_FromStringAndSize(*e, (int)(p-*e));
|
||||||
if (v == NULL)
|
if (k == NULL) {
|
||||||
|
PyErr_Clear();
|
||||||
continue;
|
continue;
|
||||||
*p = '\0';
|
}
|
||||||
if (PyDict_GetItemString(d, *e) == NULL)
|
v = PyString_FromString(p+1);
|
||||||
(void) PyDict_SetItemString(d, *e, v);
|
if (v == NULL) {
|
||||||
*p = '=';
|
PyErr_Clear();
|
||||||
|
Py_DECREF(k);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (PyDict_GetItem(d, k) == NULL) {
|
||||||
|
if (PyDict_SetItem(d, k, v) != 0)
|
||||||
|
PyErr_Clear();
|
||||||
|
}
|
||||||
|
Py_DECREF(k);
|
||||||
Py_DECREF(v);
|
Py_DECREF(v);
|
||||||
}
|
}
|
||||||
#if defined(PYOS_OS2)
|
#if defined(PYOS_OS2)
|
||||||
|
|
Loading…
Reference in New Issue