Commit Graph

584 Commits

Author SHA1 Message Date
Denys Vlasenko
a77f3ecf68 grep: for -L, exitcode 0 means files *without* matches were found, closes 13151
This is a recent change in GNU grep as well (after 3.1)

function                                             old     new   delta
grep_file                                           1215    1228     +13

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-08-15 00:39:30 +02:00
Denys Vlasenko
7c443d110d randomconfig fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-06-24 00:27:37 +02:00
Denys Vlasenko
5fa5c4bde8 randomconfig fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-06-23 21:28:19 +02:00
Denys Vlasenko
002be6e821 sysctl: do report EACCES errors on write
function                                             old     new   delta
sysctl_act_recursive                                 165     179     +14
sysctl_act_on_setting                                467     471      +4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 18/0)               Total: 18 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-06-09 15:58:32 +02:00
Mark Edgar
b2ab920716 unexpand: correct behavior for --first-only --tabs=4
Prior to the patch, both -f and --first-only are in all cases either
no-op or ignored.
Without --tabs, --first-only is the default so specifying it is a no-op.
With --tabs, --all is implied, and --first-only is intended to reset this.

function                                             old     new   delta
expand_main                                          690     694      +4

Signed-off-by: Mark Edgar <medgar123@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-06-09 15:40:49 +02:00
Denys Vlasenko
6f7a009649 awk: disallow "str"++, closes bug 12981
function                                             old     new   delta
parse_expr                                           887     896      +9

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-06-09 01:33:54 +02:00
Sören Tempel
42a8984abc grep: add proper support for pattern_list
From POSIX.1-2008:

	The pattern_list's value shall consist of one or more patterns
	separated by <newline> characters;

As such, given patterns need to be split at newline characters. Without
doing so, busybox grep will interpret the newline as part of the pattern
which is not in accordance with POSIX.

See also: https://bugs.busybox.net/show_bug.cgi?id=12721

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-04-30 00:20:18 +02:00
Gray Wolf
c3295d233b grep: Fix -f FILE when FILE is empty and -x provided
Grep currently special-cased empty pattern file to be the same as
pattern file with one empty line (empty pattern). That does mirror how
GNU grep behaves, except when -x is provided. In that case .* pattern
needs to be used instead.

Signed-off-by: Gray Wolf <wolf@wolfsden.cz>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-04-29 16:01:42 +02:00
Ron Yorston
1c462d47a0 xargs: restore correct behaviour of -n option
Since commit 1ff7002b1 (xargs: fix handling of quoted arguments, closes
11441) the -n option hasn't worked properly:

   $ echo 1 2 3 | xargs -n 1 echo
   1
   2

   3

   $

Because state is now remembered between calls to process_stdin() it's
necessary to update the state before any premature return.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-04-29 15:53:51 +02:00
Denys Vlasenko
bd8b05ba1b awk: fix more "length" cases, closes 12486
function                                             old     new   delta
next_token                                           808     831     +23

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-02 23:28:55 +01:00
Ron Yorston
1ff7002b1d xargs: fix handling of quoted arguments, closes 11441
As reported in bug 11441 when presented with a large number of quoted
arguments xargs can return 'argument line too long':

   seq 10000 29999 | sed -e 's/^/"/' -e 's/$/"/' | busybox xargs echo

This happens because the variant of process_stdin() which handles quoted
arguments doesn't preserve state between calls.  If the allowed number
of characters is exceeded part way through a quoted argument the next
call to process_stdin() incorrectly treats the terminating quote as a
starting quote, thus quoting all of the argument separators.

function                                             old     new   delta
process_stdin                                        274     303     +29
xargs_main                                           731     745     +14
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 43/0)               Total: 43 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-01-29 14:39:13 +01:00
Denys Vlasenko
008413754b bc: fix comparison bug, closes 12336
function                                             old     new   delta
bc_num_cmp                                           249     259     +10

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-11-23 17:25:21 +01:00
Brian Foley
10509a70ee dc: Parse error & fix out of bounds read in xc_program_printString
function                                             old     new   delta
xc_program_print                                     712     735     +23

