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

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