Skip to content

Commit 5e159b3

Browse files
waderitchyny
authored andcommitted
Fix GHSA-f946-j5j2-4w5m stack-overflow by limit regex parse depth
Was detect by AFL build but it's unsure if possible to trigger in non-fuzz build. Oniguruma has a default limit of 4096 but this is not be low enough to protect from stack-overflows in some builds like with AFL where it seems to use more stack space. A limit of 1024 should be enough usage-wise and also give more margin.
1 parent 499c91b commit 5e159b3

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/main.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
extern void jv_tsd_dtoa_ctx_init();
2222
#endif
2323

24+
#ifdef HAVE_LIBONIG
25+
#include <oniguruma.h>
26+
#endif
27+
2428
#if !defined(HAVE_ISATTY) && defined(HAVE__ISATTY)
2529
#undef isatty
2630
#define isatty _isatty
@@ -298,6 +302,13 @@ int main(int argc, char* argv[]) {
298302
(void) setlocale(LC_ALL, "");
299303
#endif
300304

305+
#ifdef HAVE_LIBONIG
306+
// use a lower regex parse depth limit than the default (4096) to protect
307+
// from stack-overflows
308+
// https://github.com/jqlang/jq/security/advisories/GHSA-f946-j5j2-4w5m
309+
onig_set_parse_depth_limit(1024);
310+
#endif
311+
301312
#ifdef __OpenBSD__
302313
if (pledge("stdio rpath", NULL) == -1) {
303314
perror("pledge");

0 commit comments

Comments
 (0)