From f5147e312f43a9050468de539aeafa072caa1a60 Mon Sep 17 00:00:00 2001 From: Conrad Meyer Date: Mon, 26 Mar 2018 22:02:36 +0000 Subject: [PATCH] libctf: Don't construct pointers to out of bounds array offsets Just attempting to do the pointer arithmetic is undefined behavior. No functional change intended. Reported by: Coverity Sponsored by: Dell EMC Isilon --- cddl/contrib/opensolaris/common/ctf/ctf_lookup.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cddl/contrib/opensolaris/common/ctf/ctf_lookup.c b/cddl/contrib/opensolaris/common/ctf/ctf_lookup.c index f8fa72435591..aa58663309b6 100644 --- a/cddl/contrib/opensolaris/common/ctf/ctf_lookup.c +++ b/cddl/contrib/opensolaris/common/ctf/ctf_lookup.c @@ -59,10 +59,12 @@ isqualifier(const char *s, size_t len) }; int h = s[len - 1] + (int)len - 105; - const struct qual *qp = &qhash[h]; + const struct qual *qp; - return (h >= 0 && h < sizeof (qhash) / sizeof (qhash[0]) && - len == qp->q_len && strncmp(qp->q_name, s, qp->q_len) == 0); + if (h < 0 || h >= sizeof (qhash) / sizeof (qhash[0])) + return (0); + qp = &qhash[h]; + return (len == qp->q_len && strncmp(qp->q_name, s, qp->q_len) == 0); } /*