From 9dd46b2527877caf69b11e809e4bcf42b42bcd83 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Sun, 27 Mar 2011 17:16:15 -0400 Subject: [PATCH] Use bitwise AND instead of modulus to check for length being odd. A newline in the middle of a string is an error unless a line continuation character is used. --HG-- branch : 1.7 --- toke.c | 22 +++++++++++++--------- toke.l | 6 +++++- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/toke.c b/toke.c index ebd7a93ae..f6e8b8879 100644 --- a/toke.c +++ b/toke.c @@ -2340,7 +2340,7 @@ case 50: YY_RULE_SETUP #line 562 "toke.l" { - if (yyleng % 2 == 1) + if (yyleng & 1) return '!'; /* return '!' */ } YY_BREAK @@ -2348,6 +2348,10 @@ case 51: YY_RULE_SETUP #line 567 "toke.l" { + if (YY_START == INSTR) { + LEXTRACE("ERROR "); + return ERROR; /* line break in string */ + } BEGIN INITIAL; ++sudolineno; continued = FALSE; @@ -2357,14 +2361,14 @@ YY_RULE_SETUP YY_BREAK case 52: YY_RULE_SETUP -#line 575 "toke.l" +#line 579 "toke.l" { /* throw away space/tabs */ sawspace = TRUE; /* but remember for fill_args */ } YY_BREAK case 53: YY_RULE_SETUP -#line 579 "toke.l" +#line 583 "toke.l" { sawspace = TRUE; /* remember for fill_args */ ++sudolineno; @@ -2373,7 +2377,7 @@ YY_RULE_SETUP YY_BREAK case 54: YY_RULE_SETUP -#line 585 "toke.l" +#line 589 "toke.l" { BEGIN INITIAL; ++sudolineno; @@ -2384,7 +2388,7 @@ YY_RULE_SETUP YY_BREAK case 55: YY_RULE_SETUP -#line 593 "toke.l" +#line 597 "toke.l" { LEXTRACE("ERROR "); return ERROR; @@ -2396,7 +2400,7 @@ case YY_STATE_EOF(GOTCMND): case YY_STATE_EOF(STARTDEFS): case YY_STATE_EOF(INDEFS): case YY_STATE_EOF(INSTR): -#line 598 "toke.l" +#line 602 "toke.l" { if (YY_START != INITIAL) { BEGIN INITIAL; @@ -2409,10 +2413,10 @@ case YY_STATE_EOF(INSTR): YY_BREAK case 56: YY_RULE_SETUP -#line 608 "toke.l" +#line 612 "toke.l" ECHO; YY_BREAK -#line 2415 "lex.yy.c" +#line 2419 "lex.yy.c" case YY_END_OF_BUFFER: { @@ -3303,7 +3307,7 @@ int main() return 0; } #endif -#line 608 "toke.l" +#line 612 "toke.l" struct path_list { char *path; diff --git a/toke.l b/toke.l index f9b49f85b..ee56a6d04 100644 --- a/toke.l +++ b/toke.l @@ -560,11 +560,15 @@ sudoedit { } /* return ':' */ <*>!+ { - if (yyleng % 2 == 1) + if (yyleng & 1) return '!'; /* return '!' */ } <*>\n { + if (YY_START == INSTR) { + LEXTRACE("ERROR "); + return ERROR; /* line break in string */ + } BEGIN INITIAL; ++sudolineno; continued = FALSE; -- 2.40.0