This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH 1/2] python: disallow python code to instanciate certain types
- From: Phil Muldoon <pmuldoon at redhat dot com>
- To: Sanimir Agovic <sanimir dot agovic at intel dot com>
- Cc: gdb-patches at sourceware dot org
- Date: Fri, 30 Aug 2013 16:08:40 +0100
- Subject: Re: [PATCH 1/2] python: disallow python code to instanciate certain types
- Authentication-results: sourceware.org; auth=none
- References: <1377873604-15519-1-git-send-email-sanimir dot agovic at intel dot com> <1377873604-15519-2-git-send-email-sanimir dot agovic at intel dot com>
On 30/08/13 15:40, Sanimir Agovic wrote:
> I simply followed the pattern used for gdb.Type and assign NULL to tp_new
> thus the type cannot be created from python code.
>
> before>
> (gdb) python gdb.Frame()
> (gdb)
>
> after>
> (gdb) python gdb.Frame()
> Traceback (most recent call last):
> File "<string>", line 1, in <module>
> TypeError: cannot create 'gdb.Frame' instances
> Error while executing Python code.
>
> 2013-08-30 Sanimir Agovic <sanimir.agovic@intel.com>
Thanks.
> -static PyObject *
> -objfpy_new (PyTypeObject *type, PyObject *args, PyObject *keywords)
> -{
> - objfile_object *self = (objfile_object *) type->tp_alloc (type, 0);
> -
> - if (self)
> - {
> - self->objfile = NULL;
> -
> - self->printers = PyList_New (0);
> - if (!self->printers)
> - {
> - Py_DECREF (self);
> - return NULL;
> - }
> -
> - self->frame_filters = PyDict_New ();
> - if (!self->frame_filters)
> - {
> - Py_DECREF (self);
> - return NULL;
> - }
> -
> - self->type_printers = PyList_New (0);
> - if (!self->type_printers)
> - {
> - Py_DECREF (self);
> - return NULL;
> - }
> - }
> - return (PyObject *) self;
> -}
In removing this function, you are removing the instantiation of
self->printers (Which is needed for pretty-printers),
self->frame-filters (for frame filters) and self->type_printers (for
type printers). If this is the case, and I have not missed an
equivalent instantiation somewhere else, you will have an
uninitialized PyObject for each of the above and likely will result in
a crash? I'm surprised this did not crash GDB. Each object file
keeps a separate list or dictionary of frame filters, pretty printers
and type printers that may be populated for object file specific
scenarios (like auto-loading). Also, I suspect the corresponding
clean-up function for these objects will crash when they are freed.
> -static PyObject *
> -pspy_new (PyTypeObject *type, PyObject *args, PyObject *keywords)
> -{
> - pspace_object *self = (pspace_object *) type->tp_alloc (type, 0);
> -
> - if (self)
> - {
> - self->pspace = NULL;
> -
> - self->printers = PyList_New (0);
> - if (!self->printers)
> - {
> - Py_DECREF (self);
> - return NULL;
> - }
> -
> - self->frame_filters = PyDict_New ();
> - if (!self->frame_filters)
> - {
> - Py_DECREF (self);
> - return NULL;
> - }
> -
> - self->type_printers = PyList_New (0);
> - if (!self->type_printers)
> - {
> - Py_DECREF (self);
> - return NULL;
> - }
> - }
> - return (PyObject *) self;
> -}
> -
Ditto, same with object files above.
Cheers,
Phil