[Python-checkins] cpython: Catch PyUnicode_AS_UNICODE() errors in fileutils.c

victor.stinner python-checkins at python.org
Thu Nov 17 00:53:09 CET 2011


http://hg.python.org/cpython/rev/94a38ad4aebf
changeset:   73593:94a38ad4aebf
user:        Victor Stinner <victor.stinner at haypocalc.com>
date:        Thu Nov 17 00:51:38 2011 +0100
summary:
  Catch PyUnicode_AS_UNICODE() errors in fileutils.c

files:
  Python/fileutils.c |  13 +++++++++++--
  1 files changed, 11 insertions(+), 2 deletions(-)


diff --git a/Python/fileutils.c b/Python/fileutils.c
--- a/Python/fileutils.c
+++ b/Python/fileutils.c
@@ -244,8 +244,12 @@
 #ifdef MS_WINDOWS
     int err;
     struct _stat wstatbuf;
+    wchar_t *wpath;
 
-    err = _wstat(PyUnicode_AS_UNICODE(path), &wstatbuf);
+    wpath = PyUnicode_AsUnicode(path);
+    if (wpath == NULL)
+        return -1;
+    err = _wstat(wpath, &wstatbuf);
     if (!err)
         statbuf->st_mode = wstatbuf.st_mode;
     return err;
@@ -297,14 +301,19 @@
 _Py_fopen(PyObject *path, const char *mode)
 {
 #ifdef MS_WINDOWS
+    wchar_t *wpath;
     wchar_t wmode[10];
     int usize;
 
+    wpath = PyUnicode_AsUnicode(path);
+    if (wpath == NULL)
+        return NULL;
+
     usize = MultiByteToWideChar(CP_ACP, 0, mode, -1, wmode, sizeof(wmode));
     if (usize == 0)
         return NULL;
 
-    return _wfopen(PyUnicode_AS_UNICODE(path), wmode);
+    return _wfopen(wpath, wmode);
 #else
     FILE *f;
     PyObject *bytes = PyUnicode_EncodeFSDefault(path);

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list