[patch] filter invalid utf-8 characters from volume labels

Sjoerd Simons sjoerd at luon.net
Wed Jul 28 00:12:26 PDT 2004


Hi,

  Having volume labels that aren't valid utf-8 causes some problems. Hal
  assumes there utf-8 and tries to send it as an utf-8 string over dbus, which
  will throw hal out of the bus[0].

  Attached path replaces the invalid utf-8 characters in a volume label with ?.
  I believe David is thinking about a better long-term solution, but he can 
  better comment on that himself.  And ofcourse there is the traditional
  screenshot[1] :)

  Sjoerd

0: http://vrfy.org/images/D-BUSs.jpg
1: http://luon.net/~sjoerd/hal/hal-non_utf8_label-20040728.png
-- 
Do not take life too seriously; you will never get out of it alive.
-------------- next part --------------
Index: hald/linux/block_class_device.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux/block_class_device.c,v
retrieving revision 1.45
diff -u -r1.45 block_class_device.c
--- hald/linux/block_class_device.c	27 Jul 2004 20:26:50 -0000	1.45
+++ hald/linux/block_class_device.c	28 Jul 2004 06:46:23 -0000
@@ -1063,6 +1063,7 @@
 {
 	struct volume_id *vid;
 	const char *device_file;
+	char *endchar;
 	int rc;
 
 	device_file = hal_device_property_get_string (d, "block.device");
@@ -1076,6 +1077,12 @@
 		return;
 	}
 
+  /* replace non-valid utf8 charaters in the volume.label field 
+   */
+	while (!g_utf8_validate(vid->label_string, -1, (const gchar **) &endchar)) {
+		*endchar = '?';
+	}
+
 	hal_device_property_set_string (d, "volume.fstype", vid->fs_name);
 	if (vid->label_string[0] != '\0')
 		hal_device_property_set_string (d, "volume.label", vid->label_string);
-------------- next part --------------
_______________________________________________
hal mailing list
hal at freedesktop.org
http://freedesktop.org/mailman/listinfo/hal


More information about the Hal mailing list