Commit Graph

531 Commits

Author SHA1 Message Date
Denys Vlasenko
a50576a415 bc: fold zbc_parse_else() into its only caller
While at it, allow newline between "else" and its body

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-16 19:21:57 +01:00
Denys Vlasenko
202dd1943c bc: fixes for multi-line if/while/for
function                                             old     new   delta
zbc_vm_process                                       561     589     +28
zbc_lex_next_and_skip_NLINE                            -      22     +22
zbc_parse_stmt_possibly_auto                        2232    2253     +21
zbc_lex_skip_if_at_NLINE                               -      14     +14
zbc_lex_number                                       192     200      +8
zbc_num_divmod                                       150     156      +6
bc_vm_run                                            134     139      +5
bc_vm_init                                           757     760      +3
bc_num_printNewline                                   51      54      +3
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 7/0 up/down: 110/0)             Total: 110 bytes
   text	   data	    bss	    dec	    hex	filename
 982138	    485	   7296	 989919	  f1adf	busybox_old
 982275	    485	   7296	 990056	  f1b68	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-16 17:30:35 +01:00
Denys Vlasenko
e9519e44a6 bc: fix handling of 'return' not in functions, and 'define f()<newline>{...}'
function                                             old     new   delta
zbc_vm_process                                       561     597     +36
zbc_parse_stmt_possibly_auto                        2232    2253     +21
zbc_lex_number                                       192     200      +8
zbc_num_divmod                                       150     156      +6
bc_vm_run                                            134     139      +5
bc_vm_init                                           757     760      +3
bc_num_printNewline                                   51      54      +3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 7/0 up/down: 82/0)               Total: 82 bytes
   text	   data	    bss	    dec	    hex	filename
 982138	    485	   7296	 989919	  f1adf	busybox_old
 982247	    485	   7296	 990028	  f1b4c	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-16 17:06:07 +01:00
Denys Vlasenko
d1d29b4245 bc: partially rewrite parser, tests pass, ^C might be broken now
The entire control construct (if/while/for/funcdef) or {} block is
"eaten" by the corresponding parsing function, instead of maintaining
special "block flag stack" with magic bits in it, and returning to main
input loop after every inner statement (every input line, essentially).

This required moving line input deep into lexer - now zbc_lex_next()
triggers more reading when needed.

"block flag stack" is gone.

Correctness of ^C handling wasn't checked, might need fixing now.

if/else syntax is changed to match GNU bc: "else" can not be on
the next line (the rationale is that "if (1) 2" statement in interactive
mode should execute and print 2 instead of waiting for possible
"else ..." line).

This change fixes the following examples:

if (1) if (1) 1 else 2 else 3

if (0) 1 else if (1) 2

define w() { auto z; return 1; }

function                                             old     new   delta
zbc_parse_stmt_possibly_auto                           -    2232   +2232
zbc_vm_process                                        89     561    +472
zbc_lex_next                                        1982    2296    +314
bc_vm_init                                           749     757      +8
bc_parse_expr_empty_ok                              2016    2021      +5
bc_num_printNewline                                   54      51      -3
zbc_program_read                                     289     280      -9
bc_parse_free                                         47      38      -9
bc_parse_reset                                       126     113     -13
bc_parse_create                                      108      92     -16
bc_parse_push_block_flag                              47       -     -47
bc_parse_noElse                                       48       -     -48
zbc_parse_text_init                                  113      59     -54
zbc_parse_body                                       121       -    -121
zbc_parse_else                                       125       -    -125
zbc_parse_endBody                                    254       -    -254
bc_vm_run                                            421     134    -287
zbc_parse_auto                                       290       -    -290
zcommon_parse                                        476       -    -476
zbc_parse_stmt                                      1682       7   -1675
------------------------------------------------------------------------------
(add/remove: 1/7 grow/shrink: 4/8 up/down: 3031/-3427)       Total: -396 bytes
   text	   data	    bss	    dec	    hex	filename
 982586	    485	   7296	 990367	  f1c9f	busybox_old
 982138	    485	   7296	 989919	  f1adf	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-16 16:10:38 +01:00
