Bug 1280844 - Fix a null check in parse.c. r?mt. draft
authorNicholas Nethercote <nnethercote@mozilla.com>
Tue, 21 Jun 2016 09:59:17 +1000
changeset 380170 f715f0bb465f9925ecd19d6fca66093147e6401e
parent 380169 861c92565f6c16310f84953804e9365d7c1302cc
child 380171 cb51d2f903ca1ceda8461644289df0da4d4ab67b
push id21158
push usernnethercote@mozilla.com
push dateMon, 20 Jun 2016 23:59:39 +0000
reviewersmt
bugs1280844
milestone50.0a1
Bug 1280844 - Fix a null check in parse.c. r?mt. This patch fixes things so that we don't deref file before checking it. MozReview-Commit-ID: 6z6wzfVWNYj
security/nss/coreconf/mkdepend/parse.c
--- a/security/nss/coreconf/mkdepend/parse.c
+++ b/security/nss/coreconf/mkdepend/parse.c
@@ -424,19 +424,26 @@ define(char *def, struct inclist *file)
 	val = "1";
     define2(def, val, file);
 }
 
 struct symtab **
 slookup(char *symbol, struct inclist *file)
 {
 	register int first = 0;
-	register int last = file->i_ndefs - 1;
+	register int last;
 
-	if (file) while (last >= first)
+	if (!file)
+	{
+	    return NULL;
+	}
+
+	last = file->i_ndefs - 1;
+
+	while (last >= first)
 	{
 	    /* Fast inline binary search */
 	    register char *s1;
 	    register char *s2;
 	    register int middle = first + (last - first) / 2;
 
 	    /* Fast inline strchr() */
 	    s1 = symbol;
@@ -456,17 +463,17 @@ slookup(char *symbol, struct inclist *fi
 	        first = middle + 1;
 	    }
 	    /* else ... */
 	    else
 	    {
 	        last = middle - 1;
 	    }
 	}
-	return(NULL);
+	return NULL;
 }
 
 static int 
 merge2defines(struct inclist *file1, struct inclist *file2)
 {
 	int i;
 
 	if ((file1==NULL) || (file2==NULL) ||