libmultipath: fix parsing of non-space-terminated T10 ID
authorMartin Wilck <mwilck@suse.com>
Mon, 24 Jun 2019 09:27:48 +0000 (11:27 +0200)
committerChristophe Varoqui <christophe.varoqui@opensvc.com>
Wed, 3 Jul 2019 06:31:38 +0000 (08:31 +0200)
If the T10 vendor specific ID doesn't end with spaces, the last
part won't be parsed. Fix it.

Fixes: 18176202e75c "Read wwid from sysfs vpg_pg83 attribute"
Signed-off-by: Martin Wilck <mwilck@suse.com>
libmultipath/discovery.c

index 3558e55..efcea46 100644 (file)
@@ -1083,6 +1083,17 @@ parse_vpd_pg83(const unsigned char *in, size_t in_len,
                                        vpd_len --;
                                }
                        }
+                       p_len = vpd_len;
+                       if (p_len > 0 && len < out_len - 1) {
+                               if (len + p_len > out_len - 1) {
+                                       condlog(1, "%s: WWID overflow, type 1, %d/%lu bytes required",
+                                               __func__, len + p_len + 1, out_len);
+                                       p_len = out_len - len - 1;
+                               }
+                               memcpy(out + len, vpd, p_len);
+                               len += p_len;
+                               out[len] = '\0';
+                       }
                        if (len > 1 && out[len - 1] == '_') {
                                out[len - 1] = '\0';
                                len--;