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

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