From: Victor Stinner Date: Sun, 18 Dec 2011 20:05:22 +0000 (+0100) Subject: (Merge 3.2) Handle correctly _Py_fopen() error: don't replace the exception X-Git-Tag: v3.3.0a1~567 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=357347627186a037805b12ff1740d36d0f8e2e11;p=thirdparty%2FPython%2Fcpython.git (Merge 3.2) Handle correctly _Py_fopen() error: don't replace the exception --- 357347627186a037805b12ff1740d36d0f8e2e11 diff --cc Modules/zipimport.c index ed835c9cd8e5,11c390452538..09bd83aed780 --- a/Modules/zipimport.c +++ b/Modules/zipimport.c @@@ -740,9 -727,17 +740,10 @@@ read_directory(PyObject *archive const char *charset; int bootstrap; - if (PyUnicode_GET_SIZE(archive_obj) > MAXPATHLEN) { - PyErr_SetString(PyExc_OverflowError, - "Zip path name is too long"); - return NULL; - } - Py_UNICODE_strcpy(path, PyUnicode_AS_UNICODE(archive_obj)); - - fp = _Py_fopen(archive_obj, "rb"); + fp = _Py_fopen(archive, "rb"); if (fp == NULL) { - PyErr_Format(ZipImportError, "can't open Zip file: %R", archive); + if (!PyErr_Occurred()) - PyErr_Format(ZipImportError, "can't open Zip file: '%U'", archive_obj); ++ PyErr_Format(ZipImportError, "can't open Zip file: %R", archive); return NULL; } fseek(fp, -22, SEEK_END); diff --cc Python/import.c index 34d1a26dc785,e721498aaa38..c7541316b53e --- a/Python/import.c +++ b/Python/import.c @@@ -3759,27 -3318,27 +3759,39 @@@ get_file(PyObject *pathname, PyObject * if (mode[0] == 'U') mode = "r" PY_STDIOTEXTMODE; if (fob == NULL) { - fp = fopen(pathname, mode); + fp = _Py_fopen(pathname, mode); ++ if (!fp) { ++ if (!PyErr_Occurred()) ++ PyErr_SetFromErrno(PyExc_IOError); ++ return NULL; ++ } ++ return fp; } else { int fd = PyObject_AsFileDescriptor(fob); if (fd == -1) return NULL; -- if (!_PyVerify_fd(fd)) -- goto error; ++ if (!_PyVerify_fd(fd)) { ++ PyErr_SetFromErrno(PyExc_IOError); ++ return NULL; ++ } ++ /* the FILE struct gets a new fd, so that it can be closed * independently of the file descriptor given */ fd = dup(fd); -- if (fd == -1) -- goto error; ++ if (fd == -1) { ++ PyErr_SetFromErrno(PyExc_IOError); ++ return NULL; ++ } ++ fp = fdopen(fd, mode); -- } -- if (fp) ++ if (!fp) { ++ PyErr_SetFromErrno(PyExc_IOError); ++ return NULL; ++ } return fp; --error: -- PyErr_SetFromErrno(PyExc_IOError); -- return NULL; ++ } } static PyObject *