From 042f133d8299d5a2222def66fd125cde16437cd8 Mon Sep 17 00:00:00 2001 From: Matthias Klose Date: Sat, 4 Apr 2009 14:32:42 +0000 Subject: [PATCH] Merged revisions 71152 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r71152 | matthias.klose | 2009-04-04 16:18:13 +0200 (Sa, 04 Apr 2009) | 3 lines - Issue #3845: In PyRun_SimpleFileExFlags avoid invalid memory access with short file names. ........ --- Misc/NEWS | 3 +++ Python/pythonrun.c | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS index 5b4282aa1d..616d43b83d 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -59,6 +59,9 @@ Core and Builtins - Issue #5392: when a very low recursion limit was set, the interpreter would abort with a fatal error after the recursion limit was hit twice. +- Issue #3845: In PyRun_SimpleFileExFlags avoid invalid memory access with + short file names. + Library ------- diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 9159b4c67b..f93403ba5a 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -1145,7 +1145,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) @@ -1163,7 +1163,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) -- 2.40.0