dda48ab9b28de6442a016aadbd93198d6c69a46e kent Wed Aug 7 23:54:00 2019 -0700 Fixed an inconsistency in memory handling in nextStringBetween. It is now safe in all cases to free the returned value. diff --git src/lib/common.c src/lib/common.c index 8910ce8..34ddb6c 100644 --- src/lib/common.c +++ src/lib/common.c @@ -1517,30 +1517,32 @@ char *nextStringBetween(char *start, char *end, char **pHaystack) /* Return next string that occurs between start and end strings * starting seach at *pHaystack. This will update *pHaystack to after * end, so it can be called repeatedly. Returns NULL when * no more to be found*/ { char *pos, *p; int len; char *haystack = *pHaystack; if (isEmpty(haystack)) return NULL; if ((p = stringIn(start, haystack)) != NULL) { pos = p + strlen(start); + if (isEmpty(end)) + return cloneString(pos); if ((p = stringIn(end, pos)) != NULL) { len = p - pos; pos = cloneMem(pos, len + 1); pos[len] = 0; *pHaystack = p; return pos; } } *pHaystack = NULL; return NULL; } char *stringBetween(char *start, char *end, char *haystack) /* Return string between start and end strings, or NULL if