dbus library calls abort() if it got a non-expected type passed to it. --- Changelog: v4: - Do not touch values_received - Set wps=true only if WPS info is successfully received - Set error on all failing type-checks v3: Fix embarrassing typo v2: Check against specific type instead of all basic types
src/agent-connman.c | 92 +++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 79 insertions(+), 13 deletions(-) diff --git a/src/agent-connman.c b/src/agent-connman.c index 2d714b5..fca7cc1 100644 --- a/src/agent-connman.c +++ b/src/agent-connman.c @@ -100,43 +100,77 @@ static void request_input_passphrase_reply(DBusMessage *reply, void *user_data) DBusMessageIter entry, value; dbus_message_iter_recurse(&dict, &entry); - if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING) + if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING) { + error = CONNMAN_ERROR_INTERFACE ".InvalidArguments"; break; + } dbus_message_iter_get_basic(&entry, &key); if (g_str_equal(key, "Identity")) { dbus_message_iter_next(&entry); if (dbus_message_iter_get_arg_type(&entry) - != DBUS_TYPE_VARIANT) + != DBUS_TYPE_VARIANT) { + error = CONNMAN_ERROR_INTERFACE ".InvalidArguments"; break; + } + dbus_message_iter_recurse(&entry, &value); + if (dbus_message_iter_get_arg_type(&value) != DBUS_TYPE_STRING) { + error = CONNMAN_ERROR_INTERFACE ".InvalidArguments"; + break; + } + dbus_message_iter_get_basic(&value, &identity); } else if (g_str_equal(key, "Passphrase")) { dbus_message_iter_next(&entry); if (dbus_message_iter_get_arg_type(&entry) - != DBUS_TYPE_VARIANT) + != DBUS_TYPE_VARIANT) { + error = CONNMAN_ERROR_INTERFACE ".InvalidArguments"; break; + } + dbus_message_iter_recurse(&entry, &value); + if (dbus_message_iter_get_arg_type(&value) != DBUS_TYPE_STRING) { + error = CONNMAN_ERROR_INTERFACE ".InvalidArguments"; + break; + } + dbus_message_iter_get_basic(&value, &passphrase); } else if (g_str_equal(key, "WPS")) { - wps = true; dbus_message_iter_next(&entry); if (dbus_message_iter_get_arg_type(&entry) - != DBUS_TYPE_VARIANT) + != DBUS_TYPE_VARIANT) { + error = CONNMAN_ERROR_INTERFACE ".InvalidArguments"; break; + } + dbus_message_iter_recurse(&entry, &value); + if (dbus_message_iter_get_arg_type(&value) != DBUS_TYPE_STRING) { + error = CONNMAN_ERROR_INTERFACE ".InvalidArguments"; + break; + } + + wps = true; dbus_message_iter_get_basic(&value, &wpspin); break; } else if (g_str_equal(key, "Name")) { dbus_message_iter_next(&entry); if (dbus_message_iter_get_arg_type(&entry) - != DBUS_TYPE_VARIANT) + != DBUS_TYPE_VARIANT) { + error = CONNMAN_ERROR_INTERFACE ".InvalidArguments"; break; + } + dbus_message_iter_recurse(&entry, &value); + if (dbus_message_iter_get_arg_type(&value) != DBUS_TYPE_STRING) { + error = CONNMAN_ERROR_INTERFACE ".InvalidArguments"; + break; + } + dbus_message_iter_get_basic(&value, &name); name_len = strlen(name); } else if (g_str_equal(key, "SSID")) { @@ -144,16 +178,22 @@ static void request_input_passphrase_reply(DBusMessage *reply, void *user_data) dbus_message_iter_next(&entry); if (dbus_message_iter_get_arg_type(&entry) - != DBUS_TYPE_VARIANT) + != DBUS_TYPE_VARIANT) { + error = CONNMAN_ERROR_INTERFACE ".InvalidArguments"; break; + } dbus_message_iter_recurse(&entry, &value); if (dbus_message_iter_get_arg_type(&value) - != DBUS_TYPE_ARRAY) + != DBUS_TYPE_ARRAY) { + error = CONNMAN_ERROR_INTERFACE ".InvalidArguments"; break; + } dbus_message_iter_recurse(&value, &array_iter); if (dbus_message_iter_get_arg_type(&array_iter) - != DBUS_TYPE_BYTE) + != DBUS_TYPE_BYTE) { + error = CONNMAN_ERROR_INTERFACE ".InvalidArguments"; break; + } dbus_message_iter_get_fixed_array(&array_iter, &name, &name_len); } @@ -399,17 +439,33 @@ static void request_input_login_reply(DBusMessage *reply, void *user_data) if (g_str_equal(key, "Username")) { dbus_message_iter_next(&entry); if (dbus_message_iter_get_arg_type(&entry) - != DBUS_TYPE_VARIANT) + != DBUS_TYPE_VARIANT) { + error = CONNMAN_ERROR_INTERFACE ".InvalidArguments"; break; + } + dbus_message_iter_recurse(&entry, &value); + if (dbus_message_iter_get_arg_type(&value) != DBUS_TYPE_STRING) { + error = CONNMAN_ERROR_INTERFACE ".InvalidArguments"; + break; + } + dbus_message_iter_get_basic(&value, &username); } else if (g_str_equal(key, "Password")) { dbus_message_iter_next(&entry); if (dbus_message_iter_get_arg_type(&entry) != - DBUS_TYPE_VARIANT) + DBUS_TYPE_VARIANT) { + error = CONNMAN_ERROR_INTERFACE ".InvalidArguments"; break; + } + dbus_message_iter_recurse(&entry, &value); + if (dbus_message_iter_get_arg_type(&value) != DBUS_TYPE_STRING) { + error = CONNMAN_ERROR_INTERFACE ".InvalidArguments"; + break; + } + dbus_message_iter_get_basic(&value, &password); } @@ -705,8 +761,10 @@ static void request_peer_authorization_reply(DBusMessage *reply, DBusMessageIter entry, value; dbus_message_iter_recurse(&dict, &entry); - if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING) + if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING) { + error = CONNMAN_ERROR_INTERFACE ".InvalidArguments"; break; + } dbus_message_iter_get_basic(&entry, &key); @@ -715,9 +773,17 @@ static void request_peer_authorization_reply(DBusMessage *reply, dbus_message_iter_next(&entry); if (dbus_message_iter_get_arg_type(&entry) - != DBUS_TYPE_VARIANT) + != DBUS_TYPE_VARIANT) { + error = CONNMAN_ERROR_INTERFACE ".InvalidArguments"; break; + } + dbus_message_iter_recurse(&entry, &value); + if (dbus_message_iter_get_arg_type(&value) != DBUS_TYPE_STRING) { + error = CONNMAN_ERROR_INTERFACE ".InvalidArguments"; + break; + } + dbus_message_iter_get_basic(&value, &wpspin); break; } -- 1.9.1 _______________________________________________ connman mailing list connman@connman.net https://lists.connman.net/mailman/listinfo/connman