According to the SPC spec, the unit serial number is right-aligned ASCII. Thus leading whitespace must be skipped. Moreover, trailing whitespace should be discarded before doing the length check. Fixes: 756ef73b7197 "Separate out vpd parsing functions" Signed-off-by: Martin Wilck <mwilck@xxxxxxxx> --- libmultipath/discovery.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c index 931a676f..b10afdef 100644 --- a/libmultipath/discovery.c +++ b/libmultipath/discovery.c @@ -907,9 +907,18 @@ get_geometry(struct path *pp) static int parse_vpd_pg80(const unsigned char *in, char *out, size_t out_len) { - char *p = NULL; int len = get_unaligned_be16(&in[2]); + /* + * Strip leading and trailing whitespace + */ + while (len > 0 && in[len + 3] == ' ') + --len; + while (len > 0 && in[4] == ' ') { + ++in; + --len; + } + if (len >= out_len) { condlog(2, "vpd pg80 overflow, %d/%d bytes required", len + 1, (int)out_len); @@ -919,15 +928,6 @@ parse_vpd_pg80(const unsigned char *in, char *out, size_t out_len) memcpy(out, in + 4, len); out[len] = '\0'; } - /* - * Strip trailing whitspaces - */ - p = out + len - 1; - while (p > out && *p == ' ') { - *p = '\0'; - p--; - len --; - } return len; } -- 2.21.0 -- dm-devel mailing list dm-devel@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/dm-devel