summaryrefslogtreecommitdiff
path: root/py
diff options
context:
space:
mode:
authorScott Shawcroft <scott@tannewt.org>2018-04-01 22:41:59 -0700
committerGitHub <noreply@github.com>2018-04-01 22:41:59 -0700
commite4ae1e3d59f71200a01cbf8cf2128939f181863f (patch)
tree813ffd718011a1ae6030909a46c79a0616298a61 /py
parentb62d8faaec57899abff13cb70a7e0007cba4479c (diff)
parent0041df0c6b493458000d7e815e094995cfbc8043 (diff)
Merge pull request #734 from jepler/str-find-backwards-circuitpython
py/objstr: Don't crash when end < start
Diffstat (limited to 'py')
-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");