diff options
author | Jeff Epler <jepler@gmail.com> | 2018-03-31 21:27:56 -0500 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2018-04-05 16:14:17 +1000 |
commit | d6cf5c674952d5ae3463d9b580dac6559576deac (patch) | |
tree | e2841aaa54ff91696c6725efcffb3d1ca992c4db /py/objstr.c | |
parent | b9c78425a66234c45ac5c0b159773363d185d914 (diff) |
py/objstr: In find/rfind, don't crash when end < start.
Diffstat (limited to 'py/objstr.c')
-rw-r--r-- | py/objstr.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/py/objstr.c b/py/objstr.c index 0b11533f8..da925234e 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -699,8 +699,13 @@ STATIC mp_obj_t str_finder(size_t n_args, const mp_obj_t *args, int direction, b end = str_index_to_ptr(self_type, haystack, haystack_len, args[3], true); } + if (end < start) { + goto out_error; + } + const byte *p = find_subbytes(start, end - start, needle, needle_len, direction); if (p == NULL) { + out_error: // not found if (is_index) { mp_raise_ValueError("substring not found"); |