commit 7efa977077c8e24c81d5b9a0e384ccfc7efd4d25
parent 4cb92f7db22e32384494488e1d63a3c2a841843a
Author: Alexey Yerin <yyp@disroot.org>
Date: Mon, 21 Feb 2022 21:15:19 +0300
lex: allocate space for a NUL byte
This causes an out-of-bounds read, and thus libhart build failures on
FreeBSD (not sure why it doesn't happen on Linux).
Signed-off-by: Alexey Yerin <yyp@disroot.org>
Diffstat:
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/lex.c b/src/lex.c
@@ -553,7 +553,7 @@ lex_string(struct lexer *lexer, struct token *out)
delim = c;
while ((c = next(lexer, NULL, false)) != UTF8_INVALID) {
if (c == delim) {
- char *buf = xcalloc(lexer->buflen, 1);
+ char *buf = xcalloc(lexer->buflen + 1, 1);
memcpy(buf, lexer->buf, lexer->buflen);
out->token = T_LITERAL;
out->storage = STORAGE_STRING;