Whamcloud - gitweb
Fix bug which could cause libblkid to loop forever
authorTheodore Ts'o <tytso@mit.edu>
Sat, 7 Jul 2007 22:32:26 +0000 (18:32 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Sun, 8 Jul 2007 12:50:41 +0000 (08:50 -0400)
When revalidating a partition where there is obsolete information in
/etc/blkid.tab, we end up freeing a the type tag without clearing
dev->bid_type, causing blkid_verify() to loop forever.

Addresses-Debian-Bug: #432052

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
lib/blkid/tag.c

index 57277cd..44dd86d 100644 (file)
@@ -132,6 +132,7 @@ int blkid_set_tag(blkid_dev dev, const char *name,
 {
        blkid_tag       t = 0, head = 0;
        char            *val = 0;
+       char            **dev_var = 0;
 
        if (!dev || !name)
                return -BLKID_ERR_PARAM;
@@ -139,6 +140,18 @@ int blkid_set_tag(blkid_dev dev, const char *name,
        if (!(val = blkid_strndup(value, vlength)) && value)
                return -BLKID_ERR_MEM;
 
+       /* 
+        * Certain common tags are linked directly to the device struct
+        * We need to know what they are before we do anything else because
+        * the function name parameter might get freed later on.
+        */
+       if (!strcmp(name, "TYPE"))
+               dev_var = &dev->bid_type;
+       else if (!strcmp(name, "LABEL"))
+               dev_var = &dev->bid_label;
+       else if (!strcmp(name, "UUID"))
+               dev_var = &dev->bid_uuid;
+
        t = blkid_find_tag_dev(dev, name);
        if (!value) {
                if (t)
@@ -182,12 +195,8 @@ int blkid_set_tag(blkid_dev dev, const char *name,
        }
        
        /* Link common tags directly to the device struct */
-       if (!strcmp(name, "TYPE"))
-               dev->bid_type = val;
-       else if (!strcmp(name, "LABEL"))
-               dev->bid_label = val;
-       else if (!strcmp(name, "UUID"))
-               dev->bid_uuid = val;
+       if (dev_var)
+               *dev_var = val;
                
        if (dev->bid_cache)
                dev->bid_cache->bic_flags |= BLKID_BIC_FL_CHANGED;