OSDN Git Service

Revert "toybox: find: Fix segfault when using -iname/-ipath with -exec"
authorSteve Kondik <steve@cyngn.com>
Sun, 22 May 2016 23:59:11 +0000 (16:59 -0700)
committerSteve Kondik <steve@cyngn.com>
Sun, 22 May 2016 23:59:24 +0000 (16:59 -0700)
 * Tom's patch was upstreamed.

This reverts commit d5de71798489bf4cc2c1e89c0b0f2768a3b2ae47.

Change-Id: I920566d757cf9748fbb472ab5cd44318876a2f8c

toys/posix/find.c

index 4c7e864..303aada 100644 (file)
@@ -315,21 +315,22 @@ static int do_find(struct dirtree *new)
         || !strcmp(s, "path") || !strcmp(s, "ipath"))
       {
         int i = (*s == 'i');
-
-        if (i && !new) {
-            char *p;
-            for (p = ss[1]; *p; ++p) {
-                *p = tolower(*p);
-            }
+        char *arg = ss[1], *path = 0, *name = new ? new->name : arg;
+
+        // Handle path expansion and case flattening
+        if (new && s[i] == 'p') name = path = dirtree_path(new, 0);
+        if (i) {
+          if (check || !new) {
+            if (name) name = strlower(name);
+            if (!new) {
+              dlist_add(&TT.argdata, name);
+              free(path);
+            } else arg = ((struct double_list *)llist_pop(&argdata))->data;
+          }
         }
-        if (check) {
-          char *path = 0, *name = new->name;
-
-          // Handle path expansion and case flattening
-          if (s[i] == 'p') name = path = dirtree_path(new, 0);
-          if (i) name = strlower(name);
 
-          test = !fnmatch(ss[1], name, FNM_PATHNAME*(s[i] == 'p'));
+        if (check) {
+          test = !fnmatch(arg, name, FNM_PATHNAME*(s[i] == 'p'));
           free(path);
           if (i) free(name);
         }