Skip to content

Commit e086664

Browse files
committed
lexer: fix a minor memleak in jp_get_token()/match_token()
jp_get_token() is using a stack allocated jp_opcode op and is not using jp_alloc_op() or jp_free(). jp_get_token() is calling match_token() which might assign op->str and allocate it via strdup(). Fixes: TOB-OWRT-3 Reported-by: Trail of Bits Signed-off-by: Alexander Couzens <[email protected]>
1 parent e5a07f4 commit e086664

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

‎lexer.c‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,7 @@ struct jp_opcode *
506506
jp_get_token(struct jp_state *s, const char *input, int *mlen)
507507
{
508508
struct jp_opcode op = { 0 };
509+
struct jp_opcode *newop;
509510

510511
*mlen = match_token(input, &op, s);
511512

@@ -519,5 +520,10 @@ jp_get_token(struct jp_state *s, const char *input, int *mlen)
519520
return NULL;
520521
}
521522

522-
return jp_alloc_op(s, op.type, op.num, op.str, NULL);
523+
newop = jp_alloc_op(s, op.type, op.num, op.str, NULL);
524+
/* match_token might alloced str using strdup() */
525+
if (op.str)
526+
free(op.str);
527+
528+
return newop;
523529
}

0 commit comments

Comments
 (0)