Signed-off-by: Brian Foley <bpfoley@google.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-09-05 10:53:21 +02:00
Brian Foley
b64470be17 dc: Fix segfault when executing strings generated using asciify
function                                             old     new   delta
zxc_vm_process                                      6884    6891      +7

Signed-off-by: Brian Foley <bpfoley@google.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-09-05 10:50:13 +02:00
Brian Foley
7454879a1d dc: execute shouldn't pop if stack head is not a string
This matches the behaviour of both GNU dc (as specified in
its man page), and BSD dc (where stack_popstring() pops
only if the head is a string.)

Add a couple of tests to verify this behavior.

function                                             old     new   delta
zxc_vm_process                                      6882    6884      +2

Signed-off-by: Brian Foley <bpfoley@google.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-09-05 10:46:22 +02:00
Denys Vlasenko
92549250f3 expand,unexpand: drop broken test, add FIXME comment
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-06-08 13:04:44 +02:00
Denys Vlasenko
22cc92833f awk: fix testsuite
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-06-08 13:00:46 +02:00
Denys Vlasenko
b2c123d484 testsuite: fix bunzip2.tests expectations
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-05-26 13:51:41 +02:00
Denys Vlasenko
0545bfa841 sed: fix /regex/,+N match triggering only once, closes 11871
function                                             old     new   delta
process_files                                       2235    2246     +11

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-05-13 16:30:39 +02:00
Chen Qi
32c8ce4def dc.tests: fix two test case to also depend on DC_BIG
Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-04-19 12:30:11 +02:00
Ari Sundholm
9a9c6e39ba grep: fix -x -v with certain pattern orders
We found out that busybox -x -v is a bit broken:

ari@ari-thinkpad:~/busybox$ echo '  aa bb cc' | ./busybox grep -x -e 'aa.*' -e '.*bb.*'
  aa bb cc
ari@ari-thinkpad:~/busybox$ echo '  aa bb cc' | ./busybox grep -x -v -e 'aa.*' -e '.*bb.*'
ari@ari-thinkpad:~/busybox$ echo '  aa bb cc' | ./busybox grep -x -e '.*aa.*' -e 'bb.*'
  aa bb cc
ari@ari-thinkpad:~/busybox$ echo '  aa bb cc' | ./busybox grep -x -v -e '.*aa.*' -e 'bb.*'
  aa bb cc

Last one is wrong.

This patch fixes the issue by making sure that the variable 'found'
never makes a transition from 1 to 0, as this would mean that
grep previously found a match on this input line.

Signed-off-by: Ari Sundholm <ari@tuxera.com>
Signed-off-by: Niko Vähäsarja <niko@tuxera.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-01-29 14:42:57 +01:00
Denys Vlasenko
53799506ac bc: implement pass-by-reference code from upstream
function                                             old     new   delta
zxc_program_popResultAndCopyToVar                    298     493    +195
bc_vec_pushIndex                                       -      75     +75
zxc_vm_process                                       859     928     +69
xc_program_dereference                                 -      66     +66
bc_vec_npush                                           -      65     +65
zbc_num_s                                            239     249     +10
zxc_program_num                                     1024    1032      +8
zbc_num_divmod                                       150     156      +6
xc_program_search                                    143     146      +3
zxc_program_assign                                   392     389      -3
zdc_program_execStr                                  520     517      -3
xc_program_pushVar                                   198     195      -3
zxc_program_exec                                    4101    4092      -9
zbc_program_call                                     318     308     -10
zbc_func_insert                                      120     104     -16
zbc_parse_stmt_possibly_auto                        1460    1439     -21
bc_vec_push                                           53      12     -41
xc_parse_pushIndex                                    61      18     -43
------------------------------------------------------------------------------
(add/remove: 3/0 grow/shrink: 6/9 up/down: 497/-149)          Total: 348 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-01-25 16:22:15 +01:00
Brian Foley
1c42c18e96 awk: Fix overly permissive func arg list parsing
It allows things like 'func f(a b)' and 'func f(a,)' which GNU awk forbids.

