summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2012-06-29 18:20:42 +0100
committerRichard W.M. Jones <rjones@redhat.com>2012-07-07 11:23:15 +0100
commitbbbd267dd111832af7ebba1e7f566702e5fe37d2 (patch)
treef698c80a156ba14fbf2dfbc765f5308351b09297 /src
parent03c6297e1b41abb14ac018bff851f259a2634ae4 (diff)
downloadlibguestfs-bbbd267dd111832af7ebba1e7f566702e5fe37d2.tar.gz
libguestfs-bbbd267dd111832af7ebba1e7f566702e5fe37d2.tar.xz
libguestfs-bbbd267dd111832af7ebba1e7f566702e5fe37d2.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)
Diffstat (limited to 'src')
-rw-r--r--src/inspect_fs_unix.c34
1 files changed, 26 insertions, 8 deletions
diff --git a/src/inspect_fs_unix.c b/src/inspect_fs_unix.c
index 5896cc68..435ead4b 100644
--- a/src/inspect_fs_unix.c
+++ b/src/inspect_fs_unix.c
@@ -1173,7 +1173,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;
@@ -1194,7 +1194,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;
}
@@ -1218,12 +1223,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;
}
@@ -1231,6 +1242,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;
@@ -1248,8 +1260,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;
@@ -1260,8 +1278,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;
}