aboutsummaryrefslogtreecommitdiff
path: root/toys/posix/find.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2014-09-08 08:26:02 -0500
committerRob Landley <rob@landley.net>2014-09-08 08:26:02 -0500
commit6634e46216410161f0f56dc54b16da2de6a8f2b3 (patch)
treed210d6d524e397bca88dc009e5d506100545034e /toys/posix/find.c
parent9b4ea9cf9934d5639a7d1a9b50b90b8d5569ba7e (diff)
downloadtoybox-6634e46216410161f0f56dc54b16da2de6a8f2b3.tar.gz
Add error test and fix memory leak, reported by Ashwini Sharma.
Diffstat (limited to 'toys/posix/find.c')
-rw-r--r--toys/posix/find.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/toys/posix/find.c b/toys/posix/find.c
index a5a95d96..b74cb88e 100644
--- a/toys/posix/find.c
+++ b/toys/posix/find.c
@@ -315,11 +315,11 @@ static int do_find(struct dirtree *new)
}
} else if (!strcmp(s, "type")) {
if (check) {
- char c = stridx("bcdlpfs", *ss[1]);
int types[] = {S_IFBLK, S_IFCHR, S_IFDIR, S_IFLNK, S_IFIFO,
- S_IFREG, S_IFSOCK};
+ S_IFREG, S_IFSOCK}, i = stridx("bcdlpfs", *ss[1]);
- if ((new->st.st_mode & S_IFMT) != types[c]) test = 0;
+ if (i<0) error_exit("bad -type '%c'", *ss[1]);
+ if ((new->st.st_mode & S_IFMT) != types[i]) test = 0;
}
} else if (!strcmp(s, "atime")) {
@@ -447,7 +447,12 @@ static int do_find(struct dirtree *new)
if (*s == 'o') {
char *prompt = xmprintf("[%s] %s", ss1, name);
- if(!(test = yesno(prompt, 0))) goto cont;
+ test = yesno(prompt, 0);
+ free(prompt);
+ if (!test) {
+ free(name);
+ goto cont;
+ }
}
// Add next name to list (global list without -dir, local with)