[dm-devel] [PATCH 4/4] libmultipath: fix compilation error with gcc 10 on i386

mwilck at suse.com mwilck at suse.com
Thu Feb 11 23:46:50 UTC 2021


From: Martin Wilck <mwilck at suse.com>

gcc complained about a possible negative value of "nr" in the
memcpy() call. I consider that a false positive, but it's easily
fixed.

Signed-off-by: Martin Wilck <mwilck at suse.com>
---
 libmultipath/sysfs.c | 29 ++++++++++++++---------------
 1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/libmultipath/sysfs.c b/libmultipath/sysfs.c
index 5390de6..7a2af1e 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);
 	}
-- 
2.29.2





More information about the dm-devel mailing list