commit 4d23b52f42c1843b5ef06710299d3ea4897a2f1a parent 75e7d1d81f814895bf1623eb3d9072c967c0fbf7 Author: Jacob R. Edwards <jacobouno@protonmail.com> Date: Fri, 27 Aug 2021 23:45:46 -0700 Fix NULL dereference in find When find was given a NULL item and the FIND_NEXT flag the item would get dereferenced. Diffstat:
M | aps/find.c | | | 12 | +++++------- |
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/aps/find.c b/aps/find.c @@ -43,15 +43,13 @@ finddir(struct item *(*incr)(struct item *), struct item *item, struct item *end { if (flags & FIND_REVERSE) incr = REV(incr); - if (flags & FIND_NEXT) - goto next; + if (flags & FIND_NEXT && (item == NULL || (item = incr(item)) == end)) + return NULL; while (item && !multimatch(item->path, patterns, len)) { -next: - if ((item = incr(item)) == end) { - errno = ENOENT; - return NULL; - } + item = incr(item); + if (item == end) + item = NULL; } return item;