Denys Vlasenko
99b3762335 bc: lexer debugging, added some failing test cases
function                                             old     new   delta
bc_parse_push_block_flag                               -      47     +47
zbc_parse_body                                       107     121     +14
zbc_num_divmod                                       156     150      -6
zbc_lex_number                                       200     192      -8
zbc_parse_endBody                                    264     254     -10
bc_parse_startBody                                    47       -     -47
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 1/3 up/down: 61/-71)            Total: -10 bytes
   text	   data	    bss	    dec	    hex	filename
 982596	    485	   7296	 990377	  f1ca9	busybox_old
 982586	    485	   7296	 990367	  f1c9f	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-15 20:06:59 +01:00
Denys Vlasenko
818b602c88 bc: fix another thinko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-13 17:56:35 +01:00
Denys Vlasenko
766f67250f bc: fix comment handling
function                                             old     new   delta
bc_vm_run                                            514     513      -1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-13 17:43:23 +01:00
Denys Vlasenko
9a23b07c4c testsuite: add bc and dc tests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-12 21:41:40 +01:00
Denys Vlasenko
a133137174 dc: fix testsuite
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-06 18:46:42 +01:00
Chen Qi
572dfb8e78 testsuite: check CONFIG_DESKTOP before using 'od -t'
The '-t' option for od is enabled by CONFIG_DESKTOP. So
check this config before using 'od -t' in test cases.

Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-27 16:57:36 +01:00
Bernhard Reutner-Fischer
3db4e7f84c printf: fix printing +-prefixed numbers
Thanks to Cristian Ionescu-Idbohrn for noticing.

Also fix "%d" '  42' to skip leading whitespace.

function                                             old     new   delta
print_direc                                          435     454     +19
bb_strtoll                                            99     103      +4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 23/0)               Total: 23 bytes

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2018-10-19 15:27:42 +02:00
Thomas De Schampheleire
6608879d34 head: convert existing tests to new-style
Signed-off-by: Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-09-22 19:40:35 +02:00
Thomas De Schampheleire
e0f617699f head: add test case for negative -n invocation
Commit 2da9724b56 broke 'head -n -1' and was
later reverted with 0d598ab9f0.

This commit adds a test case to avoid future breakage.

Signed-off-by: Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-09-22 19:40:35 +02:00
Denys Vlasenko
e5d5f5b9a7 hexdump: fix short file of zero butes treated as dup
function                                             old     new   delta
bb_dump_dump                                        1466    1491     +25

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-03 16:29:06 +02:00
Denys Vlasenko
335766602b testsuite/mount.tests: fix false positive
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-28 14:10:00 +02:00
Denys Vlasenko
4c58f246d4 testsuite/pidof.tests: fix false positive take 2
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-27 14:50:00 +02:00
Denys Vlasenko
332a191e7f testsuite/tar.tests: fix false positive
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-27 14:35:56 +02:00
Denys Vlasenko
33eae28710 testsuite/pidof.tests: fix false positive
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-27 14:26:21 +02:00
Denys Vlasenko
94593799f7 testsuite/bzcat.tests: fix false positive take 2
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-27 13:15:10 +02:00
Denys Vlasenko
d8799b90f3 testsuite/unexpand/unexpand-works-like-GNU: fix false positive
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-27 12:54:57 +02:00
Denys Vlasenko
a429d5d0f3 testsuite/bzcat.tests: fix false positive
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-27 10:35:45 +02:00
Denys Vlasenko
5738823dff testsuite/tar.tests: fix false positive
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-27 10:01:49 +02:00
Denys Vlasenko
751005020d testsuite/cat.tests: fix false positive
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-27 09:57:30 +02:00
Denys Vlasenko
a36986bb80 unlzma: close another SEGV possibility
function                                             old     new   delta
unpack_lzma_stream                                  2669    2686     +17

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-05-25 17:03:46 +02:00
Harald van Dijk
8c24af9dcf tar: fix interaction of delayed symlink and hardlink creation
function                                             old     new   delta
create_or_remember_link                                -     106    +106
create_links_from_list                                 -      93     +93
find_applet_by_name                                  124     128      +4
unzip_main                                          2724    2726      +2
data_extract_all                                     891     873     -18
create_symlinks_from_list                             64       -     -64
create_or_remember_symlink                            94       -     -94
------------------------------------------------------------------------------
(add/remove: 2/2 grow/shrink: 2/1 up/down: 205/-176)           Total: 29 bytes

