Commit Graph

589 Commits

Author SHA1 Message Date
Denys Vlasenko
758c2bd58e awk: add a test that $NF is empty
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-04 19:00:06 +01:00
Denys Vlasenko
665a659530 awk: FS regex matches only non-empty separators (gawk compat)
function                                             old     new   delta
awk_split                                            484     553     +69

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-02 19:07:31 +01:00
Denys Vlasenko
079487b487 hexdump: fix dup block comparison
function                                             old     new   delta
bb_dump_dump                                        1523    1520      -3

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-20 19:29:32 +02:00
Denys Vlasenko
dac5b83142 xxd: fix printing of trailing spaces
function                                             old     new   delta
bb_dump_dump                                        1497    1523     +26
xxd_main                                             459     466      +7
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 33/0)               Total: 33 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-20 18:57:02 +02:00
Denys Vlasenko
bd202a5ec1 xargs: fix -I SUBSTR behaviour
function                                             old     new   delta
process_stdin_with_replace                           165     204     +39

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-09-30 00:00:43 +02:00
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