From 0cc9d996ed3fe49b34fdf0943523e880203e5be5 Mon Sep 17 00:00:00 2001 From: Denys Nykula Date: Fri, 11 Oct 2019 19:09:15 +0300 Subject: Fix argless find segfault. Inline array becomes garbage outside the if. --- tests/find.test | 1 + toys/posix/find.c | 8 ++------ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/tests/find.test b/tests/find.test index 9129a605..afe7fd2e 100755 --- a/tests/find.test +++ b/tests/find.test @@ -52,6 +52,7 @@ testing "-print -o -print" \ # Testing previous failures +testing " " "cd perm; find" ".\n./all-read-only\n" "" "" testing "-type f -user -exec" \ "find dir -type f -user $USER -exec ls {} \\;" "dir/file\n" "" "" testing "-type l -newer -exec" \ diff --git a/toys/posix/find.c b/toys/posix/find.c index 98f18eec..433ea5bd 100644 --- a/toys/posix/find.c +++ b/toys/posix/find.c @@ -681,7 +681,7 @@ error: void find_main(void) { int i, len; - char **ss = toys.optargs; + char **ss = toys.optargs, **dotifnopaths = (char *[]){"."}; TT.topdir = -1; TT.max_bytes = sysconf(_SC_ARG_MAX) - environ_bytes(); @@ -691,11 +691,7 @@ void find_main(void) if (strchr("-!(", *toys.optargs[len])) break; TT.filter = toys.optargs+len; - // use "." if no paths - if (!len) { - ss = (char *[]){"."}; - len = 1; - } + if (!len) ss = dotifnopaths, len = 1; // first pass argument parsing, verify args match up, handle "evaluate once" TT.now = time(0); -- cgit v1.2.3