OSDN Git Service

dp.h: Try to make covscan believe format() is checking its bounds.
authorPeter Jones <pjones@redhat.com>
Mon, 1 May 2017 19:59:09 +0000 (15:59 -0400)
committerPeter Jones <pjones@redhat.com>
Mon, 1 May 2017 20:06:31 +0000 (16:06 -0400)
covscan doesn't grok that size and off wind up being proxies for buf's
NULL check.  Hilarity ensues.

Signed-off-by: Peter Jones <pjones@redhat.com>
src/dp.h

index d6775a6..c14a9ec 100644 (file)
--- a/src/dp.h
+++ b/src/dp.h
 #include "ucs2.h"
 
 #define format(buf, size, off, dp_type, fmt, args...) ({               \
-               ssize_t _x = 0;                                         \
-               if ((off) >= 0) {                                       \
-                       _x = snprintf(((buf)+(off)),                    \
-                              ((size)?((size)-(off)):0),               \
-                              fmt, ## args);                           \
+               ssize_t _insize = 0;                                    \
+               void *_inbuf = NULL;                                    \
+               if ((buf) != NULL && (size) > 0) {                      \
+                       _inbuf = (buf) + (off);                         \
+                       _insize = (size) - (off);                       \
+               }                                                       \
+               if ((off) >= 0 &&                                       \
+                   ((buf == NULL && _insize == 0) ||                   \
+                    (buf != NULL && _insize >= 0))) {                  \
+                       ssize_t _x = 0;                                 \
+                       _x = snprintf(_inbuf, _insize, fmt, ## args);   \
                        if (_x < 0) {                                   \
                                efi_error(                              \
                                        "could not build %s DP string", \