dbus.c: Check string return values properly

Apparently some versions of dbus kill the process with a failed assertion if
invalid UTF8 should be send out. Mine doesn't. Also, our behaviour of replacing
non-strings silently with strings is weird.

This commit thus makes converting from Lua to dbus fail if a non-string should
be sent as a string or if a string contains malformed UTF8.

Fixes: https://github.com/awesomeWM/awesome/issues/728
Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2016-03-06 11:16:49 +01:00
parent 77507a2877
commit 7f43608d73
1 changed files with 4 additions and 2 deletions

6
dbus.c
View File

@ -318,8 +318,10 @@ a_dbus_convert_value(lua_State *L, int idx, DBusMessageIter *iter)
case DBUS_TYPE_STRING: case DBUS_TYPE_STRING:
{ {
const char *s = lua_tostring(L, idx + 1); const char *s = lua_tostring(L, idx + 1);
if(!s) if(!s || !dbus_validate_utf8(s, NULL)) {
s = ""; luaA_warn(L, "Your D-Bus signal handling method returned an invalid string");
return false;
}
dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &s); dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &s);
} }
break; break;