[Rpm-maint] [PATCH] handle errors when constructing lists in the Python bindings
Ales Kozumplik
akozumpl at redhat.com
Mon Dec 19 08:24:39 UTC 2011
On 12/16/2011 04:24 AM, David Malcolm wrote:
> Various functions in the Python bindings construct lists of objects,
> but assume that all calls succeed.
>
> python/header-py.c: hdrKeyList
> python/rpmps-py.c: rpmps_AsList
> python/rpmtd-py.c: rpmtd_AsPyobj
> python/spec-py.c: spec_get_sources
> python/spec-py.c: spec_get_packages
>
> Each of these could segfault under low-memory conditions: if the PyList_New()
> call fails, PyList_Append(NULL, item ) will segfault.
> Similarly, although Py_List_Append(list, NULL) is safe, Py_DECREF(NULL) will
> segfault.
>
> Add error-handling for both cases to each function.
>
> Caveat: compiles, but is not tested.
>
> Found using an experimental static analysis tool I've been writing:
> http://gcc-python-plugin.readthedocs.org/en/latest/cpychecker.html
> which is part of https://fedorahosted.org/gcc-python-plugin
>
> A sample HTML report from the tool on one of these cases (specifically
> hdrKeyList) can be seen here:
> http://fedorapeople.org/~dmalcolm/gcc-python-plugin/2011-12-15/header-py.c.hdrKeyList-refcount-errors.html
> ---
Hi David,
thank you for the patch.
I have a question about returning NULL from a python method like the
patch does. Will it cause an exception? It would be preferable, rpm
generally tries to terminate quickly if an OOM situation is encountered.
Why not use http://docs.python.org/c-api/exceptions.html#PyErr_Format
then?
Ales
More information about the Rpm-maint
mailing list