function                                             old     new   delta
parse_program                                        327     367     +40
chain_expr                                            40      67     +27
parse_expr                                           891     915     +24
EMSG_TOO_FEW_ARGS                                     30      18     -12
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/1 up/down: 91/-12)             Total: 79 bytes

Signed-off-by: Brian Foley <bpfoley@google.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-01-21 12:59:19 +01:00
Brian Foley
08a514c097 awk: Syntax error if delete isn't given an arg.
Unlike exit and return, delete strictly requires an arg, and derefs a
null pointer if executed without one.

Signed-off-by: Brian Foley <bpfoley@google.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-01-21 12:55:49 +01:00
Brian Foley
dac15a10ac awk: Guard pointer chasing when parsing ternary expressions.
Avoids an uninit pointer deref for some malformed ternary exprs.

Add a test that would crash in busybox before this fix.

Signed-off-by: Brian Foley <bpfoley@google.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-01-21 12:55:49 +01:00
Denys Vlasenko
77524a311a start-stop-daemon: fix "both -x and -a" case: -a does override argv[0]
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-01-14 15:00:49 +01:00
Denys Vlasenko
088fec36fe start-stop-daemon: create pidfile before parent exits, closes 8596
This removes DAEMON_DOUBLE_FORK flag from bb_daemonize_or_rexec(),
as SSD was the only user.

Also includes fix for -S: now works without -a and -x,
does not print pids
(compat with "start-stop-daemon (OpenRC) 0.34.11 (Gentoo Linux)").

function                                             old     new   delta
start_stop_daemon_main                              1018    1084     +66
add_interface                                         99     103      +4
fail_hunk                                            139     136      -3
bb_daemonize_or_rexec                                205     183     -22
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/2 up/down: 70/-25)             Total: 45 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-01-14 14:47:21 +01:00
Denys Vlasenko
54f5c1d600 bc: support void functions (GNU compat)
function                                             old     new   delta
xc_program_print                                       -     689    +689
zxc_vm_process                                       814     869     +55
zxc_program_exec                                    4098    4116     +18
zxc_program_assign                                   385     392      +7
bc_result_free                                        43      46      +3
zxc_program_binOpPrep                                243     245      +2
zdc_program_execStr                                  518     520      +2
zxc_program_print                                    683       -    -683
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 6/0 up/down: 776/-683)           Total: 93 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-01-04 13:58:46 +01:00
Denys Vlasenko
1db367a8e6 dc: fit returning of string
function                                             old     new   delta
zxc_program_exec                                    4087    4098     +11

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-01-04 06:18:00 +01:00
Denys Vlasenko
6842c6062a dc: fix '?'
function                                             old     new   delta
zdc_parse_expr                                       470     479      +9
zxc_vm_process                                       839     814     -25
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 9/-25)             Total: -16 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-01-04 05:41:47 +01:00
Denys Vlasenko
96b5ec10fb bc: fix "...; return}" to work, disallow "return ()"
function                                             old     new   delta
zbc_parse_expr                                        24    1865   +1841
zbc_parse_stmt_possibly_auto                        1425    1413     -12
bc_parse_expr_empty_ok                              1843       -   -1843
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/1 up/down: 1841/-1855)        Total: -14 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-01-03 23:34:36 +01:00
Denys Vlasenko
cb7c955aeb bc: generate large bc tests on the fly, -5 mbytes in the git tree
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-01-02 14:00:20 +01:00
Denys Vlasenko
266bec8ba7 bc: speed up string printing, fix print ""
function                                             old     new   delta
static.esc                                             -       9      +9
zxc_program_print                                    681     683      +2
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/0 up/down: 11/0)               Total: 11 bytes
   text	   data	    bss	    dec	    hex	filename
 979144	    485	   7296	 986925	  f0f2d	busybox_old
 979062	    485	   7296	 986843	  f0edb	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-01-02 05:03:53 +01:00
