diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2020-12-19 14:33:02 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2020-12-19 14:33:02 +0100 |
| commit | 2124c0ec97249b66889b6486ab5b5223993d31c0 (patch) | |
| tree | 30a919f6a37c9de4a08a94ec55aaaaba4681e99f /shell | |
| parent | 4152b41183b03aa53b6ce5a8c02b857c577f1723 (diff) | |
| download | busybox-w32-2124c0ec97249b66889b6486ab5b5223993d31c0.tar.gz busybox-w32-2124c0ec97249b66889b6486ab5b5223993d31c0.tar.bz2 busybox-w32-2124c0ec97249b66889b6486ab5b5223993d31c0.zip | |
ash: clear ungetc counter on syntax errors
function old new delta
raise_exception 26 39 +13
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
| -rw-r--r-- | shell/ash.c | 112 |
1 files changed, 57 insertions, 55 deletions
diff --git a/shell/ash.c b/shell/ash.c index b271dd031..87d329f87 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
| @@ -544,6 +544,61 @@ var_end(const char *var) | |||
| 544 | } | 544 | } |
| 545 | 545 | ||
| 546 | 546 | ||
| 547 | /* ============ Parser data */ | ||
| 548 | |||
| 549 | /* | ||
| 550 | * ash_vmsg() needs parsefile->fd, hence parsefile definition is moved up. | ||
| 551 | */ | ||
| 552 | struct strlist { | ||
| 553 | struct strlist *next; | ||
| 554 | char *text; | ||
| 555 | }; | ||
| 556 | |||
| 557 | struct alias; | ||
| 558 | |||
| 559 | struct strpush { | ||
| 560 | struct strpush *prev; /* preceding string on stack */ | ||
| 561 | char *prev_string; | ||
| 562 | int prev_left_in_line; | ||
| 563 | #if ENABLE_ASH_ALIAS | ||
| 564 | struct alias *ap; /* if push was associated with an alias */ | ||
| 565 | #endif | ||
| 566 | char *string; /* remember the string since it may change */ | ||
| 567 | |||
| 568 | /* Remember last two characters for pungetc. */ | ||
| 569 | int lastc[2]; | ||
| 570 | |||
| 571 | /* Number of outstanding calls to pungetc. */ | ||
| 572 | int unget; | ||
| 573 | }; | ||
| 574 | |||
| 575 | /* | ||
| 576 | * The parsefile structure pointed to by the global variable parsefile | ||
| 577 | * contains information about the current file being read. | ||
| 578 | */ | ||
| 579 | struct parsefile { | ||
| 580 | struct parsefile *prev; /* preceding file on stack */ | ||
| 581 | int linno; /* current line */ | ||
| 582 | int pf_fd; /* file descriptor (or -1 if string) */ | ||
| 583 | int left_in_line; /* number of chars left in this line */ | ||
| 584 | int left_in_buffer; /* number of chars left in this buffer past the line */ | ||
| 585 | char *next_to_pgetc; /* next char in buffer */ | ||
| 586 | char *buf; /* input buffer */ | ||
| 587 | struct strpush *strpush; /* for pushing strings at this level */ | ||
| 588 | struct strpush basestrpush; /* so pushing one is fast */ | ||
| 589 | |||
| 590 | /* Remember last two characters for pungetc. */ | ||
| 591 | int lastc[2]; | ||
| 592 | |||
| 593 | /* Number of outstanding calls to pungetc. */ | ||
| 594 | int unget; | ||
| 595 | }; | ||
| 596 | |||
| 597 | static struct parsefile basepf; /* top level input file */ | ||
| 598 | static struct parsefile *g_parsefile = &basepf; /* current input file */ | ||
| 599 | static char *commandname; /* currently executing command */ | ||
| 600 | |||
| 601 | |||
| 547 | /* ============ Interrupts / exceptions */ | 602 | /* ============ Interrupts / exceptions */ |
| 548 | 603 | ||
| 549 | static void exitshell(void) NORETURN; | 604 | static void exitshell(void) NORETURN; |
| @@ -581,6 +636,8 @@ raise_exception(int e) | |||
| 581 | abort(); | 636 | abort(); |
| 582 | #endif | 637 | #endif |
| 583 | INT_OFF; | 638 | INT_OFF; |
| 639 | /* Prevent this: ";l" -> syntax error, then "s" -> runs "ls" */ | ||
| 640 | g_parsefile->unget = 0; | ||
| 584 | exception_type = e; | 641 | exception_type = e; |
| 585 | longjmp(exception_handler->loc, 1); | 642 | longjmp(exception_handler->loc, 1); |
| 586 | } | 643 | } |
| @@ -1299,61 +1356,6 @@ showtree(union node *n) | |||
| 1299 | #endif /* DEBUG */ | 1356 | #endif /* DEBUG */ |
| 1300 | 1357 | ||
| 1301 | 1358 | ||
| 1302 | /* ============ Parser data */ | ||
| 1303 | |||
| 1304 | /* | ||
| 1305 | * ash_vmsg() needs parsefile->fd, hence parsefile definition is moved up. | ||
| 1306 | */ | ||
| 1307 | struct strlist { | ||
| 1308 | struct strlist *next; | ||
| 1309 | char *text; | ||
| 1310 | }; | ||
| 1311 | |||
| 1312 | struct alias; | ||
| 1313 | |||
| 1314 | struct strpush { | ||
| 1315 | struct strpush *prev; /* preceding string on stack */ | ||
| 1316 | char *prev_string; | ||
| 1317 | int prev_left_in_line; | ||
| 1318 | #if ENABLE_ASH_ALIAS | ||
| 1319 | struct alias *ap; /* if push was associated with an alias */ | ||
| 1320 | #endif | ||
| 1321 | char *string; /* remember the string since it may change */ | ||
| 1322 | |||
| 1323 | /* Remember last two characters for pungetc. */ | ||
| 1324 | int lastc[2]; | ||
| 1325 | |||
| 1326 | /* Number of outstanding calls to pungetc. */ | ||
| 1327 | int unget; | ||
| 1328 | }; | ||
| 1329 | |||
| 1330 | /* | ||
| 1331 | * The parsefile structure pointed to by the global variable parsefile | ||
| 1332 | * contains information about the current file being read. | ||
| 1333 | */ | ||
| 1334 | struct parsefile { | ||
| 1335 | struct parsefile *prev; /* preceding file on stack */ | ||
| 1336 | int linno; /* current line */ | ||
| 1337 | int pf_fd; /* file descriptor (or -1 if string) */ | ||
| 1338 | int left_in_line; /* number of chars left in this line */ | ||
| 1339 | int left_in_buffer; /* number of chars left in this buffer past the line */ | ||
| 1340 | char *next_to_pgetc; /* next char in buffer */ | ||
| 1341 | char *buf; /* input buffer */ | ||
| 1342 | struct strpush *strpush; /* for pushing strings at this level */ | ||
| 1343 | struct strpush basestrpush; /* so pushing one is fast */ | ||
| 1344 | |||
| 1345 | /* Remember last two characters for pungetc. */ | ||
| 1346 | int lastc[2]; | ||
| 1347 | |||
| 1348 | /* Number of outstanding calls to pungetc. */ | ||
| 1349 | int unget; | ||
| 1350 | }; | ||
| 1351 | |||
| 1352 | static struct parsefile basepf; /* top level input file */ | ||
| 1353 | static struct parsefile *g_parsefile = &basepf; /* current input file */ | ||
| 1354 | static char *commandname; /* currently executing command */ | ||
| 1355 | |||
| 1356 | |||
| 1357 | /* ============ Message printing */ | 1359 | /* ============ Message printing */ |
| 1358 | 1360 | ||
| 1359 | static void | 1361 | static void |
