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

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