OSDN Git Service
Samuel Holland [Sun, 20 Mar 2016 18:13:21 +0000 (11:13 -0700)]
basename: fix segfault on null input; add tests
When passed an empty string, glibc's basename() returns a pointer to the
string "." in read-only memory. If an empty suffix is given, it fits
the condition of being shorter than the path, so we try to overwrite the
null byte and crash. Fix this by just ignoring empty suffixes; they
don't do anything anyway.
Elliott Hughes [Sat, 19 Mar 2016 03:12:04 +0000 (20:12 -0700)]
Add od -w.
I'm not an od user myself, but I copy & pasted an 'od' invocation from a bug
and it didn't work. Which was embarrassing because I'd just claimed that the
od user didn't need to run od on their desktop (as they had done) and could
have run it on the device instead...
Elliott Hughes [Mon, 7 Mar 2016 22:51:10 +0000 (14:51 -0800)]
toolbox prlimit is no more.
Replaced by toybox ulimit -p.
Rob Landley [Thu, 24 Mar 2016 21:20:36 +0000 (16:20 -0500)]
Debian bug 635570 did something horribly nonstandard (depending on a side
effect of "sed -e 'a\'" with no trailing line). But there's an actual user,
and it's not hard to implement, and it's not hard to implement, and there
isn't an obvious _other_ way to do it, so add the behavior and a test for it.
Fix some bad/missing comments while I was there, and add a couple TODOs.
Rob Landley [Wed, 23 Mar 2016 08:44:51 +0000 (03:44 -0500)]
Fix bzcat.test (as noted by Andy Chu), wean tests off $TOPDIR and supply $FILES
instead, move tests/blkid into tests/files/blkid.
Rob Landley [Wed, 23 Mar 2016 08:30:23 +0000 (03:30 -0500)]
The test infrastructure prints the command name now, so file.test shouldn't.
Rob Landley [Wed, 23 Mar 2016 08:27:39 +0000 (03:27 -0500)]
Minor blkid cleanup. (There was a while(ptr[-1]==' ') ptr--; that could fall
off the start of the string. I pulled on the thread...)
Rob Landley [Wed, 23 Mar 2016 08:25:37 +0000 (03:25 -0500)]
Redo build stuff in response to Andy Chu's suggestions.
Toybox single binaries are now made directly with the new name instead of
stomping toybox and getting renamed.
Unstripped files now live in generated/unstripped.
Target to run all tests is now "make tests" to avoid conflict with "make test".
.singleconfig now has .PHONY: entries for all test_$NAME targets.
Default install location changed to /usr/toybox, code.html now says how
to change it (set $PREFIX).
scripts/install.sh --uninstall works now. (And you get to keep the pieces!)
Samuel Holland [Sun, 20 Mar 2016 18:13:22 +0000 (11:13 -0700)]
blkid: Handle short/empty vfat labels; update tests
vfat labels have a fixed space allocated for them. In the case of a
shorter label, the remaining bytes are padded with spaces. A vfat
filesystem with no label (i.e. that will show up in Windows as "Local
Disk (X:)" or "Removable Disk (X:)") is stored as "NO NAME ".
Both of these changes match behavior from util-linux.
Rob Landley [Mon, 21 Mar 2016 01:39:27 +0000 (20:39 -0500)]
Posix requires "" to be false, and 00 should be false, and -0 should be false.
Fix memory leaks in regex. Simplify regex check (if we matched, subexpression
had to match). Don't exit() from a command, set exitval and return.
Elliott Hughes [Sat, 19 Mar 2016 15:56:09 +0000 (08:56 -0700)]
Make lsof 10x faster by caching /proc/net socket info.
I deliberately didn't do this first time round because for me our lsof
is already 10x faster than traditional lsof, and caching means we potentially
give less information about a socket that's created while we're running.
It turns out that traditional lsof caches anyway, so I guess nobody cares.
This also fixes a mistake where lsof used CFG_FREE instead of CFG_TOYBOX_FREE.
Rob Landley [Fri, 18 Mar 2016 19:12:53 +0000 (14:12 -0500)]
Fix last commit (had newline before first ==> name <==) and add -f tests.
Josh Gao [Wed, 16 Mar 2016 22:41:13 +0000 (15:41 -0700)]
Fix "tail -f single_file".
TT.file_no was being incorrectly calculated as 0 when tail -f was passed
a single argument.
Rob Landley [Thu, 17 Mar 2016 20:19:16 +0000 (15:19 -0500)]
expr cleanup: simplify get_str() and free returned allocations.
Andy Chu [Thu, 17 Mar 2016 19:02:55 +0000 (12:02 -0700)]
Remove 'exit' from xargs test too.
Andy Chu [Thu, 17 Mar 2016 07:06:32 +0000 (00:06 -0700)]
Fix bug where all tests aren't being run with 'make test'.
The tests/*.test files shouldn't explicitly exit, because they are
sourced in scripts/test.sh. No tests after sed were being run.
Rob Landley [Thu, 17 Mar 2016 02:55:19 +0000 (21:55 -0500)]
expr cleanup: traverse optargs with tok instead of incrementing optargs and
copying itinto a second variable. Also add error message for empty ( )
Rob Landley [Wed, 16 Mar 2016 17:33:32 +0000 (12:33 -0500)]
Move whitespace and curly brackets around, move reference URLs to top of file,
eliminate syntax_error() function (just call error_exit() directly),
eliminate advance() wrapper, pipe expected error messages in test to /dev/null
Andy Chu [Tue, 15 Mar 2016 20:52:25 +0000 (13:52 -0700)]
Fix type coercion bugs in expr.
All tests pass now; this fixes the 2 remaining failures, including a
segfault.
The structure of the code has changed a lot -- instead of having a tiny
function per operator, we have eval_op() which does common type coercion
and then evaluates the operator. I tried writing it a couple different
ways, and this was the cleanest.
The OPS table now contains the operator string, precedence level,
signature for type coercion, and operator ID.
Andy Chu [Tue, 15 Mar 2016 20:42:30 +0000 (13:42 -0700)]
Fix the operator precedence in expr.
expr now uses the precedence table specified by POSIX, implemented using
the "precedence climbing" algorithm. See the references at the top of
eval_expr().
This fixes 3 of 4 failing tests.
I also added more tests for correct behavior and for syntax errors.
This includes a new test exposing a segfault, related to type coercion.
Rob Landley [Tue, 15 Mar 2016 20:02:21 +0000 (15:02 -0500)]
Add base64.test, and Izabera pointed out that -w0 should disable wrapping.
Rob Landley [Tue, 15 Mar 2016 07:23:50 +0000 (02:23 -0500)]
Add ls -b and make ls -q work with utf8.
Rob Landley [Mon, 14 Mar 2016 01:23:41 +0000 (20:23 -0500)]
Split out _xexit() from xexit() and give sigatexit() multiple callbacks.
Rob Landley [Sun, 13 Mar 2016 22:23:11 +0000 (17:23 -0500)]
factor: use long long math (64 bit on 32 bit platforms) and handle negative
numbers even though we use unsigned math now.
Rob Landley [Sat, 12 Mar 2016 23:47:19 +0000 (17:47 -0600)]
Update scripts/single.sh and cp.c so "make mv" isn't actually building cp.
Rob Landley [Sat, 12 Mar 2016 21:56:40 +0000 (15:56 -0600)]
The xattr functions were added during the 2.5 kernel, lsm.h can #include the
header unconditionally. (This fixes the warning when CP_PRESERVE disabled.)
Andy Chu [Sun, 6 Mar 2016 17:49:50 +0000 (09:49 -0800)]
Fix segfault in sed -e 'c\'.
Found by afl-fuzz.
Rob Landley [Tue, 8 Mar 2016 19:39:23 +0000 (13:39 -0600)]
Add depends on TOYBOX_FORK for various commands that need nommu conversion.
(This should fix allyesconfig.)
Rob Landley [Mon, 7 Mar 2016 22:02:47 +0000 (16:02 -0600)]
Cleanup pass on the dirtree infrastructure, in preparation for making rm -r
handle infinite depth. Fix docs, tweak dirtree_handle_callback() semantics,
remove dirtree_start() and don't export dirtree_handle_callback(), instead
offer dirtree_flagread(). (dirtree_read() is a wrapper around dirtree_flagread
passing 0 for flags.)
Rob Landley [Mon, 7 Mar 2016 03:27:25 +0000 (21:27 -0600)]
Fix warning (toys.optflags is a long long now).
Lipi Lee [Sun, 6 Mar 2016 19:46:19 +0000 (13:46 -0600)]
wget: clean up
- shorten error messages
- replace mk_rq with sprintf
- remove struct and defines
- change unsigned int to unsigned
Rob Landley [Sun, 6 Mar 2016 19:10:19 +0000 (13:10 -0600)]
Another pass at file.c: move posix-required "executable" to front of output,
next few fields in the order the other implementation outputs, fewer commas,
fix a big where big endian executable type wasn't detected right,
and fix the filehandle leak.
Rob Landley [Fri, 4 Mar 2016 19:22:39 +0000 (13:22 -0600)]
Elliott pointed out that we output "unlimited" instead of "infinity", so
accept that as input. (And that I screwed up the test.)
Rob Landley [Thu, 3 Mar 2016 17:07:59 +0000 (11:07 -0600)]
Fix bzcat integer overflow reported by John Regehr.
Elliott Hughes [Tue, 1 Mar 2016 03:35:13 +0000 (19:35 -0800)]
Fix file for Java class files, improve script detection, and add tests.
Rob Landley [Thu, 3 Mar 2016 04:12:02 +0000 (22:12 -0600)]
More minor cleanup (inline a function, simplify name of another).
Rob Landley [Thu, 3 Mar 2016 04:10:49 +0000 (22:10 -0600)]
Minor cleanup.
Rob Landley [Thu, 3 Mar 2016 04:05:21 +0000 (22:05 -0600)]
Fix base64 so == wraps properly.
Rob Landley [Wed, 2 Mar 2016 21:20:04 +0000 (15:20 -0600)]
Factor out command name at the start of test name, have runtest.sh print it.
Rob Landley [Wed, 2 Mar 2016 21:10:24 +0000 (15:10 -0600)]
Print command name at start of each test.
Rob Landley [Wed, 2 Mar 2016 21:01:51 +0000 (15:01 -0600)]
Split lsattr/chattr tests.
Rob Landley [Wed, 2 Mar 2016 20:41:47 +0000 (14:41 -0600)]
Command name at start of each test.
Rob Landley [Wed, 2 Mar 2016 20:29:03 +0000 (14:29 -0600)]
Add fstype test.
Rob Landley [Wed, 2 Mar 2016 19:49:47 +0000 (13:49 -0600)]
Try to consistently print command name at the start of each test.
Rob Landley [Wed, 2 Mar 2016 19:46:52 +0000 (13:46 -0600)]
split pgrep/pkill tests.
Rob Landley [Wed, 2 Mar 2016 17:52:38 +0000 (11:52 -0600)]
For years the man pages have said to #include <sys/types.h> to get
major/minor/makedev, but glibc has vowed to break existing programs
(https://sourceware.org/ml/libc-alpha/2015-11/msg00253.html)
and replace it with _another_ non-standard header (not in posix or lsb),
so let's just add functions to lib/ that do the transform ourselves.
Rob Landley [Wed, 2 Mar 2016 05:50:23 +0000 (23:50 -0600)]
The last-ever release of uClibc hasn't got prlimit, so probe.
Rob Landley [Wed, 2 Mar 2016 05:41:01 +0000 (23:41 -0600)]
SYS_finit_module isn't there on Ubuntu 12.04 because it was only added to the
3.8 kernel in 2012. That's way too new to assume the build environment has
it, so #ifdef and simulate a failure if it's not there.
Rob Landley [Wed, 2 Mar 2016 05:39:27 +0000 (23:39 -0600)]
Use shell builtins instead of calling wc/awk/sed. (Fewer forks in build loop.)
Based on suggestions from Nicholas Boichat.
Rob Landley [Wed, 2 Mar 2016 03:14:55 +0000 (21:14 -0600)]
The last-ever release of uClibc didn't #define MS_RELATIME.
George Burgess IV [Thu, 25 Feb 2016 05:25:52 +0000 (21:25 -0800)]
Use the correct types for recvfrom.
The clang FORITFY implementation doesn't like pointer signedness mismatch.
"What mismatch?", you say. "The historical bug in LP32 Android that left
it with a signed socklen_t".
Elliott Hughes [Sat, 27 Feb 2016 21:27:26 +0000 (13:27 -0800)]
Fix "make help" again.
Same missing quote at end of line as last time. The new additions to
the help are very useful though.
Mike Frysinger [Mon, 29 Feb 2016 19:13:38 +0000 (13:13 -0600)]
config2help: add missing ctype.h include
This file uses isspace which is defined in the ctype.h header.
Rob Landley [Tue, 1 Mar 2016 05:30:03 +0000 (23:30 -0600)]
do_regular_file() prints output line, don't fall through to print default.
Elliott Hughes [Mon, 29 Feb 2016 18:34:07 +0000 (10:34 -0800)]
Fix trailing spaces on ps -o cmdline.
Rob Landley [Mon, 29 Feb 2016 17:40:28 +0000 (11:40 -0600)]
Fix inverted test.
Isaac Dunham [Mon, 29 Feb 2016 17:29:21 +0000 (11:29 -0600)]
pending/file: add cpio, tar, zip formats.
Rob Landley [Mon, 29 Feb 2016 17:21:43 +0000 (11:21 -0600)]
Fix a typo from last time, and Isaac Dunham's todo list:
- per POSIX, 'cannot open' must be in the 'type' string if open() fails
(both EPERM and ENOENT); we only do that if open() succeeds and fstat(fd)
fails.
- symlink detection (as per POSIX) won't work: opening them O_RDONLY
results in following the link, then we fstat() the fd.
- file 'FIFO' causes a hang; open() won't return till there's a writer.
Rob Landley [Mon, 29 Feb 2016 06:57:11 +0000 (00:57 -0600)]
Second pass at the ELF type table.
Rob Landley [Fri, 26 Feb 2016 06:22:15 +0000 (00:22 -0600)]
Switch to $! for make.sh process enumeration.
Rob Landley [Fri, 26 Feb 2016 00:10:35 +0000 (18:10 -0600)]
Fix more warnings on 32 bit builds.
Rob Landley [Fri, 26 Feb 2016 00:03:08 +0000 (18:03 -0600)]
Fix bug where mount -o leftover string didn't get passed through to kernel
for 2-argument version.
Rob Landley [Thu, 25 Feb 2016 23:49:40 +0000 (17:49 -0600)]
Typecast a printf argument because wchar_t isn't a rigidly defined size.
Rob Landley [Thu, 25 Feb 2016 23:16:32 +0000 (17:16 -0600)]
Musl needs an extra #include.
Lipi C. H. Lee [Mon, 22 Feb 2016 21:25:46 +0000 (15:25 -0600)]
implement simple 'wget' and port name can be specified in URL if default
port 80 is not used.
Rob Landley [Sun, 21 Feb 2016 20:03:21 +0000 (14:03 -0600)]
lsof cleanup
Accept multiple -p, inline filter_matches, convert misleading "char* a, b" to
"char *a, b", use readfile() to read a file, use DIRTREE_SHUTUP, don't need
{ } around a single line, don't modify command line environment space
(which changes what ps/pgrep sees).
Elliott Hughes [Fri, 19 Feb 2016 00:24:02 +0000 (16:24 -0800)]
Implement "insmod -".
Also use finit_module if available. Given that "insmod -" requires
init_module, maybe this isn't a worthwhile optimization. Given that
"insmod /actual/file.ko" is the common use case, maybe it is.
Fix a bug in readfileat where *plen would be corrupted if you didn't supply
your own buffer (because ibuf is 0 in that case, not a pointer to the start
of the allocated space).
Rob Landley [Fri, 19 Feb 2016 23:56:01 +0000 (17:56 -0600)]
Add test_COMMAND for each command, update "make help" to describe TEST_HOST
and VERBOSE=fail, and fix a quote mismatch.
Rob Landley [Fri, 19 Feb 2016 17:58:17 +0000 (11:58 -0600)]
Help text update from Isaac Dunham, tweaked slightly.
Elliott Hughes [Fri, 19 Feb 2016 05:11:07 +0000 (21:11 -0800)]
Add xxd -p and -r.
SELinux denials include hex-encoded paths in the log messages; xxd -r -p is
a convenient way to decode them.
The heuristics are a little weird to my mind, but match the documentation
and observed behavior.
Rob Landley [Fri, 19 Feb 2016 02:31:22 +0000 (20:31 -0600)]
RLIMIT_RTTIME was added to the kernel in 2008, you can't expect uClibc to have noticed yet.
Rob Landley [Thu, 18 Feb 2016 01:21:44 +0000 (19:21 -0600)]
The perl build's attempt to escape spaces and such in LD_LIBRARY_PATH is _SAD_.
It uses a sed expression that assumes you can escape - to use it as a literal
(you can't, it has to be first or last char of the range), and assumes
you have to escape delimiters in sed [] context (you don't), and/or that
non-printf escapes become the literal character (they don't, the backslash
is preserved as a literal), meaning it winds up doing "s/[\-\]//" which is
a length 1 range, which is officially undefined behavior according to posix,
and regcomp errors out.
But if we don't accept it (like other implementations do) the perl build
breaks. So collapse [A-A] into just [A].
Testcae taken from perl 5.22.0 file Makefile.SH line 8.
(While we're at it, remove an unused argument from a function.)
Tom Cherry [Thu, 18 Feb 2016 00:27:08 +0000 (16:27 -0800)]
Add support for getprop -Z
Add support for a -Z option to getprop that will either print the
SELabel of a given property if one is provided or print all properties
that have been set along with their SELabel.
Also, correct a memory leak when freeing TT.nv.
Elliott Hughes [Thu, 18 Feb 2016 00:40:17 +0000 (16:40 -0800)]
Fix remounting /system on Android.
This adds the missing "relatime" option, fixes error handling logic (mount
returns 0/-1, not an errno value, and I at least get EACCES rather than
EROFS in the case where the underlying block device is read-only; we should
also probably only try again if the ioctl actually succeeded), and adds the
missing newline in case where we go around and try again read-only.
The test case was "mount -o rw,remount /system" on Android.
Rob Landley [Wed, 17 Feb 2016 23:35:42 +0000 (17:35 -0600)]
Testfile with the 3 different types of "not utf8 output" escaped chars in it.
Rob Landley [Wed, 17 Feb 2016 20:01:19 +0000 (14:01 -0600)]
Add dynamic/static checking to file (printing dynamic linker if found).
Rob Landley [Wed, 17 Feb 2016 18:30:31 +0000 (12:30 -0600)]
Add the sed invocations to convert tabs/spaces and back, plus some tweaks.
Rob Landley [Mon, 15 Feb 2016 22:41:14 +0000 (16:41 -0600)]
Cleanup pass on file.c, and add detection of different ELF architectures.
Rob Landley [Sun, 14 Feb 2016 20:04:21 +0000 (14:04 -0600)]
Add "make list", rename make working->list_working and pending->list_pending,
and filter out commands that aren't nofork but aren't installed either
(toyflags 0, I.E. recognized aliases like "-sh" called from login).
Elliott Hughes [Sat, 13 Feb 2016 17:50:20 +0000 (09:50 -0800)]
Implement file(1).
Unlike the POSIX file(1), there's no magic file here, just hard-coded
common (non-obsolete) file formats. Personally most of my use of file(1)
is as a one-line readelf(1) summarizer, so although I assume a full POSIX
file(1) is out of scope (because just the database would likely be larger
than all the rest of toybox), a subset that only supports in-use file types
actually covers most of the use cases I encounter personally.
Also fix peek_be/peek_le.
Elliott Hughes [Fri, 12 Feb 2016 16:13:06 +0000 (08:13 -0800)]
Fix wc -c optimization.
Check the fstat(2) return value rather than read uninitialized memory if
it failed, and add a special case for files that claim to be zero-length
but aren't (as is common in /proc on Linux).
lovelycuppatea [Thu, 11 Feb 2016 21:42:28 +0000 (21:42 +0000)]
removed unread assignment in sed.c
clang scan-build flags up this line as being unread, so clearing from code.
Rob Landley [Thu, 11 Feb 2016 05:30:45 +0000 (23:30 -0600)]
Ignore .singlemake.
Rob Landley [Thu, 11 Feb 2016 05:27:55 +0000 (23:27 -0600)]
Wean scripts/install.c off toys.h so cross compiling less brittle.
Rob Landley [Thu, 11 Feb 2016 05:06:12 +0000 (23:06 -0600)]
Don't include toys.h from config2help.c (so cross-compiling from systems we
don't run on is easier), and use HELP_ instead of help_ for macro prefixes
to avoid name collisions (such as help_exit() the function).
Tom Marshall [Wed, 10 Feb 2016 05:01:41 +0000 (00:01 -0500)]
toybox: tar: Fix support for long names
Pathnames may be longer than the name field in the header, so use
strncpy() instead of xstrncpy() to avoid bailing out.
Also add unit tests to ensure proper handling of short and long
pathnames.
Change-Id: Id025891993746889564b479e5185cf9721b54a55
Tom Marshall [Tue, 9 Feb 2016 23:32:40 +0000 (18:32 -0500)]
toybox: tar: Fix tar tests
Don't rely on ordering of readdir for tests.
Change-Id: Ice24bb64ce453acb0006e3746677d619db933ab1
Patrick Ohly [Tue, 9 Feb 2016 15:43:35 +0000 (16:43 +0100)]
main.c: fix non-root usage when installed suid root
When toybox is installed suid root and invoked by a non-root user for
commands which do not require root privileges, it drops the root
privileges during initialization.
However, since commit
afba5b8efd the result check of setuid() was
inverted such that it aborted on success, making toybox unusuable for
non-root users.
Signed-off-by: Patrick Ohly <patrick.ohly@intel.com>
Rob Landley [Thu, 11 Feb 2016 04:31:59 +0000 (22:31 -0600)]
Add seq -w, suggested by izabera.
Rob Landley [Thu, 11 Feb 2016 03:05:22 +0000 (21:05 -0600)]
Factor out strnstr() since posix hasn't got it, and add a config option for
the deeply sad passwd heuristics that don't even check numbers and punctuation.
izabera [Sat, 6 Feb 2016 14:41:59 +0000 (15:41 +0100)]
make wc -c faster
izabera [Sat, 6 Feb 2016 14:25:35 +0000 (15:25 +0100)]
use unsigned long with factor
Rob Landley [Wed, 10 Feb 2016 22:23:31 +0000 (16:23 -0600)]
Although printf("%.*s", INT_MAX, s) works fine on ubuntu 12.04, it broke since.
izabera [Wed, 10 Feb 2016 00:26:01 +0000 (01:26 +0100)]
implement env -u
Rob Landley [Tue, 9 Feb 2016 23:23:31 +0000 (17:23 -0600)]
Add ulimit.
This isn't a shell builtin, it uses prlimit to target any pid (without -P
it defaults to $PPID, so acts like historical ulimit by default).
Rob Landley [Tue, 9 Feb 2016 23:06:12 +0000 (17:06 -0600)]
Fix xpipe. (thinko.)
Rob Landley [Mon, 8 Feb 2016 21:24:33 +0000 (15:24 -0600)]
Add xpipe() to lib.
Rob Landley [Mon, 8 Feb 2016 01:09:39 +0000 (19:09 -0600)]
Dependencies for "make COMMAND"
Rob Landley [Mon, 8 Feb 2016 00:15:53 +0000 (18:15 -0600)]
Add "make ls" and friends targets, with "make working" and "make pending" lists.
Rob Landley [Sun, 7 Feb 2016 18:27:40 +0000 (12:27 -0600)]
Add a warning when building commands out of pending.