Index: Lib/os.py =================================================================== --- Lib/os.py (révision 66831) +++ Lib/os.py (copie de travail) @@ -358,6 +358,10 @@ PATH = envpath.split(pathsep) last_exc = saved_exc = None saved_tb = None + if name == 'posix' \ + and isinstance(file, bytes): + encoding = sys.getfilesystemencoding() + PATH = (bytes(dir, encoding) for dir in PATH) for dir in PATH: fullname = path.join(dir, file) try: --- Modules/posixmodule.c.orig 2008-10-08 02:06:36.000000000 +0200 +++ Modules/posixmodule.c 2008-10-08 02:05:57.000000000 +0200 @@ -3088,33 +3088,35 @@ if (!PyArg_Parse( key, - "s;execve() arg 3 contains a non-string key", + "et;execve() arg 3 key contains a non-string key", + Py_FileSystemDefaultEncoding, &k) || !PyArg_Parse( val, - "s;execve() arg 3 contains a non-string value", + "et;execve() arg 3 value contains a non-string value", + Py_FileSystemDefaultEncoding, &v)) { 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) { + /* 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; - p = PyMem_NEW(char, len); - if (p == NULL) { - PyErr_NoMemory(); - goto fail_2; - } - PyOS_snprintf(p, len, "%s=%s", k, v); - envlist[envc++] = p; + len = strlen(k) + strlen(v) + 2; + p = PyMem_NEW(char, len); + if (p == NULL) { + PyErr_NoMemory(); + goto fail_2; + } + PyOS_snprintf(p, len, "%s=%s", k, v); + envlist[envc++] = p; #if defined(PYOS_OS2) - } + } #endif } - envlist[envc] = 0; + envlist[envc] = NULL; execve(path, argvlist, envlist); Index: Lib/test/test_posix.py =================================================================== --- Lib/test/test_posix.py (révision 66831) +++ Lib/test/test_posix.py (copie de travail) @@ -13,6 +13,7 @@ import shutil import unittest import warnings +import sys warnings.filterwarnings('ignore', '.* potential security risk .*', RuntimeWarning) @@ -252,6 +253,26 @@ support.rmtree(base_path) os.chdir(curdir) + def test_execvpe(self): + if os.name != "posix": + return + pid = os.fork() + if not pid: + code = '''import os, sys +try: + os.execvpe(b'sh', [b'sh', '-c', 'exit 1'], {'UNUSED': b'bytes'}) +except: + pass +sys.exit(2)''' + try: + os.execvpe(sys.executable, [sys.executable, '-c', code], None) + except: + pass + sys.exit(3) + else: + wpid, status = os.waitpid(pid, 0) + self.assert_(os.WIFEXITED(status)) + self.assertEqual(os.WEXITSTATUS(status), 1) def test_main(): support.run_unittest(PosixTester)