Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 11f4326

Browse files
committed
Issue #28732: Fix crash in os.spawnv() with no elements in args
Prevents crashes in some other posixmodule.c functions
1 parent ca4b252 commit 11f4326

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ Core and Builtins
121121
Library
122122
-------
123123

124+
- Issue #28732: Fix crash in os.spawnv() with no elements in args
125+
124126
- Issue #28485: Always raise ValueError for negative
125127
compileall.compile_dir(workers=...) parameter, even when multithreading is
126128
unavailable.

Modules/posixmodule.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5186,6 +5186,16 @@ os_spawnv_impl(PyObject *module, int mode, PyObject *path, PyObject *argv)
51865186
"spawnv() arg 2 must be a tuple or list");
51875187
return NULL;
51885188
}
5189+
#ifdef MS_WINDOWS
5190+
/* Avoid changing behavior in maintenance release, but
5191+
the previous Windows behavior was to crash, so this
5192+
is a "compatible" improvement. */
5193+
if (argc == 0) {
5194+
PyErr_SetString(PyExc_ValueError,
5195+
"spawnv() arg 2 cannot be empty");
5196+
return NULL;
5197+
}
5198+
#endif
51895199

51905200
argvlist = PyMem_NEW(char *, argc+1);
51915201
if (argvlist == NULL) {
@@ -5207,7 +5217,9 @@ os_spawnv_impl(PyObject *module, int mode, PyObject *path, PyObject *argv)
52075217
mode = _P_OVERLAY;
52085218

52095219
Py_BEGIN_ALLOW_THREADS
5220+
_Py_BEGIN_SUPPRESS_IPH
52105221
spawnval = _spawnv(mode, path_char, argvlist);
5222+
_Py_END_SUPPRESS_IPH
52115223
Py_END_ALLOW_THREADS
52125224

52135225
free_string_array(argvlist, argc);
@@ -5297,7 +5309,9 @@ os_spawnve_impl(PyObject *module, int mode, PyObject *path, PyObject *argv,
52975309
mode = _P_OVERLAY;
52985310

52995311
Py_BEGIN_ALLOW_THREADS
5312+
_Py_BEGIN_SUPPRESS_IPH
53005313
spawnval = _spawnve(mode, path_char, argvlist, envlist);
5314+
_Py_END_SUPPRESS_IPH
53015315
Py_END_ALLOW_THREADS
53025316

53035317
if (spawnval == -1)
@@ -7022,7 +7036,9 @@ os_waitpid_impl(PyObject *module, Py_intptr_t pid, int options)
70227036

70237037
do {
70247038
Py_BEGIN_ALLOW_THREADS
7039+
_Py_BEGIN_SUPPRESS_IPH
70257040
res = _cwait(&status, pid, options);
7041+
_Py_END_SUPPRESS_IPH
70267042
Py_END_ALLOW_THREADS
70277043
} while (res < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
70287044
if (res < 0)

0 commit comments

Comments
 (0)