Skip to content
Myr

Fix heap buffer overflow when formatting an empty string

Before adoption: this commit came in with the history the project adopted, so no landing records it.

The `jv_string_empty` did not properly null-terminate the string data, which could lead to a heap buffer overflow. The test case of GHSA-p7rr-28xf-3m5w (`0[""*0]`) was fixed by the commit dc849e9bb74a, but another case (`0[[]|implode]`) was still vulnerable. This commit ensures string data is properly null-terminated, and fixes CVE-2025-48060.

authored by itchyny · committed by itchyny · parent 3b00981 · Browse files · 2 files+5 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+5 added−0 removed

  • tests:+4 added−0 removed
  • other:+1 added−0 removed

2 files+5 added−0 removed

modified:src/jv.c+1 added
1146 unmodified lines
1147static jv jvp_string_empty_new(uint32_t length) {1148 jvp_string* s = jvp_string_alloc(length);1149 s->length_hashed = 0;1150 memset(s->data, 0, length);1151 s->data[length] = 0;1152 jv r = {JVP_FLAGS_STRING, 0, 0, 0, {&s->refcnt}};1153 return r;1154}1155
915 unmodified lines
modified:tests/jq.test+4 added
2360 unmodified lines
2361map(try implode catch .)2362[123,["a"],[nan]]2363["implode input must be an array","string (\"a\") can't be imploded, unicode codepoint needs to be numeric","number (null) can't be imploded, unicode codepoint needs to be numeric"]23642365try 0[implode] catch .2366[]2367"Cannot index number with string \"\""23682369# walk2370walk(.)2371{"x":0}2372{"x":0}
125 unmodified lines