hal/libhal libhal.c,1.51,1.52

David Zeuthen david at freedesktop.org
Thu Jul 21 06:54:13 PDT 2005


Update of /cvs/hal/hal/libhal
In directory gabe:/tmp/cvs-serv28304/libhal

Modified Files:
	libhal.c 
Log Message:
2005-07-21  David Zeuthen  <davidz at redhat.com>

        * libhal/libhal.c: This is a fix to prevent segmentation faults in
        libhal if a function called with parameter LibHalContext *ctx ==
        NULL/0. Patch from Danny Kukawka <danny.kukawka at web.de>.



Index: libhal.c
===================================================================
RCS file: /cvs/hal/hal/libhal/libhal.c,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -d -r1.51 -r1.52
--- libhal.c	12 Jul 2005 15:02:25 -0000	1.51
+++ libhal.c	21 Jul 2005 13:54:11 -0000	1.52
@@ -224,8 +224,12 @@
 dbus_bool_t
 libhal_ctx_set_user_data(LibHalContext *ctx, void *user_data)
 {
-	if (ctx == NULL)
+	if (ctx == NULL) {
+		fprintf (stderr, 
+			 "%s %d : LibHalContext *ctx is NULL\n", 
+			 __FILE__, __LINE__);
 		return FALSE;
+	}
 	ctx->user_data = user_data;
 	return TRUE;
 }
@@ -239,6 +243,12 @@
 void*
 libhal_ctx_get_user_data(LibHalContext *ctx)
 {
+	if (ctx == NULL) {
+		fprintf (stderr, 
+			 "%s %d : LibHalContext *ctx is NULL\n", 
+			 __FILE__, __LINE__);
+		return NULL;
+	}
 	return ctx->user_data;
 }
 
@@ -348,6 +358,13 @@
 	LibHalProperty *p_last;
 	DBusError _error;
 
+	if (ctx == NULL) {
+		fprintf (stderr, 
+			 "%s %d : LibHalContext *ctx is NULL\n", 
+			 __FILE__, __LINE__);
+		return NULL;
+	}
+	
 	message = dbus_message_new_method_call ("org.freedesktop.Hal", udi,
 						"org.freedesktop.Hal.Device",
 						"GetAllProperties");
@@ -501,6 +518,9 @@
 	unsigned int num_elems;
 	LibHalProperty *p;
 
+	if (set == NULL)
+		return 0;
+	
 	num_elems = 0;
 	for (p = set->properties_head; p != NULL; p = p->next)
 		num_elems++;
