[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH 5/6] daemon: lvm: Pass device parameter of lvm_canonical_lv_name as PlainString.



All sorts of strings might be passed here hoping to make them
canonical LV names.  We cannot be sure that the strings passed will be
devices which exist in the appliance.
---
 daemon/lvm.c              | 13 ++++++++++++-
 generator/actions_core.ml |  2 +-
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/daemon/lvm.c b/daemon/lvm.c
index 4026c4f92..9d91b6459 100644
--- a/daemon/lvm.c
+++ b/daemon/lvm.c
@@ -723,7 +723,18 @@ char *
 do_lvm_canonical_lv_name (const char *device)
 {
   char *canonical;
-  int r = lv_canonical (device, &canonical);
+  int r;
+
+  /* The device parameter is passed as PlainString because we can't
+   * really be sure that the device name will exist (especially for
+   * "/dev/mapper/..." names).  Do some sanity checking on it here.
+   */
+  if (!STRPREFIX (device, "/dev/")) {
+    reply_with_error ("%s: not a device name", device);
+    return NULL;
+  }
+
+  r = lv_canonical (device, &canonical);
   if (r == -1)
     return NULL;
 
diff --git a/generator/actions_core.ml b/generator/actions_core.ml
index fba6c39ca..81cb99ea8 100644
--- a/generator/actions_core.ml
+++ b/generator/actions_core.ml
@@ -6002,7 +6002,7 @@ See also C<guestfs_pread>." };
 
   { defaults with
     name = "lvm_canonical_lv_name"; added = (1, 5, 24);
-    style = RString (RDevice, "lv"), [String (Device, "lvname")], [];
+    style = RString (RDevice, "lv"), [String (PlainString, "lvname")], [];
     tests = [
       InitBasicFSonLVM, IfAvailable "lvm2", TestResultString (
         [["lvm_canonical_lv_name"; "/dev/mapper/VG-LV"]], "/dev/VG/LV"), [];
-- 
2.13.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]