Skip to content

Commit

Permalink
nixd/Parser: fix trailing-slash causing infinite loop in the Lexer
Browse files Browse the repository at this point in the history
Fixes: #231
  • Loading branch information
inclyc committed Jul 26, 2023
1 parent b835f4e commit 9a232a2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion nixd/lib/Parser/Lexer.l
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,19 @@ or { return OR_KW; }
.msg = hintfmt("invalid integer '%1%'", yytext),
.errPos = data->state.positions[CUR_POS],
});
yyterminate();
}
return INT;
}
{FLOAT} { errno = 0;
yylval->nf = strtod(yytext, 0);
if (errno != 0)
if (errno != 0) {
data->error.emplace_back(nix::ErrorInfo{
.msg = hintfmt("invalid float '%1%'", yytext),
.errPos = data->state.positions[CUR_POS],
});
yyterminate();
}
return FLOAT;
}

Expand Down Expand Up @@ -205,6 +208,7 @@ or { return OR_KW; }
.msg = hintfmt("path has a trailing slash"),
.errPos = data->state.positions[CUR_POS],
});
yyterminate();
}

{SPATH} { yylval->path = {yytext, (size_t) yyleng}; return SPATH; }
Expand Down
3 changes: 3 additions & 0 deletions nixd/tools/nixd-ast-dump/test/issue-231.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# RUN: valgrind --leak-check=full --error-exitcode=1 nixd-ast-dump %s

/././

0 comments on commit 9a232a2

Please sign in to comment.