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.
This commit is contained in:
Richard W.M. Jones
2017-08-03 18:06:54 +01:00
parent 58ecca0432
commit 63071bb8f9
2 changed files with 13 additions and 2 deletions

View File

@@ -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;

View File

@@ -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"), [];