[Mesa-dev] [PATCH mesa] intel/eu/validate: avoid null deref

Eric Engestrom eric.engestrom at imgtec.com
Mon Oct 23 17:08:46 UTC 2017

src/intel/compiler/brw_eu_validate.c:50:11: warning: argument 1 null where non-null expected [-Wnonnull]
    return memmem(haystack.str, haystack.len, needle.str, needle.len) != NULL;
In file included from src/gallium/include/pipe/p_compiler.h:39:0,
                 from src/gallium/auxiliary/util/u_math.h:42,
                 from src/mesa/main/macros.h:35,
                 from src/intel/compiler/brw_reg.h:47,
                 from src/intel/compiler/brw_eu.h:39,
                 from src/intel/compiler/brw_eu_validate.c:29:
/usr/include/string.h:368:14: note: in a call to function ‘memmem’ declared here
 extern void *memmem (const void *__haystack, size_t __haystacklen,

Signed-off-by: Eric Engestrom <eric.engestrom at imgtec.com>
Looks to me like error_msg.str always starts off being NULL, so I would
have expected this to have blown up already? I feel like I must be
missing something here.
 src/intel/compiler/brw_eu_validate.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/intel/compiler/brw_eu_validate.c b/src/intel/compiler/brw_eu_validate.c
index 9f72c650ddbd67ac6e18..a1c9e27ea2f8c1b466fd 100644
--- a/src/intel/compiler/brw_eu_validate.c
+++ b/src/intel/compiler/brw_eu_validate.c
@@ -47,6 +47,8 @@ cat(struct string *dest, const struct string src)
 static bool
 contains(const struct string haystack, const struct string needle)
+   if (!haystack.str || !needle.str)
+      return false;
    return memmem(haystack.str, haystack.len, needle.str, needle.len) != NULL;
 #define CONTAINS(haystack, needle) \

More information about the mesa-dev mailing list