Signed-off-by: Harald van Dijk <harald@gigawatt.nl>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-05-22 17:34:31 +02:00
Denys Vlasenko
d80eecb868 cat: fix cat -e and cat -v erroneously numbering 1st line
function                                             old     new   delta
cat_main                                             418     421      +3

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-29 14:05:43 +02:00
Denys Vlasenko
2454e678cb awk: do not allow $(-1)
function                                             old     new   delta
EMSG_NEGATIVE_FIELD                                    -      25     +25
evaluate                                            3390    3403     +13
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/0 up/down: 38/0)               Total: 38 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-23 10:53:18 +02:00
Denys Vlasenko
e09c426456 unlzma: fix another SEGV case
function                                             old     new   delta
unpack_lzma_stream                                  1705    1717     +12

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-19 19:30:51 +02:00
Ron Yorston
1f27fa9838 testsuite: allow tests to work in paths containing spaces
Tweak some tests so they work when the path to the test directory or
$HOME contains spaces.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-09 20:35:48 +02:00
Denys Vlasenko
a1870f4807 unlzma: fix segfault on bad archive
function                                             old     new   delta
unpack_lzma_stream                                  2647    2653      +6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-08 20:45:16 +02:00
Denys Vlasenko
38ccd6af8a bzip2: fix two crashes on corrupted archives
As it turns out, longjmp'ing into freed stack is not healthy...

function                                             old     new   delta
unpack_usage_messages                                  -      97     +97
unpack_bz2_stream                                    369     409     +40
get_next_block                                      1667    1677     +10
get_bits                                             156     155      -1
start_bunzip                                         212     183     -29
bb_show_usage                                        181     120     -61
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 2/3 up/down: 147/-91)            Total: 56 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-08 20:05:04 +02:00
Denys Vlasenko
03fd7e06f8 grep: fix echo "aa" | busybox grep -F -w "a" (should not match)
function                                             old     new   delta
grep_file                                           1461    1470      +9

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-29 18:03:50 +02:00
Denys Vlasenko
a84db18fc7 tar,unzip: postpone creation of symlinks with "suspicious" targets
This mostly reverts commit bc9bbeb2b8
"libarchive: do not extract unsafe symlinks unless $EXTRACT_UNSAFE_SYMLINKS=1"

Users report that it is somewhat too restrictive. See
https://bugs.busybox.net/show_bug.cgi?id=8411

In particular, this interferes with unpacking of busybox-based
filesystems with links like "sbin/applet" -> "../bin/busybox".

The change is made smaller by deleting ARCHIVE_EXTRACT_QUIET flag -
it is unused since 2010, and removing conditionals on it
allows commonalizing some error message codes.

function                                             old     new   delta
create_or_remember_symlink                             -      94     +94
create_symlinks_from_list                              -      64     +64
tar_main                                            1002    1006      +4
unzip_main                                          2732    2724      -8
data_extract_all                                     984     891     -93
unsafe_symlink_target                                147       -    -147
------------------------------------------------------------------------------
(add/remove: 2/1 grow/shrink: 1/2 up/down: 162/-248)          Total: -86 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-20 16:06:53 +01:00
Ron Yorston
ecaec1dbec testsuite: update busybox and bzcat tests
Test scripts that use CONFIG_* variables need to source .config.
Since this wasn't being done for busybox many tests were skipped.
As a result new failures due to changes in help output were missed.

