g_dbus_is_supported_address(): set error if returning FALSE

Previously, calling:

    g_dbus_is_supported_address ("some-imaginary-transport:", NULL)

correctly returned FALSE; but calling:

    g_dbus_is_supported_address ("some-imaginary-transport:", &error)

crashed with:

    GLib-GIO:ERROR:../gio/gdbusaddress.c:434:g_dbus_is_supported_address:
    assertion failed: (ret || (!ret && (error == NULL || *error != NULL)))

This was because, if the address component did not start with a known
transport, no error was set. Fix this, reusing an error string used by
the corresponding else branch in g_dbus_address_connect(), and adjust
the test to pass both NULL and non-NULL GError **s to this function in
every test case. This case:

    g_assert (!g_dbus_is_supported_address ("some-imaginary-transport:foo=bar;unix:path=/this/is/valid", NULL));

would have caught this bug with a non-NULL GError **.
This commit is contained in:
Will Thompson
2018-06-13 10:50:35 +01:00
parent e48a3920d4
commit ba7b035f5b
2 changed files with 53 additions and 28 deletions

View File

@@ -418,6 +418,10 @@ g_dbus_is_supported_address (const gchar *string,
supported = is_valid_nonce_tcp (a[n], key_value_pairs, error);
else if (g_strcmp0 (a[n], "autolaunch:") == 0)
supported = TRUE;
else
g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
_("Unknown or unsupported transport “%s” for address “%s”"),
transport_name, a[n]);
g_free (transport_name);
g_hash_table_unref (key_value_pairs);