summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@codefactory.se>2003-01-14 11:19:06 +0000
committerAnders Carlsson <andersca@codefactory.se>2003-01-14 11:19:06 +0000
commit1b9a4589f6836641ded324b7b5d003c5cbfb0b78 (patch)
treef2e1993b8d95b447e1a0f203065044a18c12a984
parenta22c4589d8cc14d94537694476dc96c33c2bfcb4 (diff)
2003-01-14 Anders Carlsson <andersca@codefactory.se>
* bus/connection.c: (connection_error_handler), (bus_connection_setup): * bus/main.c: (main): Make sure that the DBusConnectionData struct is NULLed out to prevent a segfault. * dbus/dbus-errors.c: (dbus_result_to_string): * dbus/dbus-errors.h: * dbus/dbus-message.c: (dbus_message_get_fields), (dbus_message_get_fields_valist), (_dbus_message_test): * dbus/dbus-message.h: Make dbus_message_get_fields return a result code so we can track invalid fields as well as oom.
-rw-r--r--ChangeLog16
-rw-r--r--bus/connection.c5
-rw-r--r--bus/main.c3
-rw-r--r--dbus/dbus-errors.c2
-rw-r--r--dbus/dbus-errors.h3
-rw-r--r--dbus/dbus-message.c46
-rw-r--r--dbus/dbus-message.h37
7 files changed, 72 insertions, 40 deletions
diff --git a/ChangeLog b/ChangeLog
index 6113d53e..6a759cf5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2003-01-14 Anders Carlsson <andersca@codefactory.se>
+
+ * bus/connection.c: (connection_error_handler),
+ (bus_connection_setup):
+ * bus/main.c: (main):
+ Make sure that the DBusConnectionData struct is NULLed
+ out to prevent a segfault.
+
+ * dbus/dbus-errors.c: (dbus_result_to_string):
+ * dbus/dbus-errors.h:
+ * dbus/dbus-message.c: (dbus_message_get_fields),
+ (dbus_message_get_fields_valist), (_dbus_message_test):
+ * dbus/dbus-message.h:
+ Make dbus_message_get_fields return a result code so we can
+ track invalid fields as well as oom.
+
2003-01-11 Havoc Pennington <hp@pobox.com>
* configure.in: change --enable-test/--enable-ansi action-if-given
diff --git a/bus/connection.c b/bus/connection.c
index 5b7c5391..f4c19dd2 100644
--- a/bus/connection.c
+++ b/bus/connection.c
@@ -43,7 +43,7 @@ connection_error_handler (DBusConnection *connection,
{
BusConnectionData *d;
BusService *service;
-
+
_dbus_warn ("Error on connection: %s\n",
dbus_result_to_string (error_code));
@@ -123,7 +123,8 @@ bus_connection_setup (DBusConnection *connection)
{
BusConnectionData *d;
- d = dbus_new (BusConnectionData, 1);
+ d = dbus_new0 (BusConnectionData, 1);
+
if (d == NULL)
return FALSE;
diff --git a/bus/main.c b/bus/main.c
index 77fb1440..27720fbc 100644
--- a/bus/main.c
+++ b/bus/main.c
@@ -95,7 +95,8 @@ main (int argc, char **argv)
dbus_server_set_new_connection_function (server,
new_connection_callback,
NULL, NULL);
-
+
+ _dbus_verbose ("We are on D-Bus...\n");
bus_loop_run ();
dbus_server_disconnect (server);
diff --git a/dbus/dbus-errors.c b/dbus/dbus-errors.c
index 1214c1f5..223750e7 100644
--- a/dbus/dbus-errors.c
+++ b/dbus/dbus-errors.c
@@ -99,6 +99,8 @@ dbus_result_to_string (DBusResultCode code)
return "Address already in use";
case DBUS_RESULT_DISCONNECTED:
return "Disconnected.";
+ case DBUS_RESULT_INVALID_FIELDS:
+ return "Invalid fields.";
/* no default, it would break our compiler warnings */
}
diff --git a/dbus/dbus-errors.h b/dbus/dbus-errors.h
index d45e2f37..4dd87677 100644
--- a/dbus/dbus-errors.h
+++ b/dbus/dbus-errors.h
@@ -49,7 +49,8 @@ typedef enum
DBUS_RESULT_TIMEOUT, /**< Timed out trying to connect. */
DBUS_RESULT_NO_NETWORK, /**< Can't find the network */
DBUS_RESULT_ADDRESS_IN_USE, /**< Someone's already using the address */
- DBUS_RESULT_DISCONNECTED /**< No more connection. */
+ DBUS_RESULT_DISCONNECTED, /**< No more connection. */
+ DBUS_RESULT_INVALID_FIELDS /**< One or more invalid fields encountered. */
} DBusResultCode;
void dbus_set_result (DBusResultCode *code_address,
diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c
index 041bf667..3bd92803 100644
--- a/dbus/dbus-message.c
+++ b/dbus/dbus-message.c
@@ -543,14 +543,14 @@ dbus_message_append_byte_array (DBusMessage *message,
* @param message the message
* @param first_field_type the first field type
* @param ... location for first field value, then list of type-location pairs
- * @returns #TRUE on success
+ * @returns result code
*/
-dbus_bool_t
+DBusResultCode
dbus_message_get_fields (DBusMessage *message,
int first_field_type,
...)
{
- dbus_bool_t retval;
+ DBusResultCode retval;
va_list var_args;
va_start (var_args, first_field_type);
@@ -570,13 +570,15 @@ dbus_message_get_fields (DBusMessage *message,
* to the arg that's bad, as that would be a security hole
* (allow one app to force another to leak memory)
*
+ * @todo We need to free the field data when an error occurs.
+ *
* @see dbus_message_get_fields
* @param message the message
* @param first_field_type type of the first field
* @param var_args return location for first field, followed by list of type/location pairs
- * @returns #TRUE on success
+ * @returns result code
*/
-dbus_bool_t
+DBusResultCode
dbus_message_get_fields_valist (DBusMessage *message,
int first_field_type,
va_list var_args)
@@ -598,13 +600,13 @@ dbus_message_get_fields_valist (DBusMessage *message,
if (msg_type != spec_type)
{
- _dbus_warn ("Field %d is specified to be of type \"%s\", but "
- "is actually of type \"%s\"\n", i,
- _dbus_type_to_string (spec_type),
- _dbus_type_to_string (msg_type));
+ _dbus_verbose ("Field %d is specified to be of type \"%s\", but "
+ "is actually of type \"%s\"\n", i,
+ _dbus_type_to_string (spec_type),
+ _dbus_type_to_string (msg_type));
dbus_message_iter_unref (iter);
- return FALSE;
+ return DBUS_RESULT_INVALID_FIELDS;
}
switch (spec_type)
@@ -645,6 +647,10 @@ dbus_message_get_fields_valist (DBusMessage *message,
ptr = va_arg (var_args, char **);
*ptr = dbus_message_iter_get_string (iter);
+
+ if (!*ptr)
+ return DBUS_RESULT_NO_MEMORY;
+
break;
}
@@ -657,6 +663,10 @@ dbus_message_get_fields_valist (DBusMessage *message,
len = va_arg (var_args, int *);
*ptr = dbus_message_iter_get_byte_array (iter, len);
+
+ if (!*ptr)
+ return DBUS_RESULT_NO_MEMORY;
+
break;
}
default:
@@ -666,16 +676,16 @@ dbus_message_get_fields_valist (DBusMessage *message,
spec_type = va_arg (var_args, int);
if (spec_type != 0 && !dbus_message_iter_next (iter))
{
- _dbus_warn ("More fields than exist in the message were specified\n");
+ _dbus_verbose ("More fields than exist in the message were specified\n");
dbus_message_iter_unref (iter);
- return FALSE;
+ return DBUS_RESULT_INVALID_FIELDS;
}
i++;
}
dbus_message_iter_unref (iter);
- return TRUE;
+ return DBUS_RESULT_SUCCESS;
}
/**
@@ -1338,11 +1348,11 @@ _dbus_message_test (void)
DBUS_TYPE_DOUBLE, 3.14159,
0);
- if (!dbus_message_get_fields (message,
- DBUS_TYPE_INT32, &our_int,
- DBUS_TYPE_STRING, &our_str,
- DBUS_TYPE_DOUBLE, &our_double,
- 0))
+ if (dbus_message_get_fields (message,
+ DBUS_TYPE_INT32, &our_int,
+ DBUS_TYPE_STRING, &our_str,
+ DBUS_TYPE_DOUBLE, &our_double,
+ 0) != DBUS_RESULT_SUCCESS)
_dbus_assert_not_reached ("Could not get fields");
if (our_int != -0x12345678)
diff --git a/dbus/dbus-message.h b/dbus/dbus-message.h
index f1b49f9b..5da95796 100644
--- a/dbus/dbus-message.h
+++ b/dbus/dbus-message.h
@@ -65,25 +65,26 @@ dbus_bool_t dbus_message_append_byte_array (DBusMessage *message,
DBusMessageIter *dbus_message_get_fields_iter (DBusMessage *message);
+DBusResultCode dbus_message_get_fields (DBusMessage *message,
+ int first_field_type,
+ ...);
+DBusResultCode dbus_message_get_fields_valist (DBusMessage *message,
+ int first_field_type,
+ va_list var_args);
+
+void dbus_message_iter_ref (DBusMessageIter *iter);
+void dbus_message_iter_unref (DBusMessageIter *iter);
+
+dbus_bool_t dbus_message_iter_has_next (DBusMessageIter *iter);
+dbus_bool_t dbus_message_iter_next (DBusMessageIter *iter);
+int dbus_message_iter_get_field_type (DBusMessageIter *iter);
+int dbus_message_iter_get_int32 (DBusMessageIter *iter);
+int dbus_message_iter_get_uint32 (DBusMessageIter *iter);
+double dbus_message_iter_get_double (DBusMessageIter *iter);
+char * dbus_message_iter_get_string (DBusMessageIter *iter);
+unsigned char * dbus_message_iter_get_byte_array (DBusMessageIter *iter,
+ int *len);
-dbus_bool_t dbus_message_get_fields (DBusMessage *message,
- int first_field_type,
- ...);
-dbus_bool_t dbus_message_get_fields_valist (DBusMessage *message,
- int first_field_type,
- va_list var_args);
-
-void dbus_message_iter_ref (DBusMessageIter *iter);
-void dbus_message_iter_unref (DBusMessageIter *iter);
-
-dbus_bool_t dbus_message_iter_has_next (DBusMessageIter *iter);
-dbus_bool_t dbus_message_iter_next (DBusMessageIter *iter);
-int dbus_message_iter_get_field_type (DBusMessageIter *iter);
-int dbus_message_iter_get_int32 (DBusMessageIter *iter);
-int dbus_message_iter_get_uint32 (DBusMessageIter *iter);
-double dbus_message_iter_get_double (DBusMessageIter *iter);
-char * dbus_message_iter_get_string (DBusMessageIter *iter);
-unsigned char *dbus_message_iter_get_byte_array (DBusMessageIter *iter, int *len);