hal/hald/linux2/probing Makefile.am, 1.10, 1.11 probe-storage.c, 1.16, 1.17

Danny Kukawka dkukawka at freedesktop.org
Thu Nov 10 11:28:36 PST 2005


Update of /cvs/hal/hal/hald/linux2/probing
In directory gabe:/tmp/cvs-serv11546/hald/linux2/probing

Modified Files:
	Makefile.am probe-storage.c 
Log Message:
2005-11-10  Danny Kukawka  <danny.kukawka at web.de>

        * hald/linux2/probing/Makefile.am: updated for glib

        * hald/linux2/probing/probe-storage.c: (strdup_valid_utf8), (main):
        Fix to prevent sending invalid UTF8 strings from storage serials to D-BUS
        which prevent adding the whole storage divice to the device store. The
        invalid, non UTF8, characters replaced now with '?' and the serial only
        added if there is at least one valid character left in the string.

        * hald/util.c: (util_compute_time_remaining): fixed compiler warning



Index: Makefile.am
===================================================================
RCS file: /cvs/hal/hal/hald/linux2/probing/Makefile.am,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- Makefile.am	28 Sep 2005 16:33:59 -0000	1.10
+++ Makefile.am	10 Nov 2005 19:28:34 -0000	1.11
@@ -30,7 +30,7 @@
 hald_probe_serial_LDADD = $(top_builddir)/libhal/libhal.la
 
 hald_probe_storage_SOURCES = probe-storage.c linux_dvd_rw_utils.c linux_dvd_rw_utils.h shared.h
-hald_probe_storage_LDADD = $(top_builddir)/libhal/libhal.la $(top_builddir)/drive_id/libdrive_id.la $(top_builddir)/volume_id/libvolume_id.la
+hald_probe_storage_LDADD = $(top_builddir)/libhal/libhal.la $(top_builddir)/drive_id/libdrive_id.la $(top_builddir)/volume_id/libvolume_id.la @PACKAGE_LIBS@
 
 hald_probe_pc_floppy_SOURCES = probe-pc-floppy.c
 

Index: probe-storage.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux2/probing/probe-storage.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- probe-storage.c	2 Nov 2005 15:38:14 -0000	1.16
+++ probe-storage.c	10 Nov 2005 19:28:34 -0000	1.17
@@ -42,6 +42,8 @@
 #include <linux/fs.h>
 #include <mntent.h>
 
+#include <glib.h>
+
 #include "libhal/libhal.h"
 
 #include "drive_id/drive_id.h"
@@ -66,6 +68,29 @@
 	_do_dbg (format, args);
 }
 
+static char *
+strdup_valid_utf8 ( const char *String )
+{
+	char *endchar;
+	char *newString;
+	unsigned int count = 0;
+
+	if (String == NULL)
+		return NULL;
+
+	newString = g_strdup( String );
+
+	while (!g_utf8_validate (newString, -1, (const char **) &endchar)) {
+		*endchar = '?';
+		count++;
+	}
+
+	if (strlen(newString) == count)
+		return NULL;
+	else
+		return newString;
+}
+
 /** Check if a filesystem on a special device file is mounted
  *
  *  @param  device_file         Special device file, e.g. /dev/cdrom
@@ -152,7 +177,8 @@
 		if (strcmp (bus, "ide") == 0 ||
 		    strcmp (bus, "scsi") == 0) {
 			struct drive_id *did;
-			
+			char *serial;		
+	
 			dbg ("Doing open (\"%s\", O_RDONLY | O_NONBLOCK)", device_file);
 			fd = open (device_file, O_RDONLY | O_NONBLOCK);
 			if (fd < 0) {
@@ -164,10 +190,14 @@
 			did = drive_id_open_fd (fd);
 			if (drive_id_probe_all (did) == 0) {
 				dbg ("serial = '%s', firmware = '%s'", did->serial, did->firmware);
-				if (did->serial[0] != '\0') {
+				
+				/* validate this string to UTF8 to prevent problems with dbus if there is garbage */
+				serial = strdup_valid_utf8 ((const char *) did->serial);
+				
+				if (did->serial[0] != '\0' && serial != NULL) {
 					dbus_error_init (&error);
 					if (!libhal_device_set_property_string (ctx, udi, "storage.serial", 
-										(char *) did->serial, &error)) {
+										serial, &error)) {
 						dbg ("Error setting storage.serial");
 					}
 				}




More information about the hal-commit mailing list