Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 26 Mar 2018 22:02:36 +0000 (UTC)
From:      Conrad Meyer <cem@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r331595 - head/cddl/contrib/opensolaris/common/ctf
Message-ID:  <201803262202.w2QM2aJh067799@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: cem
Date: Mon Mar 26 22:02:36 2018
New Revision: 331595
URL: https://svnweb.freebsd.org/changeset/base/331595

Log:
  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

Modified:
  head/cddl/contrib/opensolaris/common/ctf/ctf_lookup.c

Modified: head/cddl/contrib/opensolaris/common/ctf/ctf_lookup.c
==============================================================================
--- head/cddl/contrib/opensolaris/common/ctf/ctf_lookup.c	Mon Mar 26 21:57:44 2018	(r331594)
+++ head/cddl/contrib/opensolaris/common/ctf/ctf_lookup.c	Mon Mar 26 22:02:36 2018	(r331595)
@@ -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);
 }
 
 /*



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201803262202.w2QM2aJh067799>