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

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