In Gtk+-1.2.3, gdk_atom_name() may return NULL if the
atom's name cannot be retrieved.
In pygtk-0.6.1, PyGdkAtom_Str() expects gdk_atom_name()
to return a valid, null-terminated string.
As a result, if you invoke gtk.atom_name() on an atom
whose name cannot be found, you'll get a core dump.
The first attachment is a simple example of the problem,
derived from the Gtk+ tutorial on selections. If you run
this when there is no primary selection, it should dump
core when attempting to print seldata.type, in method
Test.selectionReceivedEH().
The second attachment is a context diff for a patch
to gtkmodule.c. It raises a ValueError if an atom has no
name.
--
Mitch Chapman
[EMAIL PROTECTED]
# Cause a core dump in atom_name().
from gtk import *
import GDK
# Add some missing constants to GDK:
GDK.SELECTION_PRIMARY = 1
GDK.SELECTION_SECONDARY = 2
GDK.CURRENT_TIME = 0L
class Test:
def __init__(self):
w = self.win = GtkWindow()
w.connect("delete_event", mainquit)
w.connect("selection_received", self.selectionReceivedEH)
t = self.table = GtkTable()
w.add(t)
t.show()
btn = GtkButton("Clear All Selections")
btn.connect("clicked", self.clearAllSelections)
t.attach(btn, 0, 1, 0, 1)
btn.show()
btn = GtkButton("List Targets")
btn.connect("clicked", self.listTargets)
t.attach(btn, 0, 1, 1, 2)
btn.show()
w.show()
def clearAllSelections(self, *args):
self.win.selection_remove_all()
def listTargets(self, *args):
targets = atom_intern("TARGETS")
self.win.selection_convert(GDK.SELECTION_PRIMARY, targets,
GDK.CURRENT_TIME)
def selectionReceivedEH(self, widget, seldata, *args):
print 72 * "_"
print "selectionReceivedEH:", seldata, args
print "Selection:", seldata.selection
print "Target: ", seldata.target
print "Type: ", seldata.type
print "Format: ", seldata.format
print "Data: ", seldata.data
def main():
"""Module mainline (for standalone execution)"""
t = Test()
mainloop()
if __name__ == "__main__":
main()
*** gtkmodule.c Fri Jun 25 15:51:47 1999
--- gtkmodule.c.orig Wed Jun 23 18:40:25 1999
***************
*** 2008,2019 ****
static PyObject *
PyGdkAtom_Str(PyGdkAtom_Object *self) {
if (!self->name) self->name = gdk_atom_name(self->atom);
! if (self->name)
! {
! return PyString_FromString(self->name);
! }
! PyErr_SetString(PyExc_ValueError, "Atom has NULL name");
! return NULL;
}
static PyNumberMethods PyGdkAtom_Number = {
--- 2008,2014 ----
static PyObject *
PyGdkAtom_Str(PyGdkAtom_Object *self) {
if (!self->name) self->name = gdk_atom_name(self->atom);
! return PyString_FromString(self->name);
}
static PyNumberMethods PyGdkAtom_Number = {