gdbusauth: Represent empty data block as DATA\r\n, with no space

This is an interoperability fix. The reference implementation of D-Bus
treats "DATA\r\n" as equivalent to "DATA \r\n", but sd-bus does not,
and only accepts the former.

Signed-off-by: Simon McVittie <smcv@collabora.com>
This commit is contained in:
Simon McVittie 2022-07-18 17:14:44 +01:00
parent b51e3ab09e
commit 3f532af65c

View File

@ -807,11 +807,21 @@ _g_dbus_auth_run_client (GDBusAuth *auth,
{
gchar *data;
gsize data_len;
gchar *encoded_data;
data = _g_dbus_auth_mechanism_client_data_send (mech, &data_len);
encoded_data = _g_dbus_hexencode (data, data_len);
s = g_strdup_printf ("DATA %s\r\n", encoded_data);
g_free (encoded_data);
if (data_len == 0)
{
s = g_strdup ("DATA\r\n");
}
else
{
gchar *encoded_data = _g_dbus_hexencode (data, data_len);
s = g_strdup_printf ("DATA %s\r\n", encoded_data);
g_free (encoded_data);
}
g_free (data);
debug_print ("CLIENT: writing '%s'", s);
if (!g_data_output_stream_put_string (dos, s, cancellable, error))
@ -1209,13 +1219,21 @@ _g_dbus_auth_run_server (GDBusAuth *auth,
gsize data_len;
data = _g_dbus_auth_mechanism_server_data_send (mech, &data_len);
if (data != NULL)
{
gchar *encoded_data;
if (data_len == 0)
{
s = g_strdup ("DATA\r\n");
}
else
{
gchar *encoded_data = _g_dbus_hexencode (data, data_len);
s = g_strdup_printf ("DATA %s\r\n", encoded_data);
g_free (encoded_data);
}
encoded_data = _g_dbus_hexencode (data, data_len);
s = g_strdup_printf ("DATA %s\r\n", encoded_data);
g_free (encoded_data);
g_free (data);
debug_print ("SERVER: writing '%s'", s);