Also remove some unnecessary echos in the bzcat script.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-12 15:32:02 +01:00
Denys Vlasenko
6f4a785bd1 awk: fix 'delete array[var--]' decrementing var twice
function                                             old     new   delta
evaluate                                            3395    3390      -5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-07 01:19:08 +01:00
Denys Vlasenko
9c47c43e07 sed: in '/regexp/cmd1;//cmd2', cmd2 should use the same regexp as cmd1
function                                             old     new   delta
get_address                                          165     211     +46

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-23 17:56:03 +02:00
Denys Vlasenko
bc9bbeb2b8 libarchive: do not extract unsafe symlinks unless $EXTRACT_UNSAFE_SYMLINKS=1
function                                             old     new   delta
unsafe_symlink_target                                  -     147    +147
unzip_main                                          2711    2732     +21
copy_file                                           1657    1678     +21
tar_main                                             999     971     -28
data_extract_all                                    1038     984     -54
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 2/2 up/down: 189/-82)           Total: 107 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-10 11:52:42 +02:00
Denys Vlasenko
9cf89cdf84 sysctl: fix file parsing, do not require -w for VAR=VAL
function                                             old     new   delta
sysctl_act_on_setting                                  -     451    +451
sysctl_main                                          222     282     +60
packed_usage                                       31744   31793     +49
config_read                                          604     639     +35
sysctl_act_recursive                                 612     163    -449
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 3/1 up/down: 595/-449)          Total: 146 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-05 13:45:22 +02:00
Denys Vlasenko
b920a38dc0 tar: postpone creation of symlinks with "suspicious" targets. Closes 8411
function                                             old     new   delta
data_extract_all                                     968    1038     +70
tar_main                                             952     986     +34
scan_tree                                            258     262      +4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 108/0)             Total: 108 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-24 17:20:13 +02:00
Ron Yorston
a165603d24 od_bloaty: fix floating point output
Currently od_bloaty does this:

   $ /bin/echo -en '\x00\x00\x00\x00\x00\x00\x00\x00' | busybox od -f
   od: invalid character 'F' in type string 'fF'
   $ /bin/echo -en '\x00\x00\x00\x00\x00\x00\x00\x00' | busybox od -t fD
   od: invalid character 'D' in type string 'fD'
   $ /bin/echo -en '\x00\x00\x00\x00\x00\x00\x00\x00' | busybox od -t f
   0000000
   0000010

The first two occur because the alphabetic length specifier isn't being
properly skipped.  The third is due to the empty length specifier being
treated as alphabetic so we fall off the end of the FDL_sizeof array with
undetermined consequences.  Coreutils defaults to printing a double in
this case.

With this patch the output is:

   $ /bin/echo -en '\x00\x00\x00\x00\x00\x00\x00\x00' | ./busybox od -f
   0000000   0.0000000e+00   0.0000000e+00
   0000010
   $ /bin/echo -en '\x00\x00\x00\x00\x00\x00\x00\x00' | ./busybox od -t fD
   0000000   0.000000000000000e+00
   0000010
   $ /bin/echo -en '\x00\x00\x00\x00\x00\x00\x00\x00' | ./busybox od -t f
   0000000   0.000000000000000e+00
   0000010

I guess nobody uses BusyBox od to print floating point numbers.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-19 13:12:02 +02:00
Denys Vlasenko
2e989ef232 msh: delete this applet
It's deprecated since 2009 and interferes with make_single_applets.sh tests.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-03 16:56:37 +02:00
Denys Vlasenko
10ad622dc2 Spelling fixes in comments, documentation, tests and examples
By klemens <ka7@github.com>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-17 16:13:32 +02:00
Denys Vlasenko
ee7f75d94f factor: new applet
thus far only able to factor up to ULLONG_MAX

function                                             old     new   delta
factor_main                                            -     378    +378
packed_usage                                       31427   31502     +75
applet_names                                        2590    2597      +7
applet_main                                         1500    1504      +4
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 3/0 up/down: 464/0)             Total: 464 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-09 21:18:43 +02:00
Maxime Coste
d2383f57cd paste: new applet
function                                             old     new   delta
paste_main                                             -     493    +493
packed_usage                                       31019   31070     +51
applet_names                                        2569    2575      +6
applet_main                                         1484    1488      +4
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 3/0 up/down: 554/0)             Total: 554 bytes

Signed-off-by: Maxime Coste <mawww@kakoune.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-03-23 17:35:52 +01:00
Denys Vlasenko
bca4ea8b68 remove "local" bashism from a few scripts
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-24 20:52:42 +01:00
Denys Vlasenko
6c73aaff38 cryptpw: support "rounds=NNNNNNN$" thing in salts
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-15 21:48:31 +01:00
Denys Vlasenko
265062d59d shells: make hush test optional, rename ASH_BUILTIN_foo -> ASH_foo
This makes hash and ash more symmetrical wrt config menu and config
options.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-10 15:13:30 +01:00
Denys Vlasenko
0ffac1cc22 unzip: do not use CDF.extra_len, read local file header. Closes 9536
While at it, shorten many field and variable names.

function                                             old     new   delta
unzip_main                                          2334    2376     +42

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-08 14:14:19 +01:00
Denys Vlasenko
e3c4db8b39 unzip: properly use CDF to find compressed files. Closes 9536
function                                             old     new   delta
unzip_main                                          2437    2350     -87

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-05 11:43:53 +01:00
Denys Vlasenko
76de3257f7 randomconfig fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-12-12 19:17:12 +01:00