mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-32890, os: Use errno instead of GetLastError() in execve() and truncate() (GH-5784)
path_error() uses GetLastError() on Windows, but some os functions are implemented via CRT APIs which report errors via errno. This may result in raising OSError with invalid error code (such as zero). Introduce posix_path_error() function and use it where appropriate.
This commit is contained in:
parent
a2670565d8
commit
834603112e
3 changed files with 27 additions and 3 deletions
|
@ -1589,6 +1589,16 @@ class ExecTests(unittest.TestCase):
|
|||
with self.assertRaises(ValueError):
|
||||
os.execve(args[0], args, newenv)
|
||||
|
||||
@unittest.skipUnless(sys.platform == "win32", "Win32-specific test")
|
||||
def test_execve_with_empty_path(self):
|
||||
# bpo-32890: Check GetLastError() misuse
|
||||
try:
|
||||
os.execve('', ['arg'], {})
|
||||
except OSError as e:
|
||||
self.assertTrue(e.winerror is None or e.winerror != 0)
|
||||
else:
|
||||
self.fail('No OSError raised')
|
||||
|
||||
|
||||
@unittest.skipUnless(sys.platform == "win32", "Win32 specific tests")
|
||||
class Win32ErrorTests(unittest.TestCase):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue