[Libguestfs] [PATCH] inspection: Fix parsing of btrfs subvolumes in /etc/fstab.

Richard W.M. Jones rjones at redhat.com
Thu Aug 25 10:12:32 UTC 2016


The code to parse btrfs subvol entries in /etc/fstab failed if the
entry had more than one comma-separated option, for example:

/dev/sda4 /home btrfs rw,user,subvol=foo 0 0

This commit fixes that code to use Augeas correctly.

Fixes commit 7ba0e10501f23358c38939930d613bf2393d744d.

Reported by: Zhongfu Li
https://bugs.launchpad.net/ubuntu/+source/libguestfs/+bug/1615337
---
 src/inspect-fs-unix.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/src/inspect-fs-unix.c b/src/inspect-fs-unix.c
index cc0e6b1..0c34701 100644
--- a/src/inspect-fs-unix.c
+++ b/src/inspect-fs-unix.c
@@ -1347,27 +1347,28 @@ check_fstab (guestfs_h *g, struct inspect_fs *fs)
     if (vfstype == NULL) return -1;
 
     if (STREQ (vfstype, "btrfs")) {
-      char **opt;
+      size_t i;
 
       snprintf (augpath, sizeof augpath, "%s/opt", *entry);
       CLEANUP_FREE_STRING_LIST char **opts = guestfs_aug_match (g, augpath);
       if (opts == NULL) return -1;
 
-      for (opt = opts; *opt; opt++) {
-        CLEANUP_FREE char *optname = guestfs_aug_get (g, augpath);
+      for (i = 0; opts[i] != NULL; ++i) {
+        CLEANUP_FREE char *optname = NULL, *optvalue = NULL, *subvol = NULL;
+        char *old_mountable;
+
+        optname = guestfs_aug_get (g, opts[i]);
         if (optname == NULL) return -1;
 
         if (STREQ (optname, "subvol")) {
-          CLEANUP_FREE char *subvol = NULL;
-          char *new;
+          optvalue = safe_asprintf (g, "%s/value", opts[i]);
 
-          snprintf (augpath, sizeof augpath, "%s/value", *opt);
-          subvol = guestfs_aug_get (g, augpath);
+          subvol = guestfs_aug_get (g, optvalue);
           if (subvol == NULL) return -1;
 
-          new = safe_asprintf (g, "btrfsvol:%s/%s", mountable, subvol);
-          free (mountable);
-          mountable = new;
+          old_mountable = mountable;
+          mountable = safe_asprintf (g, "btrfsvol:%s/%s", mountable, subvol);
+          free (old_mountable);
         }
       }
     }
-- 
2.7.4




More information about the Libguestfs mailing list