Commits

John Mulligan  committed 73623df

fslib: check return code of dup in C

  • Participants
  • Parent commits e13bca6

Comments (0)

Files changed (1)

File fsnix/fslib.c

     reslist = PyList_New(0);
     if (reslist == NULL) return NULL;
 
-    dirh = fdopendir(dup(dirfd));
+    dirfd = dup(dirfd);
+    if (dirfd < 0) {
+        Py_XDECREF(reslist);
+        PyErr_SetFromErrno(PyExc_OSError);
+        return NULL;
+    }
+    dirh = fdopendir(dirfd);
     if (dirh == NULL) {
         Py_XDECREF(reslist);
         PyErr_SetFromErrno(PyExc_OSError);
         return NULL;
     }
 
+    dirfd = dup(dirfd);
+    if (dirfd < 0) {
+        PyErr_SetFromErrno(PyExc_OSError);
+        return NULL;
+    }
     Py_BEGIN_ALLOW_THREADS
-    temp = fdopendir(dup(dirfd));
+    temp = fdopendir(dirfd);
     Py_END_ALLOW_THREADS
     if (temp == NULL) {
         PyErr_SetFromErrno(PyExc_OSError);