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

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