8000 Verify volume before searching · python/cpython@3147f63 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3147f63

Browse files
committed
Verify volume before searching
1 parent 2d807c9 commit 3147f63

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

Modules/posixmodule.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4279,7 +4279,7 @@ os_listdrives_impl(PyObject *module)
42794279
str = PyUnicode_FromWideChar(buffer, buflen - 1);
42804280
nullchar = PyUnicode_FromStringAndSize("\0", 1);
42814281
if (str && nullchar) {
4282-
r = PyUnicode_Split(str, nullchar, buflen);
4282+
r = PyUnicode_Split(str, nullchar, -1);
42834283
}
42844284
exit:
42854285
if (buffer && buffer != defaultBuffer) {
@@ -4370,12 +4370,25 @@ os_listmounts_impl(PyObject *module, path_t *volume)
43704370
wchar_t default_buffer[MAX_PATH + 1];
43714371
DWORD buflen = Py_ARRAY_LENGTH(default_buffer);
43724372
LPWSTR buffer = default_buffer;
4373+
DWORD attributes;
43734374
PyObject *str = NULL;
43744375
PyObject *nullchar = NULL;
43754376
PyObject *result = NULL;
4377+
4378+
/* Ensure we have a valid volume path before continuing */
4379+
Py_BEGIN_ALLOW_THREADS
4380+
attributes = GetFileAttributesW(volume->wide);
4381+
Py_END_ALLOW_THREADS
4382+
if (attributes == INVALID_FILE_ATTRIBUTES &&
4383+
7345 GetLastError() == ERROR_UNRECOGNIZED_VOLUME)
4384+
{
4385+
return PyErr_SetFromWindowsErr(ERROR_UNRECOGNIZED_VOLUME);
4386+
}
4387+
43764388
if (PySys_Audit("os.listmounts", "O", volume->object) < 0) {
43774389
return NULL;
43784390
}
4391+
43794392
while (1) {
43804393
BOOL success;
43814394
Py_BEGIN_ALLOW_THREADS

0 commit comments

Comments
 (0)
0