@@ -517,6 +537,9 @@
 void
 libhal_psi_init (LibHalPropertySetIterator * iter, LibHalPropertySet * set)
 {
+	if (set == NULL)
+		return;
+
 	iter->set = set;
 	iter->index = 0;
 	iter->cur_prop = set->properties_head;
@@ -912,6 +935,13 @@
 	char **hal_device_names;
 	DBusError _error;
 
+	if (ctx == NULL) {
+		fprintf (stderr, 
+			 "%s %d : LibHalContext *ctx is NULL\n", 
+			 __FILE__, __LINE__);
+		return hal_device_names;
+	}
+
 	*num_devices = 0;
 
 	message = dbus_message_new_method_call ("org.freedesktop.Hal",
@@ -976,6 +1006,13 @@
 	int type;
 	DBusError _error;
 
+	if (ctx == NULL) {
+		fprintf (stderr, 
+			 "%s %d : LibHalContext *ctx is NULL\n", 
+			 __FILE__, __LINE__);
+		return LIBHAL_PROPERTY_TYPE_INVALID; // or NULL?
+	}
+
 	message = dbus_message_new_method_call ("org.freedesktop.Hal", udi,
 						"org.freedesktop.Hal.Device",
 						"GetPropertyType");
@@ -1035,6 +1072,13 @@
 	char **our_strings;
 	DBusError _error;
 
+	if (ctx == NULL) {
+		fprintf (stderr, 
+			 "%s %d : LibHalContext *ctx is NULL\n", 
+			 __FILE__, __LINE__);
+		return NULL;
+	}
+	
 	message = dbus_message_new_method_call ("org.freedesktop.Hal", udi,
 						"org.freedesktop.Hal.Device",
 						"GetPropertyStringList");
@@ -1104,6 +1148,13 @@
 	char *dbus_str;
 	DBusError _error;
 
+	if (ctx == NULL) {
+		fprintf (stderr, 
+			 "%s %d : LibHalContext *ctx is NULL\n", 
+			 __FILE__, __LINE__);
+		return NULL;
+	}
+	
 	message = dbus_message_new_method_call ("org.freedesktop.Hal", udi,
 						"org.freedesktop.Hal.Device",
 						"GetPropertyString");
@@ -1176,6 +1227,13 @@
 	dbus_int32_t value;
 	DBusError _error;
 
+	if (ctx == NULL) {
+		fprintf (stderr, 
+			 "%s %d : LibHalContext *ctx is NULL\n", 
+			 __FILE__, __LINE__);
+		return -1;
+	}
+
 	message = dbus_message_new_method_call ("org.freedesktop.Hal", udi,
 						"org.freedesktop.Hal.Device",
 						"GetPropertyInteger");
@@ -1243,6 +1301,13 @@
 	dbus_uint64_t value;
 	DBusError _error;
 
+	if (ctx == NULL) {
+		fprintf (stderr, 
+			 "%s %d : LibHalContext *ctx is NULL\n", 
+			 __FILE__, __LINE__);
+		return -1;
+	}
+
 	message = dbus_message_new_method_call ("org.freedesktop.Hal", udi,
 						"org.freedesktop.Hal.Device",
 						"GetPropertyInteger");
@@ -1309,6 +1374,13 @@
 	double value;
 	DBusError _error;
 
+	if (ctx == NULL) {
+		fprintf (stderr, 
+			 "%s %d : LibHalContext *ctx is NULL\n", 
+			 __FILE__, __LINE__);
+		return -1.0;
+	}
+	
 	message = dbus_message_new_method_call ("org.freedesktop.Hal", udi,
 						"org.freedesktop.Hal.Device",
 						"GetPropertyDouble");
@@ -1375,6 +1447,13 @@
 	dbus_bool_t value;
 	DBusError _error;
 
+	if (ctx == NULL) {
+		fprintf (stderr, 
+			 "%s %d : LibHalContext *ctx is NULL\n", 
+			 __FILE__, __LINE__);
+		return FALSE;
+	}
+	
 	message = dbus_message_new_method_call ("org.freedesktop.Hal", udi,
 						"org.freedesktop.Hal.Device",
 						"GetPropertyBoolean");
@@ -1441,6 +1520,13 @@
 	DBusMessageIter iter;
 	char *method_name = NULL;
 
+	if (ctx == NULL) {
+		fprintf (stderr, 
+			 "%s %d : LibHalContext *ctx is NULL\n", 
+			 __FILE__, __LINE__);
+		return FALSE;
+	}
+	
 	/** @todo  sanity check incoming params */
 	switch (type) {
 	case DBUS_TYPE_INVALID:
@@ -1666,6 +1752,13 @@
 	DBusMessage *reply;
 	DBusMessageIter iter;
 
+	if (ctx == NULL) {
+		fprintf (stderr, 
+			 "%s %d : LibHalContext *ctx is NULL\n", 
+			 __FILE__, __LINE__);
+		return FALSE;
+	}
+
 	message = dbus_message_new_method_call ("org.freedesktop.Hal", udi,
 						"org.freedesktop.Hal.Device",
 						"StringListAppend");
@@ -1716,6 +1809,13 @@
 	DBusMessage *reply;
 	DBusMessageIter iter;
 
+	if (ctx == NULL) {
+		fprintf (stderr, 
+			 "%s %d : LibHalContext *ctx is NULL\n", 
+			 __FILE__, __LINE__);
+		return FALSE;
+	}
+
 	message = dbus_message_new_method_call ("org.freedesktop.Hal", udi,
 						"org.freedesktop.Hal.Device",
 						"StringListPrepend");
@@ -1766,6 +1866,13 @@
 	DBusMessage *reply;
 	DBusMessageIter iter;
 
+	if (ctx == NULL) {
+		fprintf (stderr, 
+			 "%s %d : LibHalContext *ctx is NULL\n", 
+			 __FILE__, __LINE__);
+		return FALSE;
+	}
+
 	message = dbus_message_new_method_call ("org.freedesktop.Hal", udi,
 						"org.freedesktop.Hal.Device",
 						"StringListRemoveIndex");
@@ -1815,6 +1922,13 @@
 	DBusMessage *reply;
 	DBusMessageIter iter;
 
+	if (ctx == NULL) {
+		fprintf (stderr, 
+			 "%s %d : LibHalContext *ctx is NULL\n", 
+			 __FILE__, __LINE__);
+		return FALSE;
+	}
+
 	message = dbus_message_new_method_call ("org.freedesktop.Hal", udi,
 						"org.freedesktop.Hal.Device",
 						"StringListRemove");
@@ -1867,6 +1981,13 @@
 	DBusMessageIter iter;
 	DBusMessage *reply;
 
+	if (ctx == NULL) {
+		fprintf (stderr, 
+			 "%s %d : LibHalContext *ctx is NULL\n", 
+			 __FILE__, __LINE__);
+		return FALSE;
+	}
+
 	if (reason_why_locked != NULL)
 		*reason_why_locked = NULL;
 
@@ -1930,6 +2051,13 @@
 	DBusMessage *message;
 	DBusMessage *reply;
 
+	if (ctx == NULL) {
+		fprintf (stderr, 
+			 "%s %d : LibHalContext *ctx is NULL\n", 
+			 __FILE__, __LINE__);
+		return FALSE;
+	}
+
 	message = dbus_message_new_method_call ("org.freedesktop.Hal",
 						udi,
 						"org.freedesktop.Hal.Device",
@@ -1985,6 +2113,13 @@
 	char *value;
 	char *dbus_str;
 
+	if (ctx == NULL) {
+		fprintf (stderr, 
+			 "%s %d : LibHalContext *ctx is NULL\n", 
+			 __FILE__, __LINE__);
+		return NULL;
+	}
+
 	message = dbus_message_new_method_call ("org.freedesktop.Hal",
 						"/org/freedesktop/Hal/Manager",
 						"org.freedesktop.Hal.Manager",
@@ -2063,6 +2198,13 @@
 	DBusMessage *message;
 	DBusMessage *reply;
 	DBusMessageIter iter;
+	
+	if (ctx == NULL) {
+		fprintf (stderr, 
+			 "%s %d : LibHalContext *ctx is NULL\n", 
+			 __FILE__, __LINE__);
+		return FALSE;
+	}
 
 	message = dbus_message_new_method_call ("org.freedesktop.Hal",
 						"/org/freedesktop/Hal/Manager",
@@ -2117,6 +2259,13 @@
 	DBusMessage *reply;
 	DBusMessageIter iter;
 
+	if (ctx == NULL) {
+		fprintf (stderr, 
+			 "%s %d : LibHalContext *ctx is NULL\n", 
+			 __FILE__, __LINE__);
+		return FALSE;
+	}
+
 	message = dbus_message_new_method_call ("org.freedesktop.Hal",
 						"/org/freedesktop/Hal/Manager",
 						"org.freedesktop.Hal.Manager",
@@ -2166,6 +2315,13 @@
 	dbus_bool_t value;
 	DBusError _error;
 
+	if (ctx == NULL) {
+		fprintf (stderr, 
+			 "%s %d : LibHalContext *ctx is NULL\n", 
+			 __FILE__, __LINE__);
+		return FALSE;
+	}
+
 	message = dbus_message_new_method_call ("org.freedesktop.Hal",
 						"/org/freedesktop/Hal/Manager",
 						"org.freedesktop.Hal.Manager",
@@ -2233,6 +2389,13 @@
 	dbus_bool_t value;
 	DBusError _error;
 
+	if (ctx == NULL) {
+		fprintf (stderr, 
+			 "%s %d : LibHalContext *ctx is NULL\n", 
+			 __FILE__, __LINE__);
+		return FALSE;
+	}
+
 	message = dbus_message_new_method_call ("org.freedesktop.Hal", udi,
 						"org.freedesktop.Hal.Device",
 						"PropertyExists");
@@ -2296,6 +2459,13 @@
 	DBusMessage *reply;
 	DBusMessageIter iter;
 
+	if (ctx == NULL) {
+		fprintf (stderr, 
+			 "%s %d : LibHalContext *ctx is NULL\n", 
+			 __FILE__, __LINE__);
+		return FALSE;
+	}
+
 	message = dbus_message_new_method_call ("org.freedesktop.Hal",
 						"/org/freedesktop/Hal/Manager",
 						"org.freedesktop.Hal.Manager",
@@ -2361,6 +2531,13 @@
 	dbus_bool_t value;
 	DBusError _error;
 
+	if (ctx == NULL) {
+		fprintf (stderr, 
+			 "%s %d : LibHalContext *ctx is NULL\n", 
+			 __FILE__, __LINE__);
+		return FALSE;
+	}
+
 	message = dbus_message_new_method_call ("org.freedesktop.Hal",
 						"/org/freedesktop/Hal/Manager",
 						"org.freedesktop.Hal.Manager",
@@ -2427,6 +2604,13 @@
 	LibHalPropertySet *pset;
 	LibHalPropertySetIterator i;
 
+	if (ctx == NULL) {
+		fprintf (stderr, 
+			 "%s %d : LibHalContext *ctx is NULL\n", 
+			 __FILE__, __LINE__);
+		return FALSE;
+	}
+	
 	printf ("device_id = %s\n", udi);
 
 	if ((pset = libhal_device_get_all_properties (ctx, udi, error)) == NULL)
@@ -2511,6 +2695,13 @@
 	char **hal_device_names;
 	DBusError _error;
 
+	if (ctx == NULL) {
+		fprintf (stderr, 
+			 "%s %d : LibHalContext *ctx is NULL\n", 
+			 __FILE__, __LINE__);
+		return NULL;
+	}
+
 	message = dbus_message_new_method_call ("org.freedesktop.Hal",
 						"/org/freedesktop/Hal/Manager",
 						"org.freedesktop.Hal.Manager",
@@ -2577,6 +2768,13 @@
 	DBusMessage *reply;
 	DBusMessageIter iter;
 
+	if (ctx == NULL) {
+		fprintf (stderr, 
+			 "%s %d : LibHalContext *ctx is NULL\n", 
+			 __FILE__, __LINE__);
+		return FALSE;
+	}
+
 	message = dbus_message_new_method_call ("org.freedesktop.Hal", udi,
 						"org.freedesktop.Hal.Device",
 						"AddCapability");
@@ -2627,6 +2825,13 @@
 	unsigned int i;
 	dbus_bool_t ret;
 
+	if (ctx == NULL) {
+		fprintf (stderr, 
+			 "%s %d : LibHalContext *ctx is NULL\n", 
+			 __FILE__, __LINE__);
+		return FALSE;
+	}
+
 	ret = FALSE;
 
 	caps = libhal_device_get_property_strlist (ctx, udi, "info.capabilities", error);
@@ -2663,6 +2868,13 @@
 	char **hal_device_names;
 	DBusError _error;
 
+	if (ctx == NULL) {
+		fprintf (stderr, 
+			 "%s %d : LibHalContext *ctx is NULL\n", 
+			 __FILE__, __LINE__);
+		return NULL;
+	}
+
 	message = dbus_message_new_method_call ("org.freedesktop.Hal",
 						"/org/freedesktop/Hal/Manager",
 						"org.freedesktop.Hal.Manager",
@@ -2720,6 +2932,13 @@
 dbus_bool_t
 libhal_device_property_watch_all (LibHalContext *ctx, DBusError *error)
 {
+	if (ctx == NULL) {
+		fprintf (stderr, 
+			 "%s %d : LibHalContext *ctx is NULL\n", 
+			 __FILE__, __LINE__);
+		return FALSE;
+	}
+
 	dbus_bus_add_match (ctx->connection,
 			    "type='signal',"
 			    "interface='org.freedesktop.Hal.Device',"
@@ -2748,6 +2967,13 @@
 {
 	char buf[512];
 
+	if (ctx == NULL) {
+		fprintf (stderr, 
+			 "%s %d : LibHalContext *ctx is NULL\n", 
+			 __FILE__, __LINE__);
+		return FALSE;
+	}
+
 	snprintf (buf, 512,
 		  "type='signal',"
 		  "interface='org.freedesktop.Hal.Device',"
@@ -2774,6 +3000,13 @@
 {
 	char buf[512];
 
+	if (ctx == NULL) {
+		fprintf (stderr, 
+			 "%s %d : LibHalContext *ctx is NULL\n", 
+			 __FILE__, __LINE__);
+		return FALSE;
+	}
+
 	snprintf (buf, 512,
 		  "type='signal',"
 		  "interface='org.freedesktop.Hal.Device',"
@@ -2805,7 +3038,9 @@
 
 	ctx = calloc (1, sizeof (LibHalContext));
 	if (ctx == NULL) {
-		fprintf (stderr, "%s %d : Failed to allocate %d bytes\n", __FILE__, __LINE__, sizeof (LibHalContext));
+		fprintf (stderr, 
+			 "%s %d : Failed to allocate %d bytes\n",
+			 __FILE__, __LINE__, sizeof (LibHalContext));
 		return NULL;
 	}
 
@@ -2829,8 +3064,12 @@
 dbus_bool_t
 libhal_ctx_set_cache (LibHalContext *ctx, dbus_bool_t use_cache)
 {
-	if (ctx == NULL)
+	if (ctx == NULL) {
+		fprintf (stderr, 
+			 "%s %d : LibHalContext *ctx is NULL\n", 
+			 __FILE__, __LINE__);
 		return FALSE;
+	}
 
 	ctx->cache_enabled = use_cache;
 	return TRUE;
@@ -2846,8 +3085,12 @@
 dbus_bool_t
 libhal_ctx_set_dbus_connection (LibHalContext *ctx, DBusConnection *conn)
 {
-	if (ctx == NULL)
+	if (ctx == NULL) {
+		fprintf (stderr, 
+			 "%s %d : LibHalContext *ctx is NULL\n", 
+			 __FILE__, __LINE__);
 		return FALSE;
+	}
 
 	if (conn == NULL)
 		return FALSE;
@@ -2870,8 +3113,12 @@
 	DBusError _error;
 	dbus_bool_t hald_exists;
 
-	if (ctx == NULL)
+	if (ctx == NULL) {
+		fprintf (stderr, 
+			 "%s %d : LibHalContext *ctx is NULL\n", 
+			 __FILE__, __LINE__);
 		return FALSE;
+	}
 
 	if (ctx->connection == NULL)
 		return FALSE;
@@ -2959,6 +3206,13 @@
 {
 	DBusError myerror;
 
+	if (ctx == NULL) {
+		fprintf (stderr, 
+			 "%s %d : LibHalContext *ctx is NULL\n", 
+			 __FILE__, __LINE__);
+		return FALSE;
+	}
+
 	if (ctx->is_direct) {
 		/* for some reason dbus_connection_set_exit_on_disconnect doesn't work yet so don't unref */
 		/*dbus_connection_unref (ctx->connection);*/
@@ -3007,8 +3261,13 @@
 dbus_bool_t
 libhal_ctx_set_device_added (LibHalContext *ctx, LibHalDeviceAdded callback)
 {
-	if (ctx == NULL)
+	if (ctx == NULL) {
+		fprintf (stderr, 
+			 "%s %d : LibHalContext *ctx is NULL\n", 
+			 __FILE__, __LINE__);
 		return FALSE;
+	}
+	
 	ctx->device_added = callback;
 	return TRUE;
 }
@@ -3023,8 +3282,13 @@
 dbus_bool_t
 libhal_ctx_set_device_removed (LibHalContext *ctx, LibHalDeviceRemoved callback)
 {
-	if (ctx == NULL)
+	if (ctx == NULL) {
+		fprintf (stderr, 
+			 "%s %d : LibHalContext *ctx is NULL\n", 
+			 __FILE__, __LINE__);
 		return FALSE;
+	}
+	
 	ctx->device_removed = callback;
 	return TRUE;
 }
@@ -3040,8 +3304,13 @@
 dbus_bool_t
 libhal_ctx_set_device_new_capability (LibHalContext *ctx, LibHalDeviceNewCapability callback)
 {
-	if (ctx == NULL)
+	if (ctx == NULL) {
+		fprintf (stderr, 
+			 "%s %d : LibHalContext *ctx is NULL\n", 
+			 __FILE__, __LINE__);
 		return FALSE;
+	}
+	
 	ctx->device_new_capability = callback;
 	return TRUE;
 }
@@ -3057,8 +3326,13 @@
 dbus_bool_t
 libhal_ctx_set_device_lost_capability (LibHalContext *ctx, LibHalDeviceLostCapability callback)
 {
-	if (ctx == NULL)
+	if (ctx == NULL) {
+		fprintf (stderr, 
+			 "%s %d : LibHalContext *ctx is NULL\n", 
+			 __FILE__, __LINE__);
 		return FALSE;
+	}
+	
 	ctx->device_lost_capability = callback;
 	return TRUE;
 }
@@ -3074,8 +3348,13 @@
 dbus_bool_t
 libhal_ctx_set_device_property_modified (LibHalContext *ctx, LibHalDevicePropertyModified callback)
 {
-	if (ctx == NULL)
+	if (ctx == NULL) {
+		fprintf (stderr, 
+			 "%s %d : LibHalContext *ctx is NULL\n", 
+			 __FILE__, __LINE__);
 		return FALSE;
+	}
+	
 	ctx->device_property_modified = callback;
 	return TRUE;
 }
@@ -3090,8 +3369,13 @@
 dbus_bool_t
 libhal_ctx_set_device_condition (LibHalContext *ctx, LibHalDeviceCondition callback)
 {
-	if (ctx == NULL)
+	if (ctx == NULL) {
+		fprintf (stderr, 
+			 "%s %d : LibHalContext *ctx is NULL\n", 
+			 __FILE__, __LINE__);
 		return FALSE;
+	}
+	
 	ctx->device_condition = callback;
 	return TRUE;
 }
@@ -3123,6 +3407,13 @@
 	DBusMessage *reply;
 	dbus_bool_t result;
 
+	if (ctx == NULL) {
+		fprintf (stderr, 
+			 "%s %d : LibHalContext *ctx is NULL\n", 
+			 __FILE__, __LINE__);
+		return FALSE;
+	}
+
 	message = dbus_message_new_method_call ("org.freedesktop.Hal", udi,
 						"org.freedesktop.Hal.Device",
 						"Rescan");
@@ -3170,6 +3461,13 @@
 	DBusMessage *reply;
 	dbus_bool_t result;
 
+	if (ctx == NULL) {
+		fprintf (stderr, 
+			 "%s %d : LibHalContext *ctx is NULL\n", 
+			 __FILE__, __LINE__);
+		return FALSE;
+	}
+
 	message = dbus_message_new_method_call ("org.freedesktop.Hal",
 						udi,
 						"org.freedesktop.Hal.Device",
@@ -3233,6 +3531,13 @@
 	DBusMessage *reply;
 	dbus_bool_t result;
 
+	if (ctx == NULL) {
+		fprintf (stderr, 
+			 "%s %d : LibHalContext *ctx is NULL\n", 
+			 __FILE__, __LINE__);
+		return FALSE;
+	}
+
 	message = dbus_message_new_method_call ("org.freedesktop.Hal",
 						udi,
 						"org.freedesktop.Hal.Device",




More information about the hal-commit mailing list