From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Fri, 12 Feb 2021 00:41:55 +0100 Subject: [PATCH] libmultipath: fix compilation error with gcc 10 on i386 gcc complained about a possible negative value of "nr" in the memcpy() call. I consider that a false positive, but it's easily fixed. Reviewed-by: Benjamin Marzinski Signed-off-by: Benjamin Marzinski --- libmultipath/sysfs.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/libmultipath/sysfs.c b/libmultipath/sysfs.c index 5390de62..7a2af1ea 100644 --- a/libmultipath/sysfs.c +++ b/libmultipath/sysfs.c @@ -344,24 +344,23 @@ bool sysfs_is_multipathed(struct path *pp, bool set_wwid) pthread_cleanup_push(close_fd, (void *)fd); nr = read(fd, uuid, sizeof(uuid)); if (nr > (int)UUID_PREFIX_LEN && - !memcmp(uuid, UUID_PREFIX, UUID_PREFIX_LEN)) + !memcmp(uuid, UUID_PREFIX, UUID_PREFIX_LEN)) { found = true; - else if (nr < 0) { + if (set_wwid) { + nr -= UUID_PREFIX_LEN; + memcpy(pp->wwid, uuid + UUID_PREFIX_LEN, nr); + if (nr == WWID_SIZE) { + condlog(4, "%s: overflow while reading from %s", + __func__, pathbuf); + pp->wwid[0] = '\0'; + } else { + pp->wwid[nr] = '\0'; + strchop(pp->wwid); + } + } + } else if (nr < 0) condlog(1, "%s: error reading from %s: %m", __func__, pathbuf); - } - if (found && set_wwid) { - nr -= UUID_PREFIX_LEN; - memcpy(pp->wwid, uuid + UUID_PREFIX_LEN, nr); - if (nr == WWID_SIZE) { - condlog(4, "%s: overflow while reading from %s", - __func__, pathbuf); - pp->wwid[0] = '\0'; - } else { - pp->wwid[nr] = '\0'; - strchop(pp->wwid); - } - } pthread_cleanup_pop(1); }