diff Python/pythonrun.c @ 52819:73a7e6aba7b2

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. ........
author Matthias Klose <doko@ubuntu.com>
date Sat, 04 Apr 2009 14:32:42 +0000
parents 0530aadff696
children ac209f132b17
line wrap: on
line diff
--- a/Python/pythonrun.c	Sat Apr 04 14:09:30 2009 +0000
+++ b/Python/pythonrun.c	Sat Apr 04 14:32:42 2009 +0000
@@ -1145,7 +1145,7 @@
 {
 	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 @@
 		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)