Denys Vlasenko
2231468a2f bc: upstream fixes
function                                             old     new   delta
bc_parse_expr_empty_ok                              1764    1843     +79
bc_error_at                                            -      62     +62
bc_parse_inst_isLeaf                                   -      30     +30
zbc_func_insert                                      100     120     +20
bc_error_bad_function_definition                       -      10     +10
bc_error_bad_assignment                                -      10     +10
zxc_lex_next                                        1608    1614      +6
ok_in_expr                                            30       -     -30
zxc_vm_process                                       874     839     -35
------------------------------------------------------------------------------
(add/remove: 4/1 grow/shrink: 3/1 up/down: 217/-65)           Total: 152 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-01-01 21:50:14 +01:00
Denys Vlasenko
680ccd3573 bc: support ibase up to 36 (GNU compat)
function                                             old     new   delta
zxc_program_num                                      995    1018     +23

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-31 19:42:13 +01:00
Denys Vlasenko
d5b0fa6abf bc: more fixes for unusual input bases
function                                             old     new   delta
zxc_program_num                                      990    1020     +30
zxc_lex_number                                       172     202     +30
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 60/0)               Total: 60 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-29 03:08:12 +01:00
Denys Vlasenko
e16a5223d2 bc: fix handling of "digits" above 9
function                                             old     new   delta
zxc_lex_next                                        1573    1608     +35
xc_parse_pushIndex                                    58      56      -2
xc_program_index                                      71      63      -8
zxc_program_num                                     1022     990     -32
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/3 up/down: 35/-42)             Total: -7 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-29 02:24:19 +01:00
Denys Vlasenko
1476760600 bc: rename config options
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-28 13:32:04 +01:00
Denys Vlasenko
7d32e25bf3 bc: prepare for char-by-char input handling
function                                             old     new   delta
peek_inbuf                                             -     292    +292
parse_lex_by_checking_eq_sign                          -      26     +26
eat_inbuf                                              -      22     +22
zbc_vm_execute_FILE                                   52      61      +9
bc_lex_lineComment                                    29      30      +1
zbc_lex_number                                       174     172      -2
bc_vm_run                                            104      99      -5
zbc_num_divmod                                       156     150      -6
bc_lex_file                                           24       -     -24
bc_lex_assign                                         26       -     -26
zbc_lex_next                                        1982    1587    -395
------------------------------------------------------------------------------
(add/remove: 3/2 grow/shrink: 2/4 up/down: 350/-458)         Total: -108 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-26 18:32:43 +01:00
Denys Vlasenko
94576d2b97 bc: fix interactive handling of comments in strings and quotes in comments
function                                             old     new   delta
zbc_lex_next                                        1965    1979     +14

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-25 23:45:57 +01:00
Denys Vlasenko
8fac1c7740 dc: add two tests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-25 20:50:41 +01:00
Denys Vlasenko
5fa74b9efc bc: allow {break} and {continue} (allow RBRACE to terminate them)
function                                             old     new   delta
zbc_parse_stmt_possibly_auto                        1599    1560     -39

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-25 17:07:51 +01:00
Denys Vlasenko
badf683b0a dc: unbreak interactive mode - was trying to get next tokens instead of executing
function                                             old     new   delta
zbc_program_read                                       -     268    +268
zdc_program_printStream                                -     146    +146
zbc_program_exec                                    4046    4182    +136
zdc_program_execStr                                  472     512     +40
zdc_parse_exprs_until_eof                              -      26     +26
zbc_vm_process                                       740     765     +25
zbc_lex_next                                        2225    2240     +15
zdc_parse_expr                                       569     535     -34
zbc_program_pushArray                                147       -    -147
zdc_program_asciify                                  370       -    -370
------------------------------------------------------------------------------
(add/remove: 3/2 grow/shrink: 4/1 up/down: 656/-551)          Total: 105 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-22 18:10:50 +01:00
Denys Vlasenko
8c1e723596 bc: unbreak read(), remove checks for nested read()
function                                             old     new   delta
zbc_parse_pushSTR                                      -      65     +65
common_parse_expr                                      -      32     +32
bc_error_nested_read_call                             10       -     -10
bc_parse_expr_empty_ok                              1977    1963     -14
zdc_parse_expr                                       635     615     -20
zcommon_parse_expr                                    32       -     -32
zbc_program_exec                                    4064    4023     -41
bc_parse_pushSTR                                      65       -     -65
------------------------------------------------------------------------------
(add/remove: 2/3 grow/shrink: 0/3 up/down: 97/-182)           Total: -85 bytes
   text	   data	    bss	    dec	    hex	filename
 981661	    485	   7296	 989442	  f1902	busybox_old
 981540	    485	   7296	 989321	  f1889	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-22 01:34:10 +01:00
