Fix line number accounting when a string contains a newline.

Strings are not allowed to span multiple lines without a continuation
character.  Also provide a better error message if we are in the
middle of a string and hit EOF.
This commit is contained in:
Todd C. Miller
2020-09-27 06:47:19 -06:00
parent 7d20900616
commit ddc1383838
3 changed files with 23 additions and 9 deletions

View File

@@ -4,4 +4,4 @@ USERALIAS ALIAS = BEGINSTR STRBODY STRBODY ENDSTR WORD(4)
USERALIAS ALIAS = WORD(6) USERALIAS ALIAS = WORD(6)
# #
USERALIAS ALIAS = BEGINSTR STRBODY <*> ERROR ERROR USERALIAS ALIAS = BEGINSTR STRBODY <*> ERROR

View File

@@ -3962,6 +3962,9 @@ YY_RULE_SETUP
#line 760 "toke.l" #line 760 "toke.l"
{ {
if (YY_START == INSTR) { if (YY_START == INSTR) {
/* re-scan after changing state */
BEGIN INITIAL;
sudoersless(0);
sudoerserror("unexpected line break in string"); sudoerserror("unexpected line break in string");
LEXTRACE("ERROR "); LEXTRACE("ERROR ");
return ERROR; return ERROR;
@@ -3975,7 +3978,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 77: case 77:
YY_RULE_SETUP YY_RULE_SETUP
#line 773 "toke.l" #line 776 "toke.l"
{ /* throw away space/tabs */ { /* throw away space/tabs */
sawspace = true; /* but remember for fill_args */ sawspace = true; /* but remember for fill_args */
} }
@@ -3983,7 +3986,7 @@ YY_RULE_SETUP
case 78: case 78:
/* rule 78 can match eol */ /* rule 78 can match eol */
YY_RULE_SETUP YY_RULE_SETUP
#line 777 "toke.l" #line 780 "toke.l"
{ {
sawspace = true; /* remember for fill_args */ sawspace = true; /* remember for fill_args */
sudolineno++; sudolineno++;
@@ -3993,7 +3996,7 @@ YY_RULE_SETUP
case 79: case 79:
/* rule 79 can match eol */ /* rule 79 can match eol */
YY_RULE_SETUP YY_RULE_SETUP
#line 783 "toke.l" #line 786 "toke.l"
{ {
if (sudoerstext[sudoersleng - 1] == '\n') { if (sudoerstext[sudoersleng - 1] == '\n') {
/* comment ending in a newline */ /* comment ending in a newline */
@@ -4011,7 +4014,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 80: case 80:
YY_RULE_SETUP YY_RULE_SETUP
#line 798 "toke.l" #line 801 "toke.l"
{ {
LEXTRACE("NOMATCH "); LEXTRACE("NOMATCH ");
return NOMATCH; return NOMATCH;
@@ -4026,9 +4029,13 @@ case YY_STATE_EOF(INSTR):
case YY_STATE_EOF(WANTDIGEST): case YY_STATE_EOF(WANTDIGEST):
case YY_STATE_EOF(GOTINC): case YY_STATE_EOF(GOTINC):
case YY_STATE_EOF(EXPECTPATH): case YY_STATE_EOF(EXPECTPATH):
#line 803 "toke.l" #line 806 "toke.l"
{ {
if (YY_START != INITIAL) { if (YY_START != INITIAL) {
if (YY_START == INSTR)
sudoerserror("unterminated string");
else
sudoerserror("unexpected state at EOF");
BEGIN INITIAL; BEGIN INITIAL;
LEXTRACE("ERROR "); LEXTRACE("ERROR ");
return ERROR; return ERROR;
@@ -4039,10 +4046,10 @@ case YY_STATE_EOF(EXPECTPATH):
YY_BREAK YY_BREAK
case 81: case 81:
YY_RULE_SETUP YY_RULE_SETUP
#line 813 "toke.l" #line 820 "toke.l"
ECHO; ECHO;
YY_BREAK YY_BREAK
#line 4040 "toke.c" #line 4047 "toke.c"
case YY_END_OF_BUFFER: case YY_END_OF_BUFFER:
{ {
@@ -5003,7 +5010,7 @@ void sudoersfree (void * ptr )
#define YYTABLES_NAME "yytables" #define YYTABLES_NAME "yytables"
#line 813 "toke.l" #line 820 "toke.l"
struct path_list { struct path_list {

View File

@@ -759,6 +759,9 @@ sudoedit {
<*>\r?\n { <*>\r?\n {
if (YY_START == INSTR) { if (YY_START == INSTR) {
/* re-scan after changing state */
BEGIN INITIAL;
sudoersless(0);
sudoerserror("unexpected line break in string"); sudoerserror("unexpected line break in string");
LEXTRACE("ERROR "); LEXTRACE("ERROR ");
return ERROR; return ERROR;
@@ -802,6 +805,10 @@ sudoedit {
<*><<EOF>> { <*><<EOF>> {
if (YY_START != INITIAL) { if (YY_START != INITIAL) {
if (YY_START == INSTR)
sudoerserror("unterminated string");
else
sudoerserror("unexpected state at EOF");
BEGIN INITIAL; BEGIN INITIAL;
LEXTRACE("ERROR "); LEXTRACE("ERROR ");
return ERROR; return ERROR;