Two patches attached (are github pull requests more convenient for you?)
From ef19fb43d16432cfce54ee7fe940f3fa0a87ae8a Mon Sep 17 00:00:00 2001
From: Josh Gao <[email protected]>
Date: Thu, 4 Feb 2016 10:43:20 -0800
Subject: [PATCH 1/2] Fix null dereference prior to check.
---
toys/posix/find.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/toys/posix/find.c b/toys/posix/find.c
index febe688..ac5eaac 100644
--- a/toys/posix/find.c
+++ b/toys/posix/find.c
@@ -315,7 +315,11 @@ static int do_find(struct dirtree *new)
|| !strcmp(s, "path") || !strcmp(s, "ipath"))
{
int i = (*s == 'i');
- char *arg = ss[1], *path = 0, *name = new->name;
+ char *arg = ss[1], *path = 0, *name = 0;
+
+ if (new) {
+ name = new->name;
+ }
// Handle path expansion and case flattening
if (new && s[i] == 'p') name = path = dirtree_path(new, 0);
--
2.7.0.rc3.207.g0ac5344
From 59a7187d0eb2db6fd5cb68854d3195239cb0daad Mon Sep 17 00:00:00 2001
From: Josh Gao <[email protected]>
Date: Thu, 4 Feb 2016 10:49:52 -0800
Subject: [PATCH 2/2] Fix segfault when `find -iname` gets no argument.
---
tests/find.test | 16 ++++++++++++++++
toys/posix/find.c | 3 ++-
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/tests/find.test b/tests/find.test
index 4e987b6..710684e 100755
--- a/tests/find.test
+++ b/tests/find.test
@@ -74,4 +74,20 @@ testing "find unterminated -exec {}" \
testing "find -exec {} +" \
"find dir -type f -exec ls {} +" "dir/file\n" "" ""
+# `find . -iname` was segfaulting
+testing "find -name file" \
+ "find dir -name file" "dir/file\n" "" ""
+testing "find -name FILE" \
+ "find dir -name FILE" "" "" ""
+
+testing "find -iname file" \
+ "find dir -iname FILE" "dir/file\n" "" ""
+testing "find -iname FILE" \
+ "find dir -iname FILE" "dir/file\n" "" ""
+
+
+testing "find -name (no arguments)" \
+ "find dir -name 2>&1" "find: '-name' needs 1 arg\n" "" ""
+testing "find -iname (no arguments)" \
+ "find dir -iname 2>&1" "find: '-iname' needs 1 arg\n" "" ""
rm -rf dir
diff --git a/toys/posix/find.c b/toys/posix/find.c
index ac5eaac..d3ee7f5 100644
--- a/toys/posix/find.c
+++ b/toys/posix/find.c
@@ -325,7 +325,8 @@ static int do_find(struct dirtree *new)
if (new && s[i] == 'p') name = path = dirtree_path(new, 0);
if (i) {
if (check || !new) {
- name = strlower(new ? name : arg);
+ char *temp = new ? name : arg;
+ name = temp ? strlower(temp) : 0;
if (!new) {
dlist_add(&TT.argdata, name);
free(path);
--
2.7.0.rc3.207.g0ac5344
_______________________________________________
Toybox mailing list
[email protected]
http://lists.landley.net/listinfo.cgi/toybox-landley.net