From 6b617d8073600c9f2518c87addc49a89a27d887e Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Tue, 30 Jul 2019 13:09:05 -0500 Subject: Fix signed typecast bug. We use (char *)1 and (char *)2 to indicate errors (they can never be valid pointers because both malloc() and mmap() return aligned memory and those align down to NULL, plus Linux maps 4k at the bottom to catch null dereferences anyway), and then typecast it to long (trusting in LP64) to do an integer <=2 comparison... except that needs to be UNSIGNED long or else pointers in the top half of the virtual memory space become negative and the <=2 false positives them as errors. (Oops.) --- toys/posix/xargs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toys/posix') diff --git a/toys/posix/xargs.c b/toys/posix/xargs.c index 12af9125..39d78ef5 100644 --- a/toys/posix/xargs.c +++ b/toys/posix/xargs.c @@ -161,7 +161,7 @@ void xargs_main(void) data = handle_entries(data, NULL); if (!data) continue; if (data == (char *)2) done++; - if ((long)data <= 2) data = 0; + if ((unsigned long)data <= 2) data = 0; else data = xstrdup(data); break; -- cgit v1.2.3