hal/hald/linux2/probing probe-volume.c,1.28,1.29

David Zeuthen david at kemper.freedesktop.org
Fri May 12 08:17:07 PDT 2006


Update of /cvs/hal/hal/hald/linux2/probing
In directory kemper:/tmp/cvs-serv16407/hald/linux2/probing

Modified Files:
	probe-volume.c 
Log Message:
2006-05-12  David Zeuthen  <davidz at redhat.com>

        * hald/linux2/probing/probe-volume.c (strdup_valid_utf8): In
        Ubuntu we got several bug reports about device label gibberish,
        for example: https://launchpad.net/bugs/27897. This happens if the
        label is either truly bogus, or in a non-UTF-8 compatible
        encoding. The blunt solution would be to just ignore any non-UTF-8
        labels, but since it might be preferable to retain labels which
        are only 'lightly' damaged (maybe one Umlaut in an otherwise valid
        string), I wrote a small patch to ignore invalid labels if they
        contain more than 20% illegal characters. Patch from Martin Pitt
        <martin at piware.de>.



Index: probe-volume.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux2/probing/probe-volume.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- probe-volume.c	10 May 2006 12:28:32 -0000	1.28
+++ probe-volume.c	12 May 2006 15:17:05 -0000	1.29
@@ -66,14 +66,25 @@
 {
 	char *endchar;
 	char *newstr;
+	char *s;
+	unsigned int fixes;
 
 	if (str == NULL)
 		return NULL;
 
 	newstr = g_strdup (str);
 
-	while (!g_utf8_validate (newstr, -1, (const char **) &endchar)) {
+	fixes = 0;
+	s = newstr;
+	while (!g_utf8_validate (s, -1, (const char **) &endchar)) {
 		*endchar = '_';
+		++fixes;
+	}
+
+	/* If we had to fix more than 20% of the characters, give up */
+	if (fixes > 0 && g_utf8_strlen (newstr, -1) / fixes < 5) {
+	    g_free (newstr);
+	    newstr = g_strdup("");
 	}
 
 	return newstr;




More information about the hal-commit mailing list