Blame SOURCES/0021-efiboot-Make-the-device-node-skipping-code-pass-cove.patch

80b73c
From bc11451222cc77d8c1b4e752167adabd3c7f64c9 Mon Sep 17 00:00:00 2001
80b73c
From: Peter Jones <pjones@redhat.com>
80b73c
Date: Thu, 21 Jun 2018 13:33:26 -0400
80b73c
Subject: [PATCH 21/24] efiboot: Make the device node skipping code pass
80b73c
 coverity.
80b73c
80b73c
Signed-off-by: Peter Jones <pjones@redhat.com>
80b73c
---
80b73c
 src/linux.c | 31 ++++++++++++++++++-------------
80b73c
 1 file changed, 18 insertions(+), 13 deletions(-)
80b73c
80b73c
diff --git a/src/linux.c b/src/linux.c
80b73c
index f919dee5b67..6d20c2dbe25 100644
80b73c
--- a/src/linux.c
80b73c
+++ b/src/linux.c
80b73c
@@ -308,7 +308,8 @@ struct device HIDDEN
80b73c
 {
80b73c
         struct device *dev;
80b73c
         char *linkbuf = NULL, *tmpbuf = NULL;
80b73c
-        unsigned int i, n = 0;
80b73c
+        int i = 0;
80b73c
+        unsigned int n = 0;
80b73c
         int rc;
80b73c
 
80b73c
         size_t nmemb = (sizeof(dev_probes)
80b73c
@@ -432,9 +433,11 @@ struct device HIDDEN
80b73c
         int last_successful_probe = -1;
80b73c
 
80b73c
         debug("searching for device nodes in %s", dev->link);
80b73c
-        for (i = 0; dev_probes[i] && dev_probes[i]->parse; i++) {
80b73c
+        for (i = 0;
80b73c
+             dev_probes[i] && dev_probes[i]->parse && *current;
80b73c
+             i++) {
80b73c
                 struct dev_probe *probe = dev_probes[i];
80b73c
-                ssize_t pos;
80b73c
+                int pos;
80b73c
 
80b73c
                 if (!needs_root &&
80b73c
                     (probe->flags & DEV_PROVIDES_ROOT)) {
80b73c
@@ -471,24 +474,26 @@ struct device HIDDEN
80b73c
                 debug("dev_probes[i+1]: %p dev->interface_type: %d\n",
80b73c
                       dev_probes[i+1], dev->interface_type);
80b73c
                 if (dev_probes[i+1] == NULL && dev->interface_type == unknown) {
80b73c
-                        int new_pos = 0;
80b73c
-                        rc = sscanf(current, "%*[^/]/%n", &new_pos);
80b73c
+                        pos = 0;
80b73c
+                        rc = sscanf(current, "%*[^/]/%n", &pos;;
80b73c
                         if (rc < 0) {
80b73c
-                                efi_error(
80b73c
-                                     "Cannot parse device link segment \"%s\"",
80b73c
-                                     current);
80b73c
+slash_err:
80b73c
+                                efi_error("Cannot parse device link segment \"%s\"", current);
80b73c
                                 goto err;
80b73c
                         }
80b73c
+
80b73c
+                        while (current[pos] == '/')
80b73c
+                                pos += 1;
80b73c
+
80b73c
+                        if (!current[pos])
80b73c
+                                goto slash_err;
80b73c
+
80b73c
                         debug("Cannot parse device link segment \"%s\"", current);
80b73c
                         debug("Skipping to \"%s\"", current + pos);
80b73c
                         debug("This means we can only create abbreviated paths");
80b73c
-                        if (rc < 0)
80b73c
-                                goto err;
80b73c
-                        if (new_pos == 0)
80b73c
-                                goto err;
80b73c
                         dev->flags |= DEV_ABBREV_ONLY;
80b73c
                         i = last_successful_probe;
80b73c
-                        current += new_pos;
80b73c
+                        current += pos;
80b73c
                 }
80b73c
         }
80b73c
 
80b73c
-- 
80b73c
2.17.1
80b73c