mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
string.c: avoid infinite loop; fix #6143
`mrb_utf8len` returns 0 for invalid characters.
This commit is contained in:
+4
-1
@@ -409,7 +409,10 @@ str_index_str_by_char_search(mrb_state *mrb, const char *p, const char *pend, co
|
||||
if (pivot >= pend || pivot < p /* overflowed */) { return -1; }
|
||||
|
||||
do {
|
||||
p += mrb_utf8len(p, pend);
|
||||
mrb_int len = mrb_utf8len(p, pend);
|
||||
|
||||
if (len == 0) p++; /* invalid character */
|
||||
else p += len;
|
||||
off++;
|
||||
} while (p < pivot);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user