]> granicus.if.org Git - python/commitdiff
- Issue #3845: In PyRun_SimpleFileExFlags avoid invalid memory access with
authorMatthias Klose <doko@ubuntu.com>
Sat, 4 Apr 2009 14:18:13 +0000 (14:18 +0000)
committerMatthias Klose <doko@ubuntu.com>
Sat, 4 Apr 2009 14:18:13 +0000 (14:18 +0000)
  short file names.

Misc/NEWS
Python/pythonrun.c

index 1a7aaa68e520debed11e8d3b54dc510635cbd51e..db86b517b24fd1c59aa79076716d00113087759a 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -204,6 +204,9 @@ Core and Builtins
 
 - The re.sub(), re.subn() and re.split() functions now accept a flags parameter.
 
+- Issue #3845: In PyRun_SimpleFileExFlags avoid invalid memory access with
+  short file names.
+
 Library
 -------
 
index b3866cebb88ce19b8e40cd99752a33fd48f64c88..8fc0ca199f2af2e31ce10b0a8d21a31347521c3f 100644 (file)
@@ -898,7 +898,7 @@ PyRun_SimpleFileExFlags(FILE *fp, const char *filename, int closeit,
 {
        PyObject *m, *d, *v;
        const char *ext;
-       int set_file_name = 0, ret;
+       int set_file_name = 0, ret, len;
 
        m = PyImport_AddModule("__main__");
        if (m == NULL)
@@ -915,7 +915,8 @@ PyRun_SimpleFileExFlags(FILE *fp, const char *filename, int closeit,
                set_file_name = 1;
                Py_DECREF(f);
        }
-       ext = filename + strlen(filename) - 4;
+       len = strlen(filename);
+       ext = filename + len - (len > 4 ? 4 : 0);
        if (maybe_pyc_file(fp, filename, ext, closeit)) {
                /* Try to run a pyc file. First, re-open in binary */
                if (closeit)