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

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