}
g_debug ("[KDBUS] receive pool size set to %" G_GUINT64_FORMAT "\n", receive_pool_size);
- worker->receive_pool_size = receive_pool_size;
+ worker->receive_pool_size = receive_pool_size;
cmd->pool_size = worker->receive_pool_size;
-
+
item = cmd->items;
item->size = G_STRUCT_OFFSET (struct kdbus_item, str) + conn_name_size + 1;
item->type = KDBUS_ITEM_CONN_DESCRIPTION;
memcpy (worker->bus_id, cmd->id128, 16);
worker->unique_id = cmd->id;
- asprintf (&worker->unique_name, ":1.%llu", (unsigned long long) cmd->id);
+ if (asprintf (&worker->unique_name, ":1.%llu", (unsigned long long) cmd->id) < 0)
+ {
+ g_set_error (error,
+ G_IO_ERROR,
+ G_IO_ERROR_UNKNOWN,
+ "asprintf error: %s",
+ g_strerror(errno));
+ return NULL;
+ }
/* read bloom filters parameters */
bloom = NULL;
{
gchar *unique_name;
- asprintf (&unique_name, ":1.%llu", name->id);
+ if (asprintf (&unique_name, ":1.%llu", name->id) < 0)
+ {
+ g_set_error (error,
+ G_IO_ERROR,
+ G_IO_ERROR_UNKNOWN,
+ "asprintf error: %s",
+ g_strerror(errno));
+ goto error;
+ }
+
expand_strv (&listnames, unique_name);
prev_id = name->id;
}
g_kdbus_free_data (worker, cmd.offset);
return listnames;
+
+error:
+ g_strfreev(listnames);
+ return NULL;
}
if (flags & G_DBUS_CREDS_UNIQUE_NAME)
{
- asprintf (&creds->unique_name, ":1.%llu", (unsigned long long) conn_info->id);
- //TODO: Error handling
+ if (asprintf (&creds->unique_name, ":1.%llu", (unsigned long long) conn_info->id) < 0)
+ {
+ g_set_error (error,
+ G_DBUS_ERROR,
+ G_DBUS_ERROR_FAILED,
+ "asprintf error: %s",
+ g_strerror(errno));
+ goto error;
+ }
}
KDBUS_ITEM_FOREACH(item, conn_info, items)
break;
case MATCH_ELEMENT_ARGN:
- asprintf (&type, "arg%u", element->arg);
- g_kdbus_bloom_add_pair (worker, bloom, type, element->value);
- free (type);
+ if (asprintf (&type, "arg%u", element->arg) < 0)
+ {
+ g_set_error (error,
+ G_DBUS_ERROR,
+ G_DBUS_ERROR_FAILED,
+ "asprintf failed: %s", g_strerror(errno));
+ match_free (match);
+ return FALSE;
+ }
+ else
+ {
+ g_kdbus_bloom_add_pair (worker, bloom, type, element->value);
+ free (type);
+ }
break;
case MATCH_ELEMENT_ARGNPATH:
- asprintf (&type, "arg%u-slash-prefix", element->arg);
- g_kdbus_bloom_add_pair (worker, bloom, type, element->value);
- free (type);
+ if (asprintf (&type, "arg%u-slash-prefix", element->arg) < 0)
+ {
+ g_set_error (error,
+ G_DBUS_ERROR,
+ G_DBUS_ERROR_FAILED,
+ "asprintf failed: %s", g_strerror(errno));
+ match_free (match);
+ return FALSE;
+ }
+ else
+ {
+ g_kdbus_bloom_add_pair (worker, bloom, type, element->value);
+ free (type);
+ }
break;
case MATCH_ELEMENT_ARG0NAMESPACE:
(kmsg->sender_seclabel != NULL))
{
gint check;
- gchar *destination = g_dbus_message_get_destination (kmsg->message);
+ const gchar *destination = g_dbus_message_get_destination (kmsg->message);
if (!destination)
destination = worker->unique_name;
{
int ret = errno;
gchar *info;
- asprintf (&info, "sender=%s destination=%s path=%s interface=%s member=%s type=%d",
+ if (asprintf (&info, "sender=%s destination=%s path=%s interface=%s member=%s type=%d",
g_dbus_message_get_sender (message),
g_dbus_message_get_destination (message),
g_dbus_message_get_path (message),
g_dbus_message_get_interface (message),
g_dbus_message_get_member (message),
- g_dbus_message_get_message_type (message));
-
- errno = ret;
- if (errno == ENXIO || errno == ESRCH)
- {
- if (g_dbus_message_get_flags (message) & G_DBUS_MESSAGE_FLAGS_NO_AUTO_START)
- g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_NAME_HAS_NO_OWNER,
- "Name \"%s\" does not exist, %s", dst_name, info);
- else
- g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_SERVICE_UNKNOWN,
- "Destination '%s' not known, %s", dst_name, info);
- }
- else if (errno == EADDRNOTAVAIL)
- {
- g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_SERVICE_UNKNOWN,
- "No support for activation for name: %s, %s", dst_name, info);
- }
- else if (errno == EXFULL)
- {
- g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_LIMITS_EXCEEDED,
- "The memory pool of the receiver is full, %s", info);
- }
- else if (errno == ENOBUFS)
+ g_dbus_message_get_message_type (message)) < 0)
{
- g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_LIMITS_EXCEEDED,
- "Too many pending messages on the receiver side, %s", info);
- }
- else if (errno == EMSGSIZE)
- {
- g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_LIMITS_EXCEEDED,
- "The size of the message is excessive, %s", info);
- }
- else if (errno == EMLINK)
- {
- g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_LIMITS_EXCEEDED,
- "The maximum number of pending replies per connection has been reached, %s", info);
- }
- else if (errno == ECANCELED)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_CANCELLED,
- "Operation was cancelled, %s", info);
- }
- else if (errno == ETIMEDOUT)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_TIMED_OUT,
- "Timeout was reached, %s", info);
- }
- else if (errno == EPERM)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED,
- "Permission denied, %s", info);
+ g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "%s", g_strerror(errno));
+ /* If asprintf fails, we lose the ioctl errno,
+ * but without info, we can't give a useful error message.
+ * In practice though, asprintf failure is exceedingly rare.
+ */
}
else
{
- g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "%s, %s", g_strerror(errno), info);
- g_warning ("kdbus: %s, %s", g_strerror(errno), info);
+ errno = ret;
+ if (errno == ENXIO || errno == ESRCH)
+ {
+ if (g_dbus_message_get_flags (message) & G_DBUS_MESSAGE_FLAGS_NO_AUTO_START)
+ g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_NAME_HAS_NO_OWNER,
+ "Name \"%s\" does not exist, %s", dst_name, info);
+ else
+ g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_SERVICE_UNKNOWN,
+ "Destination '%s' not known, %s", dst_name, info);
+ }
+ else if (errno == EADDRNOTAVAIL)
+ {
+ g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_SERVICE_UNKNOWN,
+ "No support for activation for name: %s, %s", dst_name, info);
+ }
+ else if (errno == EXFULL)
+ {
+ g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_LIMITS_EXCEEDED,
+ "The memory pool of the receiver is full, %s", info);
+ }
+ else if (errno == ENOBUFS)
+ {
+ g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_LIMITS_EXCEEDED,
+ "Too many pending messages on the receiver side, %s", info);
+ }
+ else if (errno == EMSGSIZE)
+ {
+ g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_LIMITS_EXCEEDED,
+ "The size of the message is excessive, %s", info);
+ }
+ else if (errno == EMLINK)
+ {
+ g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_LIMITS_EXCEEDED,
+ "The maximum number of pending replies per connection has been reached, %s", info);
+ }
+ else if (errno == ECANCELED)
+ {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_CANCELLED,
+ "Operation was cancelled, %s", info);
+ }
+ else if (errno == ETIMEDOUT)
+ {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_TIMED_OUT,
+ "Timeout was reached, %s", info);
+ }
+ else if (errno == EPERM)
+ {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED,
+ "Permission denied, %s", info);
+ }
+ else
+ {
+ g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "%s, %s", g_strerror(errno), info);
+ g_warning ("kdbus: %s, %s", g_strerror(errno), info);
+ }
+ free(info);
}
result = FALSE;
- free(info);
}
else if (out_reply != NULL)
{