From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10064 invoked by alias); 30 Aug 2013 15:08:46 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 10050 invoked by uid 89); 30 Aug 2013 15:08:46 -0000 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 30 Aug 2013 15:08:46 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-5.2 required=5.0 tests=AWL,BAYES_00,KHOP_THREADED,RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r7UF8g9o000468 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 30 Aug 2013 11:08:42 -0400 Received: from localhost.localdomain (ovpn-112-21.ams2.redhat.com [10.36.112.21]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r7UF8eeY011184; Fri, 30 Aug 2013 11:08:41 -0400 Message-ID: <5220B578.6030100@redhat.com> Date: Fri, 30 Aug 2013 15:08:00 -0000 From: Phil Muldoon MIME-Version: 1.0 To: Sanimir Agovic CC: gdb-patches@sourceware.org Subject: Re: [PATCH 1/2] python: disallow python code to instanciate certain types References: <1377873604-15519-1-git-send-email-sanimir.agovic@intel.com> <1377873604-15519-2-git-send-email-sanimir.agovic@intel.com> In-Reply-To: <1377873604-15519-2-git-send-email-sanimir.agovic@intel.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-SW-Source: 2013-08/txt/msg00919.txt.bz2 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 "", line 1, in > TypeError: cannot create 'gdb.Frame' instances > Error while executing Python code. > > 2013-08-30 Sanimir Agovic 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