Skip to content

Commit c6e0416

Browse files
committed
Fix heap buffer overflow when formatting an empty string
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 dc849e9, but another case (`0[[]|implode]`) was still vulnerable. This commit ensures string data is properly null-terminated, and fixes CVE-2025-48060.
1 parent 3b00981 commit c6e0416

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

src/jv.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,7 @@ static jv jvp_string_empty_new(uint32_t length) {
11481148
jvp_string* s = jvp_string_alloc(length);
11491149
s->length_hashed = 0;
11501150
memset(s->data, 0, length);
1151+
s->data[length] = 0;
11511152
jv r = {JVP_FLAGS_STRING, 0, 0, 0, {&s->refcnt}};
11521153
return r;
11531154
}

tests/jq.test

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2362,6 +2362,10 @@ map(try implode catch .)
23622362
[123,["a"],[nan]]
23632363
["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"]
23642364

2365+
try 0[implode] catch .
2366+
[]
2367+
"Cannot index number with string \"\""
2368+
23652369
# walk
23662370
walk(.)
23672371
{"x":0}

0 commit comments

Comments
 (0)