If we have a 15-byte name, we don't know whether comm actually matches
or is a truncated form of a longer name that has a common prefix.

For example, with "this-is-a-very-long-name-that-is-too-long", we shouldn't
match "this-is-a-very-" (but the old code would).

Bug: http://b/73123244
---
 lib/lib.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
From 6b4d00aec3fa6695b5ca916f37e2e37ab330dffc Mon Sep 17 00:00:00 2001
From: Elliott Hughes <e...@google.com>
Date: Mon, 25 Dec 2017 21:24:57 -0800
Subject: [PATCH] Fix xargs -0 with -n.

Also make -0 and -E mutually exclusive (rather than just ignore -E
with -0).

Bug: https://github.com/landley/toybox/issues/78
---
 tests/xargs.test   | 3 +++
 toys/posix/xargs.c | 5 ++---
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/tests/xargs.test b/tests/xargs.test
index 966bc5d..407817c 100755
--- a/tests/xargs.test
+++ b/tests/xargs.test
@@ -24,6 +24,9 @@ testing "command -opt" "xargs -n2 ls -1" "one\ntwo\nthree\n" "" \
 	"one two three"
 rm one two three
 
+testing "-0 -n1" "printf 'a\0b\0c\0d\0e\0f' | xargs -0 -n1 echo _" "_ a\n_ b\n_ c\n_ d\n_ e\n_ f\n" "" ""
+testing "-0 -n2" "printf 'a\0b\0c\0d\0e\0f' | xargs -0 -n2 echo _" "_ a b\n_ c d\n_ e f\n" "" ""
+
 #testing "-n exact match"
 #testing "-s exact match"
 #testing "-s 0"
diff --git a/toys/posix/xargs.c b/toys/posix/xargs.c
index e7dd10b..cac143c 100644
--- a/toys/posix/xargs.c
+++ b/toys/posix/xargs.c
@@ -6,7 +6,7 @@
  *
  * TODO: Rich's whitespace objection, env size isn't fixed anymore.
 
-USE_XARGS(NEWTOY(xargs, "^I:E:L#ptxrn#<1s#0", TOYFLAG_USR|TOYFLAG_BIN))
+USE_XARGS(NEWTOY(xargs, "^I:E:L#ptxrn#<1s#0[!0E]", TOYFLAG_USR|TOYFLAG_BIN))
 
 config XARGS
   bool "xargs"
@@ -99,8 +99,7 @@ static char *handle_entries(char *data, char **entry)
   } else {
     TT.bytes += sizeof(char *)+strlen(data)+1;
     if (TT.max_bytes && TT.bytes >= TT.max_bytes) return data;
-    if (TT.max_entries && TT.entries >= TT.max_entries)
-      return (char *)1;
+    if (TT.max_entries && TT.entries >= TT.max_entries) return data;
     if (entry) entry[TT.entries] = data;
     TT.entries++;
   }
-- 
2.15.1.620.gb9897f4670-goog

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

Reply via email to