changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > plan9front / changeset: plumber: loop will go out of bounds when *++s == '\0'; replace with strstr

changeset 7258: 783d3ae87188
parent 7257: e55d4b846784
child 7259: 32b0b95f1964
author: BurnZeZ
date: Fri, 31 May 2019 22:15:53 +0000
files: sys/src/cmd/plumb/rules.c
description: plumber: loop will go out of bounds when *++s == '\0'; replace with strstr
     1.1--- a/sys/src/cmd/plumb/rules.c
     1.2+++ b/sys/src/cmd/plumb/rules.c
     1.3@@ -728,7 +728,7 @@ morerules(uchar *text, int done)
     1.4 {
     1.5 	int n;
     1.6 	Ruleset *rs;
     1.7-	uchar *otext, *s, *endofrule;
     1.8+	uchar *otext, *p;
     1.9 
    1.10 	pushinput("<rules input>", -1, text);
    1.11 	if(done)
    1.12@@ -738,15 +738,11 @@ morerules(uchar *text, int done)
    1.13 		 * Help user by sending any full rules to parser so any parse errors will
    1.14 		 * occur on write rather than close. A heuristic will do: blank line ends rule.
    1.15 		 */
    1.16-		endofrule = nil;
    1.17-		for(s=text; *s!='\0'; s++)
    1.18-			if(*s=='\n' && *++s=='\n')
    1.19-				endofrule = s+1;
    1.20-		if(endofrule == nil){
    1.21+		if((p = (uchar*)strstr((char*)text, "\n\n")) == nil){
    1.22 			popinput();
    1.23 			return text;
    1.24 		}
    1.25-		input->end = endofrule;
    1.26+		input->end = p+2;
    1.27 	}
    1.28 	for(n=0; rules[n]; n++)
    1.29 		;