Skip to content

Instantly share code, notes, and snippets.

@txus
Created January 5, 2016 11:10
Show Gist options
  • Save txus/8fd7842dbb3ea11ab102 to your computer and use it in GitHub Desktop.
Save txus/8fd7842dbb3ea11ab102 to your computer and use it in GitHub Desktop.
Python is crazy

Usage

You'll need dbus running. In a console:

python server.py

In another console:

python client.py

Exposing the bug

In server.py line 32, replace:

bus_name = dbus.service.BusName('org.example.Ui', bus)

With:

dbus.service.BusName('org.example.Ui', bus)

Hypothesis

I'm guessing BusName initializes an object that in its construction has the side effect of publishing a service on dbus, and if it's not assigned to anything, the python interpreter discards it, and thus destroys it, which probably causes the dbus service to disappear. Bonkers.

#!/usr/bin/env python
import dbus
bus = dbus.SessionBus()
service_name = 'org.example.Ui'
ui = bus.get_object(service_name, '/')
iface = dbus.Interface(ui, dbus_interface=service_name)
iface.LaunchBrowser()
#!/usr/bin/env python
import gobject
import dbus
import dbus.service
import dbus.mainloop.glib
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
class Ui(dbus.service.Object):
def __init__(self, bus, path):
# Set up any needed state (hopefully none)
dbus.service.Object.__init__(self, bus, path)
@dbus.service.method("org.example.Ui",
in_signature='', out_signature='')
def LaunchBrowser(self):
logger.info("launchin' the browser")
if __name__ == '__main__':
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
loop = gobject.MainLoop()
bus = dbus.SessionBus()
bus_name = dbus.service.BusName('org.example.Ui', bus)
Ui(bus, '/')
loop.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment