summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas Williams <nico@cryptonector.com>2019-02-08 20:39:36 -0600
committerNicolas Williams <nico@cryptonector.com>2019-02-08 20:40:55 -0600
commit2660b04a731568c54eb4b91fe811d81cbbf3470b (patch)
treea3f99840574d3bf3c1fc2b4947d73215f25c6c68
parent18ac789d6d74f198053c547fba4e8c70cb99d55a (diff)
Fix infinite loop in index("") (fix #1815)
-rw-r--r--src/jv.c2
-rw-r--r--tests/jq.test5
2 files changed, 7 insertions, 0 deletions
diff --git a/src/jv.c b/src/jv.c
index f051d730..b3fcd5e3 100644
--- a/src/jv.c
+++ b/src/jv.c
@@ -658,6 +658,8 @@ jv jv_string_indexes(jv j, jv k) {
int idxlen = jv_string_length_bytes(jv_copy(k));
jv a = jv_array();
+ if (idxlen == 0)
+ return a;
p = jstr;
while ((p = _jq_memmem(p, (jstr + jlen) - p, idxstr, idxlen)) != NULL) {
a = jv_array_append(a, jv_number(p - jstr));
diff --git a/tests/jq.test b/tests/jq.test
index 6ee657b6..1572043e 100644
--- a/tests/jq.test
+++ b/tests/jq.test
@@ -1538,4 +1538,9 @@ isempty(1,error("foo"))
null
false
+# Regression test for #1815
+index("")
+""
+null
+