Skip to content

Commit 77d54cc

Browse files
committed
jsonfilter: fix memory leak in jsonfilter
Cherry pick an upstream patch to fix a memory leak. Fixed in OpenWrt main branch in commit 2c2cea8 ("package: update jsonfilter to latest HEAD 2026-03-12") Link: openwrt/jsonpath@e086664 Link: openwrt/openwrt#22440 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
1 parent 3e77f8c commit 77d54cc

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
From e086664e6a570630e8feba889482f174a9a8715e Mon Sep 17 00:00:00 2001
2+
From: Alexander Couzens <lynxis@fe80.eu>
3+
Date: Tue, 10 Feb 2026 13:42:26 +0100
4+
Subject: [PATCH] lexer: fix a minor memleak in jp_get_token()/match_token()
5+
6+
jp_get_token() is using a stack allocated jp_opcode op and
7+
is not using jp_alloc_op() or jp_free().
8+
9+
jp_get_token() is calling match_token() which might assign op->str
10+
and allocate it via strdup().
11+
12+
Fixes: TOB-OWRT-3
13+
Reported-by: Trail of Bits
14+
Signed-off-by: Alexander Couzens <lynxis@fe80.eu>
15+
---
16+
lexer.c | 8 +++++++-
17+
1 file changed, 7 insertions(+), 1 deletion(-)
18+
19+
--- a/lexer.c
20+
+++ b/lexer.c
21+
@@ -506,6 +506,7 @@ struct jp_opcode *
22+
jp_get_token(struct jp_state *s, const char *input, int *mlen)
23+
{
24+
struct jp_opcode op = { 0 };
25+
+ struct jp_opcode *newop;
26+
27+
*mlen = match_token(input, &op, s);
28+
29+
@@ -519,5 +520,10 @@ jp_get_token(struct jp_state *s, const c
30+
return NULL;
31+
}
32+
33+
- return jp_alloc_op(s, op.type, op.num, op.str, NULL);
34+
+ newop = jp_alloc_op(s, op.type, op.num, op.str, NULL);
35+
+ /* match_token might alloced str using strdup() */
36+
+ if (op.str)
37+
+ free(op.str);
38+
+
39+
+ return newop;
40+
}

0 commit comments

Comments
 (0)