summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2001-08-08 05:30:36 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2001-08-08 05:30:36 (GMT)
commit6b3a2c4a48eeefce64de12060d4ba0f38a5f3033 (patch)
tree9a019edb363bfbc5c3cd3aff83516e7663531504
parent96204f5e4916c9f4f00855ef4e76c35aa17a474e (diff)
downloadcpython-6b3a2c4a48eeefce64de12060d4ba0f38a5f3033.zip
cpython-6b3a2c4a48eeefce64de12060d4ba0f38a5f3033.tar.gz
cpython-6b3a2c4a48eeefce64de12060d4ba0f38a5f3033.tar.bz2
Patch #448227: Raise an exception when a directory is passed to execfile.
-rw-r--r--Python/bltinmodule.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index ec3c5fc..fa68162 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -568,6 +568,8 @@ builtin_execfile(PyObject *self, PyObject *args)
PyObject *res;
FILE* fp;
PyCompilerFlags cf;
+ int exists;
+ struct stat s;
if (!PyArg_ParseTuple(args, "s|O!O!:execfile",
&filename,
@@ -586,10 +588,27 @@ builtin_execfile(PyObject *self, PyObject *args)
PyEval_GetBuiltins()) != 0)
return NULL;
}
- Py_BEGIN_ALLOW_THREADS
- fp = fopen(filename, "r");
- Py_END_ALLOW_THREADS
- if (fp == NULL) {
+
+ exists = 0;
+ /* Test for existence or directory. */
+ 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);
return NULL;
}