New submission from Robert Snoeberger:

While embedding the Python 2.7 interpreter in an application, I have 
encountered a crash when the built-in function 'execfile' is invoked with one 
argument.

A file is attached, execfile_invoke.c, that reproduces the crash. The 
reproduction steps on my machine are the following:

% gcc -o execfile_invoke execfile_invoke.c -I/usr/include/python2.7 -L/usr/lib 
-lpthread -ldl -lutil -lm -lpython2.7 -Xlinker -export-dynamic
% ./execfile_invoke
Call execfile with one argument...
Segmentation fault
% 

I am using the following version of Python.

Python 2.7.3 (default, Mar 13 2014, 11:03:55) 
[GCC 4.7.2] on linux2

The crash appears to occur because a call to PyEval_GetGlobals returns a NULL 
PyObject*,

globals = PyEval_GetGlobals();

and PyDict_GetItemString is called before a NULL check is performed.

In the Python 3 function builtin_exec, globals and locals are checked for NULL. 
If either is NULL, an exception with message "globals and locals cannot be 
NULL" is set.

if (!globals || !locals) {
     PyErr_SetString(PyExc_SystemError,
            "globals and locals cannot be NULL");
   return NULL;
}

----------
files: execfile_invoke.c
messages: 218988
nosy: snoeberger
priority: normal
severity: normal
status: open
title: Segv during call to builtin_execfile in application embedding Python 
interpreter.
type: crash
versions: Python 2.7
Added file: http://bugs.python.org/file35329/execfile_invoke.c

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue21563>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to