@@ -265,7 +265,21 @@ canonicalize(wchar_t *buffer, const wchar_t *path)
265
265
return _PyStatus_NO_MEMORY ();
266
266
}
267
267
268
- if (FAILED (PathCchCanonicalizeEx (buffer , MAXPATHLEN + 1 , path , 0 ))) {
268
+ if (PathIsRelativeW (path )) {
269
+ wchar_t buff [MAXPATHLEN ];
270
+ if (!GetCurrentDirectoryW (MAXPATHLEN , buff )) {
271
+ return _PyStatus_ERR ("unable to find current working directory" );
272
+ }
273
+ if (FAILED (PathCchCombineEx (buff , MAXPATHLEN + 1 , buff , path , PATHCCH_ALLOW_LONG_PATHS ))) {
274
+ return INIT_ERR_BUFFER_OVERFLOW ();
275
+ }
276
+ if (FAILED (PathCchCanonicalizeEx (buffer , MAXPATHLEN + 1 , buff , PATHCCH_ALLOW_LONG_PATHS ))) {
277
+ return INIT_ERR_BUFFER_OVERFLOW ();
278
+ }
279
+ return _PyStatus_OK ();
280
+ }
281
+
282
+ if (FAILED (PathCchCanonicalizeEx (buffer , MAXPATHLEN + 1 , path , PATHCCH_ALLOW_LONG_PATHS ))) {
269
283
return INIT_ERR_BUFFER_OVERFLOW ();
270
284
}
271
285
return _PyStatus_OK ();
@@ -291,6 +305,9 @@ search_for_prefix(wchar_t *prefix, const wchar_t *argv0_path)
291
305
/* Search from argv0_path, until LANDMARK is found.
292
306
We guarantee 'prefix' is null terminated in bounds. */
293
307
wcscpy_s (prefix , MAXPATHLEN + 1 , argv0_path );
308
+ if (!prefix [0 ]) {
309
+ return 0 ;
310
+ }
294
311
wchar_t stdlibdir [MAXPATHLEN + 1 ];
295
312
wcscpy_s (stdlibdir , Py_ARRAY_LENGTH (stdlibdir ), prefix );
296
313
/* We initialize with the longest possible path, in case it doesn't fit.
@@ -925,6 +942,7 @@ calculate_module_search_path(PyCalculatePath *calculate,
925
942
the parent of that.
926
943
*/
927
944
if (prefix [0 ] == L'\0' ) {
945
+ PyStatus status ;
928
946
wchar_t lookBuf [MAXPATHLEN + 1 ];
929
947
const wchar_t * look = buf - 1 ; /* 'buf' is at the end of the buffer */
930
948
while (1 ) {
@@ -939,6 +957,10 @@ calculate_module_search_path(PyCalculatePath *calculate,
939
957
nchars = lookEnd - look ;
940
958
wcsncpy (lookBuf , look + 1 , nchars );
941
959
lookBuf [nchars ] = L'\0' ;
960
+ status = canonicalize (lookBuf , lookBuf );
961
+ if (_PyStatus_EXCEPTION (status )) {
962
+ return status ;
963
+ }
942
964
/* Up one level to the parent */
943
965
reduce (lookBuf );
944
966
if (search_for_prefix (prefix , lookBuf )) {
0 commit comments