diff mbox series

[22/30] libmultipath: fix parsing of non-space-terminated T10 ID

Message ID 20190607130552.13203-23-mwilck@suse.com (mailing list archive)
State Not Applicable, archived
Delegated to: christophe varoqui
Headers show
Series multipath-tools: gcc9, VPD parsing, and get_uid fixes | expand

Commit Message

Martin Wilck June 7, 2019, 1:05 p.m. UTC
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 | 11 +++++++++++
 1 file changed, 11 insertions(+)
diff mbox series

Patch

diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c
index 3558e559..efcea468 100644
--- a/libmultipath/discovery.c
+++ b/libmultipath/discovery.c
@@ -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--;