]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
imsm: Block volume creation with empty name
authorRoman Sobanski <roman.sobanski@intel.com>
Fri, 10 Aug 2018 12:20:35 +0000 (14:20 +0200)
committerJes Sorensen <jsorensen@fb.com>
Thu, 27 Sep 2018 14:27:25 +0000 (10:27 -0400)
There is a possibility to create a RAID with empty name. Block it. Also
remove trailing and leading whitespaces from given name.

Signed-off-by: Roman Sobanski <roman.sobanski@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
super-intel.c

index f011a31f51072a740c4dc442b6275aad022d6f0b..d3d256a4f36b0ba6199be7e70454ed1ce2574e10 100644 (file)
@@ -5285,10 +5285,22 @@ static int check_name(struct intel_super *super, char *name, int quiet)
 {
        struct imsm_super *mpb = super->anchor;
        char *reason = NULL;
+       char *start = name;
+       size_t len = strlen(name);
        int i;
 
-       if (strlen(name) > MAX_RAID_SERIAL_LEN)
+       if (len > 0) {
+               while (isspace(start[len - 1]))
+                       start[--len] = 0;
+               while (*start && isspace(*start))
+                       ++start, --len;
+               memmove(name, start, len + 1);
+       }
+
+       if (len > MAX_RAID_SERIAL_LEN)
                reason = "must be 16 characters or less";
+       else if (len == 0)
+               reason = "must be a non-empty string";
 
        for (i = 0; i < mpb->num_raid_devs; i++) {
                struct imsm_dev *dev = get_imsm_dev(super, i);