[New-bugs-announce] [issue21563] Segv during call to builtin_execfile in application embedding Python interpreter.

Robert Snoeberger report at bugs.python.org
Fri May 23 21:00:36 CEST 2014


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 <report at bugs.python.org>
<http://bugs.python.org/issue21563>
_______________________________________


More information about the New-bugs-announce mailing list