Index: Modules/posixmodule.c =================================================================== --- Modules/posixmodule.c (révision 80008) +++ Modules/posixmodule.c (copie de travail) @@ -2689,15 +2689,18 @@ if (!PyArg_ParseTuple(args, "u:system", &command)) return NULL; #else + PyObject *command_obj; char *command; - if (!PyArg_ParseTuple(args, "s:system", &command)) + if (!PyArg_ParseTuple(args, "O&:system", PyUnicode_FSConverter, &command_obj)) return NULL; #endif Py_BEGIN_ALLOW_THREADS #ifdef MS_WINDOWS sts = _wsystem(command); #else + command = bytes2str(command_obj, 1); sts = system(command); + release_bytes(command_obj); #endif Py_END_ALLOW_THREADS return PyLong_FromLong(sts); @@ -3168,6 +3171,7 @@ for (pos = 0; pos < i; pos++) { char *p, *k, *v; size_t len; + PyObject *val2; key = PyList_GetItem(keys, pos); val = PyList_GetItem(vals, pos); @@ -3177,27 +3181,30 @@ if (!PyArg_Parse( key, "s;execve() arg 3 contains a non-string key", - &k) || - !PyArg_Parse( - val, - "s;execve() arg 3 contains a non-string value", - &v)) + &k)) { goto fail_2; } + val2 = PyUnicode_AsEncodedString(val, + Py_FileSystemDefaultEncoding, "surrogateescape"); + if (val2 == NULL) + goto fail_2; + #if defined(PYOS_OS2) /* Omit Pseudo-Env Vars that Would Confuse Programs if Passed On */ if (stricmp(k, "BEGINLIBPATH") != 0 && stricmp(k, "ENDLIBPATH") != 0) { #endif - len = PyUnicode_GetSize(key) + PyUnicode_GetSize(val) + 2; + len = PyUnicode_GetSize(key) + PyBytes_GET_SIZE(val2) + 2; p = PyMem_NEW(char, len); if (p == NULL) { PyErr_NoMemory(); + Py_DECREF(val2); goto fail_2; } - PyOS_snprintf(p, len, "%s=%s", k, v); + PyOS_snprintf(p, len, "%s=%s", k, PyBytes_AsString(val2)); envlist[envc++] = p; + Py_DECREF(val2); #if defined(PYOS_OS2) } #endif