@@ -1527,6 +1527,7 @@ get_sourcefile(PyObject *filename)
15271527 Py_UCS4 * fileuni ;
15281528 PyObject * py ;
15291529 struct stat statbuf ;
1530+ int err ;
15301531
15311532 len = PyUnicode_GET_LENGTH (filename );
15321533 if (len == 0 )
@@ -1554,7 +1555,10 @@ get_sourcefile(PyObject *filename)
15541555 if (py == NULL )
15551556 goto error ;
15561557
1557- if (_Py_stat (py , & statbuf ) == 0 && S_ISREG (statbuf .st_mode )) {
1558+ err = _Py_stat (py , & statbuf );
1559+ if (err == -2 )
1560+ goto error ;
1561+ if (err == 0 && S_ISREG (statbuf .st_mode )) {
15581562 PyMem_Free (fileuni );
15591563 return py ;
15601564 }
@@ -1760,7 +1764,7 @@ find_module_path(PyObject *fullname, PyObject *name, PyObject *path,
17601764 Py_ssize_t len , pos ;
17611765 struct stat statbuf ;
17621766 static struct filedescr fd_package = {"" , "" , PKG_DIRECTORY };
1763- int result , addsep ;
1767+ int err , result , addsep ;
17641768
17651769 if (PyUnicode_Check (path )) {
17661770 Py_INCREF (path );
@@ -1844,7 +1848,12 @@ find_module_path(PyObject *fullname, PyObject *name, PyObject *path,
18441848 /* Check for package import (buf holds a directory name,
18451849 and there's an __init__ module in that directory */
18461850#ifdef HAVE_STAT
1847- if (_Py_stat (filename , & statbuf ) == 0 && /* it exists */
1851+ err = _Py_stat (filename , & statbuf );
1852+ if (err == -2 ) {
1853+ result = -1 ;
1854+ goto out ;
1855+ }
1856+ if (err == 0 && /* it exists */
18481857 S_ISDIR (statbuf .st_mode )) /* it's a directory */
18491858 {
18501859 int match ;
@@ -1905,6 +1914,7 @@ find_module_path_list(PyObject *fullname, PyObject *name,
19051914 FILE * fp = NULL ;
19061915 PyObject * prefix , * filename ;
19071916 int match ;
1917+ int err ;
19081918
19091919 npath = PyList_Size (search_path_list );
19101920 for (i = 0 ; i < npath ; i ++ ) {
@@ -1944,8 +1954,13 @@ find_module_path_list(PyObject *fullname, PyObject *name,
19441954 if (Py_VerboseFlag > 1 )
19451955 PySys_FormatStderr ("# trying %R\n" , filename );
19461956
1947- if (_Py_stat (filename , & statbuf ) != 0 || S_ISDIR (statbuf .st_mode ))
1948- {
1957+ err = _Py_stat (filename , & statbuf );
1958+ if (err == -2 ) {
1959+ Py_DECREF (prefix );
1960+ Py_DECREF (filename );
1961+ return NULL ;
1962+ }
1963+ if (err != 0 || S_ISDIR (statbuf .st_mode )) {
19491964 /* it doesn't exist, or it's a directory */
19501965 Py_DECREF (filename );
19511966 continue ;
@@ -2345,11 +2360,15 @@ find_init_module(PyObject *directory)
23452360 struct stat statbuf ;
23462361 PyObject * filename ;
23472362 int match ;
2363+ int err ;
23482364
23492365 filename = PyUnicode_FromFormat ("%U%c__init__.py" , directory , SEP );
23502366 if (filename == NULL )
23512367 return -1 ;
2352- if (_Py_stat (filename , & statbuf ) == 0 ) {
2368+ err = _Py_stat (filename , & statbuf );
2369+ if (err == -2 )
2370+ return -1 ;
2371+ if (err == 0 ) {
23532372 /* 3=len(".py") */
23542373 match = case_ok (filename , -3 , initstr );
23552374 if (match < 0 ) {
@@ -2367,7 +2386,12 @@ find_init_module(PyObject *directory)
23672386 directory , SEP , Py_OptimizeFlag ? 'o' : 'c' );
23682387 if (filename == NULL )
23692388 return -1 ;
2370- if (_Py_stat (filename , & statbuf ) == 0 ) {
2389+ err = _Py_stat (filename , & statbuf );
2390+ if (err == -2 ) {
2391+ Py_DECREF (filename );
2392+ return -1 ;
2393+ }
2394+ if (err == 0 ) {
23712395 /* 4=len(".pyc") */
23722396 match = case_ok (filename , -4 , initstr );
23732397 if (match < 0 ) {
0 commit comments