Blame SOURCES/0002-libfwup-set_up_boot_next-make-sure-we-check-if-our-f.patch

5dbb77
From a0c57f8759a0548aa7f0334f6839156b1456bb2a Mon Sep 17 00:00:00 2001
5dbb77
From: Peter Jones <pjones@redhat.com>
5dbb77
Date: Wed, 13 Jun 2018 09:57:49 -0400
5dbb77
Subject: [PATCH 2/2] libfwup: set_up_boot_next(): make sure we check if our
5dbb77
 file paths are NULL.
5dbb77
5dbb77
Coverity's clang scan believes we can sometimes alloca(0) if
5dbb77
fwup_esp_path is NULL, though I don't think this can happen because if
5dbb77
it is NULL get_paths() should have returned error.  Nevertheless, just
5dbb77
check both things.
5dbb77
5dbb77
Additionally, this adds a check to make sure utf8_to_ucs2() and
5dbb77
ucs2len() didn't fail.
5dbb77
5dbb77
Signed-off-by: Peter Jones <pjones@redhat.com>
5dbb77
---
5dbb77
 linux/libfwup.c | 19 +++++++++++++++----
5dbb77
 1 file changed, 15 insertions(+), 4 deletions(-)
5dbb77
5dbb77
diff --git a/linux/libfwup.c b/linux/libfwup.c
5dbb77
index abab18e96ac..61a9d280c32 100644
5dbb77
--- a/linux/libfwup.c
5dbb77
+++ b/linux/libfwup.c
5dbb77
@@ -1215,9 +1215,9 @@ set_up_boot_next(void)
5dbb77
 	uint32_t attributes = LOAD_OPTION_ACTIVE;
5dbb77
 
5dbb77
 	rc = get_paths(&shim_fs_path, &fwup_fs_path, &fwup_esp_path);
5dbb77
-	if (rc < 0) {
5dbb77
+	if (rc < 0 || (!shim_fs_path && (!fwup_fs_path || !fwup_esp_path))) {
5dbb77
 		efi_error("could not find paths for shim and fwup");
5dbb77
-		return -1;
5dbb77
+                goto out;
5dbb77
 	}
5dbb77
 
5dbb77
 	if (!shim_fs_path)
5dbb77
@@ -1242,9 +1242,20 @@ set_up_boot_next(void)
5dbb77
 
5dbb77
 	if (!use_fwup_path) {
5dbb77
 		loader_str = utf8_to_ucs2((uint8_t *)fwup_esp_path, -1);
5dbb77
+		if (loader_str == NULL) {
5dbb77
+			efi_error("utf8_to_ucs2() failed");
5dbb77
+			goto out;
5dbb77
+		}
5dbb77
 		loader_sz = ucs2len(loader_str, -1) * 2;
5dbb77
-		if (loader_sz)
5dbb77
-			loader_sz += 2;
5dbb77
+		if (loader_sz < 2) {
5dbb77
+			efi_error("ucs2len(fwup_esp_path) returned %zu",
5dbb77
+				  loader_sz);
5dbb77
+			saved_errno = errno;
5dbb77
+			free(loader_str);
5dbb77
+			errno = saved_errno;
5dbb77
+			goto out;
5dbb77
+		}
5dbb77
+		loader_sz += 2;
5dbb77
 		loader_str = onstack(loader_str, loader_sz);
5dbb77
 	}
5dbb77
 
5dbb77
-- 
5dbb77
2.17.1
5dbb77