summaryrefslogtreecommitdiff
path: root/py/objstr.c
diff options
context:
space:
mode:
authorJeff Epler <jepler@gmail.com>2018-03-31 21:27:56 -0500
committerJeff Epler <jepler@gmail.com>2018-03-31 22:17:11 -0500
commit0041df0c6b493458000d7e815e094995cfbc8043 (patch)
tree015c8c17a143dbc9760610e61f88c4ee746fcc86 /py/objstr.c
parent3215b85568af98987c8d54af4e691637a74e91bc (diff)
py/objstr: Don't crash when end < start
.. and add testcases for the same. (crash found by afl-fuzz)
Diffstat (limited to 'py/objstr.c')
-rw-r--r--py/objstr.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/py/objstr.c b/py/objstr.c
index 64306f54f..7ace1cf73 100644
--- a/py/objstr.c
+++ b/py/objstr.c
@@ -692,8 +692,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");