]> git.lizzy.rs Git - plan9front.git/commitdiff
plumber: loop will go out of bounds when *++s == '\0'; replace with strstr
authorBurnZeZ <devnull@localhost>
Fri, 31 May 2019 22:15:53 +0000 (22:15 +0000)
committerBurnZeZ <devnull@localhost>
Fri, 31 May 2019 22:15:53 +0000 (22:15 +0000)
sys/src/cmd/plumb/rules.c

index 5f7ea34e754bee0b29681d0c6b79164c669a3a5d..c5bec452d5bcccccd473ffd3a84b0d04ef43e468 100644 (file)
@@ -728,7 +728,7 @@ morerules(uchar *text, int done)
 {
        int n;
        Ruleset *rs;
-       uchar *otext, *s, *endofrule;
+       uchar *otext, *p;
 
        pushinput("<rules input>", -1, text);
        if(done)
@@ -738,15 +738,11 @@ morerules(uchar *text, int done)
                 * Help user by sending any full rules to parser so any parse errors will
                 * occur on write rather than close. A heuristic will do: blank line ends rule.
                 */
-               endofrule = nil;
-               for(s=text; *s!='\0'; s++)
-                       if(*s=='\n' && *++s=='\n')
-                               endofrule = s+1;
-               if(endofrule == nil){
+               if((p = (uchar*)strstr((char*)text, "\n\n")) == nil){
                        popinput();
                        return text;
                }
-               input->end = endofrule;
+               input->end = p+2;
        }
        for(n=0; rules[n]; n++)
                ;