Denys Vlasenko
19eee8ed7c bc: fix for() to not leave data on stack
function                                             old     new   delta
zbc_parse_stmt_possibly_auto                        1665    1697     +32
zbc_vm_process                                       672     701     +29
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 61/0)               Total: 61 bytes
   text	   data	    bss	    dec	    hex	filename
 981656	    485	   7296	 989437	  f18fd	busybox_old
 981748	    485	   7296	 989529	  f1959	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-21 20:29:34 +01:00
Denys Vlasenko
52caa007e3 bc: for(;;) fix from upstream
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-21 00:35:22 +01:00
Denys Vlasenko
5acd14ba5b bc: fix keyword matching to not think "ifz" is the "if" keyword
function                                             old     new   delta
zbc_lex_next                                        2224    2225      +1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-20 16:48:50 +01:00
Denys Vlasenko
55f3cab7e9 bc: fix "echo -n '#foo' | bc" not eating last 'o'
function                                             old     new   delta
zdc_parse_expr                                       656     653      -3
bc_lex_lineComment                                    39      36      -3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-6)               Total: -6 bytes
   text	   data	    bss	    dec	    hex	filename
 981424	    485	   7296	 989205	  f1815	busybox_old
 981418	    485	   7296	 989199	  f180f	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-18 14:39:33 +01:00
Denys Vlasenko
4b72aebe80 bc: remove "error after expression parsing" check
It is misplaced: caller knows better what can or cannot follow the expression.
Sometimes even caller's caller: "if (1) return a+b else..." -
parser of "return" does not know that "else" after it is valid,
parser of stmt does not know it either, - only parser of
"if" knows it!

The removed code balked on e.g. "{ print 1 }" statement.

This does not break any valid programs, but starts accepting some
invalid ones, e.g. "print 1 print 2" would work.

function                                             old     new   delta
zcommon_parse_expr                                    40      32      -8
zbc_parse_name                                       509     494     -15
zbc_parse_stmt_possibly_auto                        1678    1638     -40
bc_parse_expr_empty_ok                              2025    1977     -48
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/4 up/down: 0/-111)           Total: -111 bytes
   text	   data	    bss	    dec	    hex	filename
 981599	    485	   7296	 989380	  f18c4	busybox_old
 981488	    485	   7296	 989269	  f1855	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-17 17:00:29 +01:00
Denys Vlasenko
266aa00012 bc: store only index in p->exits, it's the only thing used there
function                                             old     new   delta
zbc_parse_stmt_possibly_auto                        1967    1964      -3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-3)               Total: -3 bytes
   text	   data	    bss	    dec	    hex	filename
 981937	    485	   7296	 989718	  f1a16	busybox_old
 981934	    485	   7296	 989715	  f1a13	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-16 23:24:25 +01:00