Browse Source

dbus.c: Handle invalid bus names

This makes the following code produce a Lua error instead of crashing
AwesomeWM:

  dbus.emit_signal("foobar", "/", "org.awesome.SomeInterface", "method",
      "s", "string argument")

The crash looked like this:

  dbus[710]: arguments to dbus_connection_send() were incorrect, assertion
      "connection != NULL" failed in file dbus/dbus-connection.c line 3307.
  This is normally a bug in some application using the D-Bus library.

Signed-off-by: Uli Schlachter <psychon@znc.in>
Uli Schlachter 5 months ago
parent
commit
ab7ac2e12a
1 changed files with 7 additions and 6 deletions
  1. 7
    6
      dbus.c

+ 7
- 6
dbus.c View File

@@ -660,12 +660,13 @@ a_dbus_cleanup(void)
660 660
  * \return The corresponding D-Bus connection.
661 661
  */
662 662
 static DBusConnection *
663
-a_dbus_bus_getbyname(const char *name)
663
+a_dbus_bus_getbyname(lua_State *L, const char *name)
664 664
 {
665 665
     if(A_STREQ(name, "system"))
666 666
         return dbus_connection_system;
667 667
     if(A_STREQ(name, "session"))
668 668
         return dbus_connection_session;
669
+    luaL_error(L, "Unknown dbus connection '%s', only 'system' and 'session' are valid", name);
669 670
     return NULL;
670 671
 }
671 672
 
@@ -681,7 +682,7 @@ luaA_dbus_request_name(lua_State *L)
681 682
 {
682 683
     const char *bus = luaL_checkstring(L, 1);
683 684
     const char *name = luaL_checkstring(L, 2);
684
-    DBusConnection *dbus_connection = a_dbus_bus_getbyname(bus);
685
+    DBusConnection *dbus_connection = a_dbus_bus_getbyname(L, bus);
685 686
     lua_pushboolean(L, a_dbus_request_name(dbus_connection, name));
686 687
     return 1;
687 688
 }
@@ -698,7 +699,7 @@ luaA_dbus_release_name(lua_State *L)
698 699
 {
699 700
     const char *bus = luaL_checkstring(L, 1);
700 701
     const char *name = luaL_checkstring(L, 2);
701
-    DBusConnection *dbus_connection = a_dbus_bus_getbyname(bus);
702
+    DBusConnection *dbus_connection = a_dbus_bus_getbyname(L, bus);
702 703
     lua_pushboolean(L, a_dbus_release_name(dbus_connection, name));
703 704
     return 1;
704 705
 }
@@ -714,7 +715,7 @@ luaA_dbus_add_match(lua_State *L)
714 715
 {
715 716
     const char *bus = luaL_checkstring(L, 1);
716 717
     const char *name = luaL_checkstring(L, 2);
717
-    DBusConnection *dbus_connection = a_dbus_bus_getbyname(bus);
718
+    DBusConnection *dbus_connection = a_dbus_bus_getbyname(L, bus);
718 719
 
719 720
     if(dbus_connection)
720 721
     {
@@ -737,7 +738,7 @@ luaA_dbus_remove_match(lua_State *L)
737 738
 {
738 739
     const char *bus = luaL_checkstring(L, 1);
739 740
     const char *name = luaL_checkstring(L, 2);
740
-    DBusConnection *dbus_connection = a_dbus_bus_getbyname(bus);
741
+    DBusConnection *dbus_connection = a_dbus_bus_getbyname(L, bus);
741 742
 
742 743
     if(dbus_connection)
743 744
     {
@@ -811,7 +812,7 @@ luaA_dbus_emit_signal(lua_State *L)
811 812
     const char *path = luaL_checkstring(L, 2);
812 813
     const char *itface = luaL_checkstring(L, 3);
813 814
     const char *name = luaL_checkstring(L, 4);
814
-    DBusConnection *dbus_connection = a_dbus_bus_getbyname(bus_name);
815
+    DBusConnection *dbus_connection = a_dbus_bus_getbyname(L, bus_name);
815 816
     DBusMessage* msg = dbus_message_new_signal(path, itface, name);
816 817
     if (msg == NULL) {
817 818
         luaA_warn(L, "your D-Bus signal emitting method error'd");

Loading…
Cancel
Save