summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorevan <evanbonner99@gmail.com>2023-03-06 21:16:06 +0000
committerevan <evanbonner99@gmail.com>2023-03-06 21:16:06 +0000
commit9da214a7a36393c0342258679690a83f6405a30a (patch)
treeb17e0407de3c174db55390874a75014e6d97efa6
parentd442ab79ca91616ab15acb342013e489db5b67c2 (diff)
Fix UB on parser error and buffer overrun in yylex
-rwxr-xr-xsrc/gram.y11
-rw-r--r--src/lex.c4
2 files changed, 9 insertions, 6 deletions
diff --git a/src/gram.y b/src/gram.y
index 606181c..c9f7888 100755
--- a/src/gram.y
+++ b/src/gram.y
@@ -1239,12 +1239,15 @@ command:
| // nothing
| error {
sc_error("syntax error: %s", line);
- line[0]='\0';
+ YYABORT;
+
//linelim = 0;
//yyparse();
- linelim = -1;
- yyclearin;
- yyerrok;
+
+ //line[0]='\0';
+ //linelim = -1;
+ //yyclearin;
+ //yyerrok;
};
term: var {
diff --git a/src/lex.c b/src/lex.c
index 1b70241..5ff8eda 100644
--- a/src/lex.c
+++ b/src/lex.c
@@ -160,9 +160,9 @@ int yylex() {
for (tblp = linelim ? experres : statres; tblp->key; tblp++) {
if (((tblp->key[0]^tokenst[0])&0137)==0) {
int i = 1;
- while (i<tokenl && ((tokenst[i]^tblp->key[i])&0137)==0)
+ while (tblp->key[i] && i<tokenl && ((tokenst[i]^tblp->key[i])&0137)==0)
i++;
- if (i >= tokenl) {
+ if (i >= tokenl && tblp->key[i] == '\0') {
ret = tblp->val;
colstate = (ret <= S_FORMAT);
if (isgoto) {