Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ffd15f5

Browse files
committed
Two robustness patches:
(1) In opendir(), don't call the lock-release macros; we're manipulating list objects and that shouldn't be done in unlocked state. (2) Don't use posix_strint() for chmod() -- the mode_t arg might be a 64 bit int (reported by Nick Maclaren).
1 parent fb2789f commit ffd15f5

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

Modules/posixmodule.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,18 @@ posix_chmod(self, args)
692692
PyObject *self;
693693
PyObject *args;
694694
{
695-
return posix_strint(args, "si:chmod", chmod);
695+
char *path;
696+
int i;
697+
int res;
698+
if (!PyArg_ParseTuple(args, format, &path, &i))
699+
return NULL;
700+
Py_BEGIN_ALLOW_THREADS
701+
res = chmod(path, i);
702+
Py_END_ALLOW_THREADS
703+
if (res < 0)
704+
return posix_error_with_filename(path);
705+
Py_INCREF(Py_None);
706+
return Py_None;
696707
}
697708

698709

@@ -998,14 +1009,11 @@ posix_listdir(self, args)
9981009
struct dirent *ep;
9991010
if (!PyArg_ParseTuple(args, "s:listdir", &name))
10001011
return NULL;
1001-
Py_BEGIN_ALLOW_THREADS
10021012
if ((dirp = opendir(name)) == NULL) {
1003-
Py_BLOCK_THREADS
10041013
return posix_error_with_filename(name);
10051014
}
10061015
if ((d = PyList_New(0)) == NULL) {
10071016
closedir(dirp);
1008-
Py_BLOCK_THREADS
10091017
return NULL;
10101018
}
10111019
while ((ep = readdir(dirp)) != NULL) {
@@ -1028,7 +1036,6 @@ posix_listdir(self, args)
10281036
Py_DECREF(v);
10291037
}
10301038
closedir(dirp);
1031-
Py_END_ALLOW_THREADS
10321039

10331040
return d;
10341041

0 commit comments

Comments
 (0)