diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2012-06-29 18:20:42 +0100 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2012-07-06 17:36:29 +0100 |
commit | 2212f79ca08853c7247ebcf165f224246e92b294 (patch) | |
tree | d59b3d06d8e01fe1c363a89085bac79de80ce66f | |
parent | 9e38de7449cd746cca326b0f60091e0eb99bb89d (diff) | |
download | libguestfs-2212f79ca08853c7247ebcf165f224246e92b294.tar.gz libguestfs-2212f79ca08853c7247ebcf165f224246e92b294.tar.xz libguestfs-2212f79ca08853c7247ebcf165f224246e92b294.zip |
inspect: Check partition exists when doing fstab mapping.
If the partition name we're about to return doesn't really exist,
then don't perform the mapping.
(cherry picked from commit ea8421c5d297698856a87c2cfe4a6b42796175a8)
-rw-r--r-- | src/inspect_fs_unix.c | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/src/inspect_fs_unix.c b/src/inspect_fs_unix.c index 94e912c0..6d574292 100644 --- a/src/inspect_fs_unix.c +++ b/src/inspect_fs_unix.c @@ -1193,7 +1193,7 @@ static int resolve_fstab_device_xdev (guestfs_h *g, const char *type, const char *disk, const char *part, char **device_ret) { - char *name; + char *name, *device; char **devices; size_t i, count; struct drive *drive; @@ -1214,7 +1214,12 @@ resolve_fstab_device_xdev (guestfs_h *g, const char *type, const char *disk, drive = g->drives; while (drive) { if (drive->name && STREQ (drive->name, name)) { - *device_ret = safe_asprintf (g, "%s%s", devices[i], part); + device = safe_asprintf (g, "%s%s", devices[i], part); + if (!is_partition (g, device)) { + free (device); + goto out; + } + *device_ret = device; break; } @@ -1238,12 +1243,18 @@ resolve_fstab_device_xdev (guestfs_h *g, const char *type, const char *disk, /* Check the index makes sense wrt the number of disks the appliance has. * If it does, map it to an appliance disk. */ - if (i < count) - *device_ret = safe_asprintf (g, "%s%s", devices[i], part); + if (i < count) { + device = safe_asprintf (g, "%s%s", devices[i], part); + if (!is_partition (g, device)) { + free (device); + goto out; + } + *device_ret = device; + } } + out: guestfs___free_string_list (devices); - return 0; } @@ -1251,6 +1262,7 @@ static int resolve_fstab_device_cciss (guestfs_h *g, const char *disk, const char *part, char **device_ret) { + char *device; char **devices; size_t i; struct drive *drive; @@ -1268,8 +1280,14 @@ resolve_fstab_device_cciss (guestfs_h *g, const char *disk, const char *part, drive = g->drives; while (drive) { if (drive->name && STREQ(drive->name, disk)) { - if (part) - *device_ret = safe_asprintf (g, "%s%s", devices[i], part); + if (part) { + device = safe_asprintf (g, "%s%s", devices[i], part); + if (!is_partition (g, device)) { + free (device); + goto out; + } + *device_ret = device; + } else *device_ret = safe_strdup (g, devices[i]); break; @@ -1280,8 +1298,8 @@ resolve_fstab_device_cciss (guestfs_h *g, const char *disk, const char *part, /* We don't try to guess mappings for cciss devices */ + out: guestfs___free_string_list (devices); - return 0; } |