Skip to content
Myr

builtin/f_match: prevent overruns of input_string

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

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

authored by Derrick Pallas · committed by Nicolas Williams · parent d29bf5b · Browse files · 1 file+3 added−3 removed
This commit

State

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

Diff stats

1 file+3 added−3 removed

  • other:+3 added−3 removed

1 file+3 added−3 removed

modified:src/builtin.c+3 added-3 removed
863 unmodified lines
864 // Zero-width match865 if (region->end[0] == region->beg[0]) {866 unsigned long idx;867 const char *fr = (const char*)input_string;868 for (idx = 0; fr != input_string+region->beg[0]; idx++) {868 for (idx = 0; fr < input_string+region->beg[0]; idx++) {869 fr += jvp_utf8_decode_length(*fr);870 }871 jv match = jv_object_set(jv_object(), jv_string("offset"), jv_number(idx));872 match = jv_object_set(match, jv_string("length"), jv_number(0));
28 unmodified lines
901 cap = jv_object_set(jv_object(), jv_string("offset"), jv_number(-1));902 cap = jv_object_set(cap, jv_string("string"), jv_null());903 } else {904 fr = input_string;905 for (idx = 0; fr != input_string+region->beg[i]; idx++) {905 for (idx = 0; fr < input_string+region->beg[i]; idx++) {906 fr += jvp_utf8_decode_length(*fr);907 }908 cap = jv_object_set(jv_object(), jv_string("offset"), jv_number(idx));909 cap = jv_object_set(cap, jv_string("string"), jv_string(""));
3 unmodified lines
913 captures = jv_array_append(captures, cap);914 continue;915 }916 fr = input_string;917 for (idx = len = 0; fr != input_string+region->end[i]; len++) {917 for (idx = len = 0; fr < input_string+region->end[i]; len++) {918 if (fr == input_string+region->beg[i]) idx = len, len=0;919 fr += jvp_utf8_decode_length(*fr);920 }921
891 unmodified lines