builtin/f_match: prevent overruns of input_string
If these values do not match exactly, it is because the UTF-8 is invalid anyway and we counted codepoints differently than oniguruma did. Perhaps it would be better to error out here, but at least one similar loop already uses < vs != and since we're off the rails anyway this might be OK. It is certainly better than overruning the buffer. Resolves https://github.com/stedolan/jq/issues/1804
This commit is contained in:
1 parent
d29bf5b4fc
commit
21be3857b5
1 file changed
+3
-3
+3
-3
@@ -865,7 +865,7 @@ static jv f_match(jq_state *jq, jv input, jv regex, jv modifiers, jv testmode) {
|
|||||||
if (region->end[0] == region->beg[0]) {
|
if (region->end[0] == region->beg[0]) {
|
||||||
unsigned long idx;
|
unsigned long idx;
|
||||||
const char *fr = (const char*)input_string;
|
const char *fr = (const char*)input_string;
|
||||||
for (idx = 0; fr != input_string+region->beg[0]; idx++) {
|
for (idx = 0; fr < input_string+region->beg[0]; idx++) {
|
||||||
fr += jvp_utf8_decode_length(*fr);
|
fr += jvp_utf8_decode_length(*fr);
|
||||||
}
|
}
|
||||||
jv match = jv_object_set(jv_object(), jv_string("offset"), jv_number(idx));
|
jv match = jv_object_set(jv_object(), jv_string("offset"), jv_number(idx));
|
||||||
@@ -902,7 +902,7 @@ static jv f_match(jq_state *jq, jv input, jv regex, jv modifiers, jv testmode) {
|
|||||||
cap = jv_object_set(cap, jv_string("string"), jv_null());
|
cap = jv_object_set(cap, jv_string("string"), jv_null());
|
||||||
} else {
|
} else {
|
||||||
fr = input_string;
|
fr = input_string;
|
||||||
for (idx = 0; fr != input_string+region->beg[i]; idx++) {
|
for (idx = 0; fr < input_string+region->beg[i]; idx++) {
|
||||||
fr += jvp_utf8_decode_length(*fr);
|
fr += jvp_utf8_decode_length(*fr);
|
||||||
}
|
}
|
||||||
cap = jv_object_set(jv_object(), jv_string("offset"), jv_number(idx));
|
cap = jv_object_set(jv_object(), jv_string("offset"), jv_number(idx));
|
||||||
@@ -914,7 +914,7 @@ static jv f_match(jq_state *jq, jv input, jv regex, jv modifiers, jv testmode) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
fr = input_string;
|
fr = input_string;
|
||||||
for (idx = len = 0; fr != input_string+region->end[i]; len++) {
|
for (idx = len = 0; fr < input_string+region->end[i]; len++) {
|
||||||
if (fr == input_string+region->beg[i]) idx = len, len=0;
|
if (fr == input_string+region->beg[i]) idx = len, len=0;
|
||||||
fr += jvp_utf8_decode_length(*fr);
|
fr += jvp_utf8_decode_length(*fr);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user