Fixed buffer overrun in function chars2bytes()

If `off` was greater than zero, the address pointed to by `e` exceeded the valid range of the buffer.
This commit is contained in:
dearblue
2025-02-26 21:22:37 +09:00
parent 66606f71dd
commit 76fc6e9ace
+3 -2
View File
@@ -465,9 +465,10 @@ chars2bytes(mrb_value str, mrb_int off, mrb_int idx)
return idx;
}
const char *p0 = RSTR_PTR(s) + off;
const char *o = RSTR_PTR(s);
const char *p0 = o + off;
const char *p = p0;
const char *e = p0 + RSTR_LEN(s);
const char *e = o + RSTR_LEN(s);
mrb_int i = 0;
while (p<e && i<idx) {