mirror of
https://github.com/python/cpython.git
synced 2025-12-04 08:34:25 +00:00
Patch #448227: Raise an exception when a directory is passed to execfile.
This commit is contained in:
parent
96204f5e49
commit
6b3a2c4a48
1 changed files with 23 additions and 4 deletions
|
|
@ -568,6 +568,8 @@ builtin_execfile(PyObject *self, PyObject *args)
|
||||||
PyObject *res;
|
PyObject *res;
|
||||||
FILE* fp;
|
FILE* fp;
|
||||||
PyCompilerFlags cf;
|
PyCompilerFlags cf;
|
||||||
|
int exists;
|
||||||
|
struct stat s;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "s|O!O!:execfile",
|
if (!PyArg_ParseTuple(args, "s|O!O!:execfile",
|
||||||
&filename,
|
&filename,
|
||||||
|
|
@ -586,10 +588,27 @@ builtin_execfile(PyObject *self, PyObject *args)
|
||||||
PyEval_GetBuiltins()) != 0)
|
PyEval_GetBuiltins()) != 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
Py_BEGIN_ALLOW_THREADS
|
|
||||||
fp = fopen(filename, "r");
|
exists = 0;
|
||||||
Py_END_ALLOW_THREADS
|
/* Test for existence or directory. */
|
||||||
if (fp == NULL) {
|
if (!stat(filename, &s)) {
|
||||||
|
if (S_ISDIR(s.st_mode))
|
||||||
|
errno = EISDIR;
|
||||||
|
else
|
||||||
|
exists = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (exists) {
|
||||||
|
Py_BEGIN_ALLOW_THREADS
|
||||||
|
fp = fopen(filename, "r");
|
||||||
|
Py_END_ALLOW_THREADS
|
||||||
|
|
||||||
|
if (fp == NULL) {
|
||||||
|
exists = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!exists) {
|
||||||
PyErr_SetFromErrno(PyExc_IOError);
|
PyErr_SetFromErrno(PyExc_IOError);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue