Re: [Toybox] [PATCH] Fix segfault in `find . -iname`

2016-02-05 Thread Rob Landley
Sorry, I was looking at the bunzip segfault John Regher emailed me.

Applied, one patch slightly tweaked, still passes the tests Josh added
but let me know if I screwed something up.

Thanks,

Rob

On 02/05/2016 12:19 PM, enh wrote:
> is this likely to go in today? (trying to decide whether to do my
> weekly merge now to AOSP or wait until this evening.)
> 
> On Thu, Feb 4, 2016 at 4:58 PM, Rob Landley  wrote:
>> On 02/04/2016 12:54 PM, Josh Gao wrote:
>>> Two patches attached (are github pull requests more convenient for you?)
>>
>> I prefer patches or "git format-patch". If I like it I can apply it, if
>> I have comments I can reply to it.
>>
>> (Github pull requests I wget the git format-patch and "git am" it
>> locally, but then don't have an obvious channel to reply.)
>>
>> Thanks,
>>
>> Rob
>> ___
>> Toybox mailing list
>> Toybox@lists.landley.net
>> http://lists.landley.net/listinfo.cgi/toybox-landley.net
> 
> 
> 
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] [PATCH] Fix segfault in `find . -iname`

2016-02-05 Thread enh
is this likely to go in today? (trying to decide whether to do my
weekly merge now to AOSP or wait until this evening.)

On Thu, Feb 4, 2016 at 4:58 PM, Rob Landley  wrote:
> On 02/04/2016 12:54 PM, Josh Gao wrote:
>> Two patches attached (are github pull requests more convenient for you?)
>
> I prefer patches or "git format-patch". If I like it I can apply it, if
> I have comments I can reply to it.
>
> (Github pull requests I wget the git format-patch and "git am" it
> locally, but then don't have an obvious channel to reply.)
>
> Thanks,
>
> Rob
> ___
> Toybox mailing list
> Toybox@lists.landley.net
> http://lists.landley.net/listinfo.cgi/toybox-landley.net



-- 
Elliott Hughes - http://who/enh - http://jessies.org/~enh/
Android native code/tools questions? Mail me/drop by/add me as a reviewer.
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] [PATCH] Fix segfault in `find . -iname`

2016-02-04 Thread Rob Landley
On 02/04/2016 12:54 PM, Josh Gao wrote:
> Two patches attached (are github pull requests more convenient for you?)

I prefer patches or "git format-patch". If I like it I can apply it, if
I have comments I can reply to it.

(Github pull requests I wget the git format-patch and "git am" it
locally, but then don't have an obvious channel to reply.)

Thanks,

Rob
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


[Toybox] [PATCH] Fix segfault in `find . -iname`

2016-02-04 Thread Josh Gao
Two patches attached (are github pull requests more convenient for you?)
From ef19fb43d16432cfce54ee7fe940f3fa0a87ae8a Mon Sep 17 00:00:00 2001
From: Josh Gao 
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 
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
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net