Blame SOURCES/0020-dp.h-Try-to-make-covscan-believe-format-is-checking-.patch

ac385c
From 9d74090cea256021e68b204c4770a5df28398cbd Mon Sep 17 00:00:00 2001
ac385c
From: Peter Jones <pjones@redhat.com>
ac385c
Date: Mon, 1 May 2017 15:59:09 -0400
ac385c
Subject: [PATCH 20/22] dp.h: Try to make covscan believe format() is checking
ac385c
 its bounds.
ac385c
ac385c
covscan doesn't grok that size and off wind up being proxies for buf's
ac385c
NULL check.  Hilarity ensues.
ac385c
ac385c
Signed-off-by: Peter Jones <pjones@redhat.com>
ac385c
---
ac385c
 src/dp.h | 16 +++++++++++-----
ac385c
 1 file changed, 11 insertions(+), 5 deletions(-)
ac385c
ac385c
diff --git a/src/dp.h b/src/dp.h
ac385c
index d6775a6..c14a9ec 100644
ac385c
--- a/src/dp.h
ac385c
+++ b/src/dp.h
ac385c
@@ -28,11 +28,17 @@
ac385c
 #include "ucs2.h"
ac385c
 
ac385c
 #define format(buf, size, off, dp_type, fmt, args...) ({		\
ac385c
-		ssize_t _x = 0;						\
ac385c
-		if ((off) >= 0) {					\
ac385c
-			_x = snprintf(((buf)+(off)),			\
ac385c
-			       ((size)?((size)-(off)):0),		\
ac385c
-			       fmt, ## args);				\
ac385c
+		ssize_t _insize = 0;					\
ac385c
+		void *_inbuf = NULL;					\
ac385c
+		if ((buf) != NULL && (size) > 0) {			\
ac385c
+			_inbuf = (buf) + (off);				\
ac385c
+			_insize = (size) - (off);			\
ac385c
+		}							\
ac385c
+		if ((off) >= 0 &&					\
ac385c
+		    ((buf == NULL && _insize == 0) ||			\
ac385c
+		     (buf != NULL && _insize >= 0))) {			\
ac385c
+			ssize_t _x = 0;					\
ac385c
+			_x = snprintf(_inbuf, _insize, fmt, ## args);	\
ac385c
 			if (_x < 0) {					\
ac385c
 				efi_error(				\
ac385c
 					"could not build %s DP string",	\
ac385c
-- 
ac385c
2.12.2
ac385c