Fix hang on setting invalid VFAT labels
authorMartin Pitt <martin.pitt@ubuntu.com>
Sat, 6 Nov 2010 17:40:07 +0000 (13:40 -0400)
committerMartin Pitt <martin.pitt@ubuntu.com>
Sat, 6 Nov 2010 17:40:07 +0000 (13:40 -0400)
VFAT does not support several characters in file names and labels, in
particular: " * / : < > ? \ |
(http://en.wikipedia.org/wiki/File_Allocation_Table)

When using one of those, mlabel interactively asks what to do, and thus causes
a hang. Now check for invalid characters and return a proper error instead.

Also update the test case to verify that we get an Error on invalid labels, and
that valid labels still work.

src/helpers/job-change-filesystem-label.c
tests/run

index 5017b58..fcdee76 100644 (file)
@@ -51,6 +51,7 @@ main (int argc,
   char *command_line;
   char *standard_error;
   char *new_label;
+  char *c;
 
   ret = 1;
   command_line = NULL;
@@ -92,6 +93,16 @@ main (int argc,
     {
       if (!validate_and_escape_label (&new_label, 254))
         goto out;
+      /* VFAT does not allow some characters */
+      for (c = "\"*/:<>?\\|"; *c; ++c)
+       {
+         if (strchr (new_label, *c) != NULL)
+           {
+             g_printerr ("character '%c' not supported in VFAT labels\n", *c);
+             goto out;
+           }
+          }
+
       g_setenv ("MTOOLS_SKIP_CHECK", "1", TRUE);
       if (strlen (new_label) == 0)
         command_line = g_strdup_printf ("mlabel -c -i %s ::", device);
index e455422..a25d8d9 100755 (executable)
--- a/tests/run
+++ b/tests/run
@@ -736,6 +736,10 @@ class FS(UDisksTestCase):
         # change label
         if supports_label_rename:
             l = 'n"a\m\\"e' + type
+            if type == 'vfat':
+                # VFAT does not support some characters
+                self.assertRaises(dbus.DBusException, iface.FilesystemSetLabel, l)
+                l = "n@a$me"
             iface.FilesystemSetLabel(l)
             self.sync_workaround()
             i = self.get_info()