Blame SOURCES/0008-Make-efidp_make_file-have-even-more-better-input-con.patch

80b73c
From 9bc1e24859630c933410bfb77658bd69ee400e16 Mon Sep 17 00:00:00 2001
80b73c
From: Peter Jones <pjones@redhat.com>
80b73c
Date: Wed, 13 Jun 2018 09:25:58 -0400
80b73c
Subject: [PATCH 08/17] Make efidp_make_file() have even more, better input
80b73c
 constraints.
80b73c
80b73c
This is all in the effort to convince coverity that it doesn't
80b73c
dereference buf when size==0, which it already doesn't.
80b73c
80b73c
Signed-off-by: Peter Jones <pjones@redhat.com>
80b73c
---
80b73c
 src/dp-media.c |  6 ++++++
80b73c
 src/dp.c       | 10 +++++++++-
80b73c
 2 files changed, 15 insertions(+), 1 deletion(-)
80b73c
80b73c
diff --git a/src/dp-media.c b/src/dp-media.c
80b73c
index cec6b8bb58d..96a576fdc2a 100644
80b73c
--- a/src/dp-media.c
80b73c
+++ b/src/dp-media.c
80b73c
@@ -162,6 +162,12 @@ efidp_make_file(uint8_t *buf, ssize_t size, char *filepath)
80b73c
 	ssize_t len = utf8len(lf, -1) + 1;
80b73c
 	ssize_t req = sizeof (*file) + len * sizeof (uint16_t);
80b73c
 
80b73c
+	if (len == 0) {
80b73c
+		errno = EINVAL;
80b73c
+		efi_error("%s() called with %s file path", __func__,
80b73c
+			  filepath == NULL ? "NULL" : "empty");
80b73c
+		return -1;
80b73c
+	}
80b73c
 	sz = efidp_make_generic(buf, size, EFIDP_MEDIA_TYPE, EFIDP_MEDIA_FILE,
80b73c
 				req);
80b73c
 	if (size && sz == req) {
80b73c
diff --git a/src/dp.c b/src/dp.c
80b73c
index 4e76e25b1a1..82d60b4f9be 100644
80b73c
--- a/src/dp.c
80b73c
+++ b/src/dp.c
80b73c
@@ -443,9 +443,17 @@ efidp_make_generic(uint8_t *buf, ssize_t size, uint8_t type, uint8_t subtype,
80b73c
 
80b73c
 	if (!size)
80b73c
 		return total_size;
80b73c
+
80b73c
+	if (!buf) {
80b73c
+		errno = EINVAL;
80b73c
+		efi_error("%s was called with nonzero size and NULL buffer",
80b73c
+			  __func__);
80b73c
+		return -1;
80b73c
+	}
80b73c
+
80b73c
 	if (size < total_size) {
80b73c
+		errno = ENOSPC;
80b73c
 		efi_error("total size is bigger than size limit");
80b73c
-		errno = ENOSPC;
80b73c
 		return -1;
80b73c
 	}
80b73c
 
80b73c
-- 
80b73c
2.17.1
80b73c