Commit Graph

1513 Commits

Author SHA1 Message Date
Ron Yorston
922b58b3e4 tar,smemcap: silence compiler warning
gcc 11.2.1 complains that the tar header checksum might overflow
the checksum field.  It won't and using an unsigned int for the
calculation seems to convince the compiler too.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-08-22 15:44:57 +02:00
Denys Vlasenko
1e7ca18591 Regularize "NUL terminated input" --help texts
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-08-22 15:43:29 +02:00
Denys Vlasenko
62d5a1e56f tar,smemcap: commonalyze checksumming code for tar header
function                                             old     new   delta
chksum_and_xwrite_tar_header                           -      99     +99
writeheader                                          280     199     -81
chksum_and_xwrite                                    102       -    -102
------------------------------------------------------------------------------
(add/remove: 2/1 grow/shrink: 0/1 up/down: 99/-183)           Total: -84 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-08-20 17:58:49 +02:00
Harald van Dijk
8ae6a4344d tar: exclude files before updating hardlink info list
When excluding one file, and including another file that is a hardlink
of the excluded file, it should be stored as an ordinary file.

function                                             old     new   delta
writeFileToTarball                                   489     493      +4

Signed-off-by: Harald van Dijk <harald@gigawatt.nl>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-08-02 20:13:28 +02:00
Denys Vlasenko
3d40dfabe1 tar: simplify addition of --exclude=GLOB to the expansion of -X EXCLFILE
function                                             old     new   delta
tar_main                                            1115    1105     -10

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-08-02 19:58:13 +02:00
S Harris
e03b49477a cpio: fix sscanf on unterminated buffer
Signed-off-by: S Harris <S.E.Harris@kent.ac.uk>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-23 19:06:09 +02:00
Denys Vlasenko
04f052c56d unlzma: fix a case where we could read before beginning of buffer
Testcase:

  21 01 01 00 00 00 00 00 e7 01 01 01 ef 00 df b6
  00 17 02 10 11 0f ff 00 16 00 00

Unfortunately, the bug is not reliably causing a segfault,
the behavior depends on what's in memory before the buffer.

function                                             old     new   delta
unpack_lzma_stream                                  2762    2768      +6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-15 15:14:00 +02:00
Denys Vlasenko
1f60d88cf6 *: more --help tweaks
function                                             old     new   delta
packed_usage                                       33552   33541     -11

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-15 10:00:18 +02:00
Denys Vlasenko
e2b9215868 *: --help tweaks
function                                             old     new   delta
packed_usage                                       33589   33552     -37

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-14 20:47:20 +02:00
Denys Vlasenko
1849285a20 *: more --help tweaks, mostly expanding ts --help
function                                             old     new   delta
packed_usage                                       33554   33596     +42

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-13 03:12:09 +02:00
Denys Vlasenko
6b6826f0b8 *: --help tweaks
function                                             old     new   delta
.rodata                                           103190  103189      -1
packed_usage                                       33590   33566     -24
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-25)             Total: -25 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-13 01:08:48 +02:00
Denys Vlasenko
b1a2762ecf cpio: fix "cpio -d -p A/B/C"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-03 20:26:30 +02:00
Denys Vlasenko
147ac93a06 decompress_gunzip: simplify ERR_RET bit clearing
My gcc is in fact clever enough to do it itself, but let's be explicit

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-05-03 14:58:32 +02:00
Denys Vlasenko
cca4c9f4c0 unzip: add -t
function                                             old     new   delta
packed_usage                                       33584   33598     +14
.rodata                                           103218  103219      +1
unzip_main                                          2665    2656      -9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 15/-9)               Total: 6 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-04-14 21:34:00 +02:00
Denys Vlasenko
afc766fc12 unzip: fix for .zip archives with >4GB file
function                                             old     new   delta
unzip_main                                          2644    2665     +21
input_tab                                            926     927      +1
bb_banner                                             46      47      +1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 23/0)               Total: 23 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-04-14 21:15:25 +02:00
Samuel Sapalski
f25d254dfd decompress_gunzip: Fix DoS if gzip is corrupt
On certain corrupt gzip files, huft_build will set the error bit on
the result pointer. If afterwards abort_unzip is called huft_free
might run into a segmentation fault or an invalid pointer to
free(p).

In order to mitigate this, we check in huft_free if the error bit
is set and clear it before the linked list is freed.

Signed-off-by: Samuel Sapalski <samuel.sapalski@nokia.com>
Signed-off-by: Peter Kaestle <peter.kaestle@nokia.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-03-12 10:45:10 +01:00
Denys Vlasenko
9daa877d6b tar: add TODO about a bug with non-writable directories on extract
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-01-01 13:34:25 +01:00
Denys Vlasenko
a2f18d950a help text tweaks
function                                             old     new   delta
packed_usage                                       33570   33502     -68

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-18 04:12:51 +01:00
Denys Vlasenko
c7b858ff8d libbb: add and use infrastructure for fixed page size optimization
function                                             old     new   delta
procps_scan                                         1121    1118      -3
getpagesize                                            6       -      -6
rpm_main                                            1037    1027     -10
rpm2cpio_main                                        120     110     -10
ptok                                                  38      21     -17
time_main                                           1282    1261     -21
mkswap_main                                          317     278     -39
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 0/6 up/down: 0/-106)           Total: -106 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-14 18:54:30 +01:00
Denys Vlasenko
fd3c512f88 libbb: create and use mmap() helpers
function                                             old     new   delta
mmap_anon                                              -      22     +22
mmap_read                                              -      21     +21
xmmap_anon                                             -      16     +16
rpm_gettags                                          465     447     -18
bb_full_fd_action                                    498     480     -18
uevent_main                                          337     310     -27
------------------------------------------------------------------------------
(add/remove: 3/0 grow/shrink: 0/3 up/down: 59/-63)             Total: -4 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-14 18:25:28 +01:00
Denys Vlasenko
11f1a2553e help text tweaks
function                                             old     new   delta
packed_usage                                       33547   33545      -2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-13 19:04:19 +01:00
Denys Vlasenko
c9b93cf290 tar: expand --help
function                                             old     new   delta
packed_usage                                       33486   33590    +104

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-08 16:46:41 +01:00
Denys Vlasenko
6cc4962b60 decrease padding: gcc-9.3.1 slaps 32-byte alignment on arrays willy-nilly
text	   data	    bss	    dec	    hex	filename
1021236	    559	   5052	1026847	  fab1f	busybox_old
1021120	    559	   5052	1026731	  faaab	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-30 14:58:02 +01:00
Denys Vlasenko
965b795b87 decrease paddign: gcc-9.3.1 slaps 32-byte alignment on arrays willy-nilly
text	   data	    bss	    dec	    hex	filename
1021988	    559	   5052	1027599	  fae0f	busybox_old
1021236	    559	   5052	1026847	  fab1f	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-30 13:03:03 +01:00
Joachim Nilsson
bd46f64dcb archival: avoid std namespace for local includes
Avoid using same include file naming pattern as available in GLIBC.
Renamed to match grp_.h et al.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-16 13:24:24 +01:00
Denys Vlasenko
16e82c61d4 tar: fix fallout of last_char_is(NULL) no longer being allowed
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-02 18:30:53 +02:00
Denys Vlasenko
689d0650ab libbb: shrink recursive_action() by reducing memory pressure
function                                             old     new   delta
recursive_action1                                      -     316    +316
file_action_grep                                     161     164      +3
add_to_prg_cache_if_socket                           202     205      +3
depmod_main                                          509     511      +2
writeFileToTarball                                   488     489      +1
parse_module                                         281     282      +1
fileAction                                           207     208      +1
act                                                  189     190      +1
add_to_dirlist                                        65      64      -1
writeTarFile                                         196     194      -2
uuidcache_init                                        47      45      -2
uuidcache_check_device                               109     107      -2
true_action                                            8       6      -2
run_parts_main                                       310     308      -2
netstat_main                                         534     532      -2
lsusb_main                                            29      27      -2
lspci_main                                            45      43      -2
initial_scan                                         138     136      -2
grep_main                                            845     843      -2
find_main                                            482     480      -2
config_file_action                                   437     435      -2
chmod_main                                           142     140      -2
dirAction                                             14      10      -4
diff_main                                           1544    1540      -4
chown_main                                           154     148      -6
skip_dir                                             136     129      -7
dir_act                                              191     184      -7
recursive_action                                     453      69    -384
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 7/20 up/down: 328/-439)        Total: -111 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-01 21:52:16 +02:00
Denys Vlasenko
4a0eb0370c gcc-9.x warning fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-01 03:07:22 +02:00
Norbert Lange
86a633ef9a dpkg: prevent important directories from being removed
busybox will remove directory symlinks, which is at
odds with common layouts that have some of
bin/lib/lib32/lib64 symlinked.

this adds a exludelist for critcal and often symlinked
directories.

Fixes: Bug 12551

function                                             old     new   delta
remove_file_array                                    139     231     +92

Signed-off-by: Norbert Lange <nolange79@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-06-29 14:06:40 +02:00
Denys Vlasenko
24c212b9ac gzip -d with zcat enabled but gunzip disabled was misbehaving
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-06-25 02:01:29 +02:00
Denys Vlasenko
7c443d110d randomconfig fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-06-24 00:27:37 +02:00
Lauri Kasanen
b9943741c2 unzip: -d should create the dir
The official Info-Zip unzip creates the dir if it doesn't exist.

Signed-off-by: Lauri Kasanen <cand@gmx.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-04-29 14:37:21 +02:00
Denys Vlasenko
2f57b5139e unxz: show -t in --help
function                                             old     new   delta
packed_usage                                       33236   33247     +11

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-11-08 16:37:28 +01:00
Denys Vlasenko
caf5ee0dd9 gunzip: fix incorrect decoding of "fixed" inflate blocks
function                                             old     new   delta
huft_build                                          1008    1022     +14
inflate_block                                       1253    1256      +3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 17/0)               Total: 17 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-26 20:04:34 +02:00
Denys Vlasenko
e1a7c97ac6 tar: fix fallout of: change -a from meaning "lzma" to mean "autodetect by extension"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-25 10:30:53 +02:00
Denys Vlasenko
fb1103595f gunzip: code shrink by using int-, not short-sized struct member
function                                             old     new   delta
inflate_block                                       1254    1253      -1
inflate_codes                                        629     621      -8
huft_build                                          1054    1008     -46
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-55)             Total: -55 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-20 19:07:06 +02:00
Denys Vlasenko
6572ef6e1e gzip: code shrink
huft_build() still has way too many params

function                                             old     new   delta
lit                                                    -      94     +94
dist                                                   -      94     +94
huft_build                                          1058    1054      -4
inflate_block                                       1281    1254     -27
cpdext                                                30       -     -30
cplext                                                31       -     -31
cpdist                                                60       -     -60
cplens                                                62       -     -62
------------------------------------------------------------------------------
(add/remove: 2/4 grow/shrink: 0/2 up/down: 188/-214)          Total: -26 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-19 18:53:19 +02:00
Denys Vlasenko
c763392458 gzip: code shrink
huft_build() has way too many params

function                                             old     new   delta
inflate_block                                       1293    1281     -12
huft_build                                          1085    1058     -27
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-39)             Total: -39 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-19 18:33:49 +02:00
Denys Vlasenko
42f454b13b dpkg-deb: work around bogus error message when working with XZ compressed packages
function                                             old     new   delta
unpack_xz_stream                                    2309    2317      +8
bb_full_fd_action                                    464     472      +8

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-11 14:11:44 +02:00
Denys Vlasenko
d327c6b190 gzip: code shrink
Converted a few 16-bit variables and small arrays to 32-bit.

Stopped pulling desc->FOO members into temporary local variables
in gen_bitlen(): on register-starved arches, this is a loss,
temporaries go into stack slots.

Sprinkled a few "const" on pointer arguments.

function                                             old     new   delta
pack_gzip                                            742     745      +3
gen_codes                                            101      97      -4
build_tree                                           886     833     -53
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 3/-57)             Total: -54 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-09-06 17:59:45 +02:00
Denys Vlasenko
750137ef7c gzip: code shrink
function                                             old     new   delta
gzip_main                                            267     264      -3

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-09-05 13:26:58 +02:00
Daniel Edgecumbe
c660cc1b77 gzip: set default compression level to 6 when CONFIG_FEATURE_GZIP_LEVELS=n
With this change, GNU gzip -n and BusyBox gzip now produce identical output
assuming that CONFIG_GZIP_FAST=2.

>> Excuse me, but I wonder one thing: Why should we follow
>> strictly with gzip on the no-options default behavior?

> First, the default 6 compression level is a de-facto standard. BSD gzip
> and Apple gzip (on macOS) use this default as well. So there is a
> reasonable expectation that different gzip implementations act the same.
> For instance, if the default for busybox gzip becomes 9, then someone
> writing a script using busybox gzip could reasonably expect that the
> compression level will still be 9 when the same script is run on another
> system. That would be wrong. Implementations should not deviate from
> de-facto standards without a strong reason.
>
> Second, the inherent reason for this default has not gone away. While
> processor speeds have exploded since the default was set, so has the
> typical size of compressed files. Multiple gigabytes are nothing unusual
> these days. And gzip is often used for compression on the fly, precisely
> because it offers a good compromise between speed and compression ratio.
> So I believe 6 continues to be a reasonable default.

function                                             old     new   delta
deflate                                              939     927     -12

Signed-off-by: Daniel Edgecumbe <git@esotericnonsense.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-09-05 13:26:58 +02:00
Daniel Edgecumbe
ca5d86d52c gzip: set compression flags correctly as per standard
With this change and CONFIG_GZIP_FAST=2, CONFIG_FEATURE_GZIP_LEVELS=y,

GNU gzip and BusyBox gzip now produce identical output at each compression
level (excluding 1..3, as BusyBox does not implement these levels).

Signed-off-by: Daniel Edgecumbe <git@esotericnonsense.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-09-05 13:26:58 +02:00
Daniel Edgecumbe
de82f0b764 gzip: default level with ENABLE_FEATURE_GZIP_LEVELS should be 6
Fixes an off-by-one that actually resulted in level 7 being used

Signed-off-by: Daniel Edgecumbe <git@esotericnonsense.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-09-05 13:26:58 +02:00
Denys Vlasenko
16474cf246 tar: change -a from meaning "lzma" to mean "autodetect by extension"
function                                             old     new   delta
tar_main                                            1026    1100     +74
packed_usage                                       33311   33329     +18
tar_longopts                                         309     325     +16
vfork_compressor                                     246     210     -36
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/1 up/down: 108/-36)            Total: 72 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-08-02 15:19:56 +02:00
Denys Vlasenko
e6a87e7483 tar: code shrink
function                                             old     new   delta
writeLongname                                        226     228      +2
static.prefilled                                      48       -     -48
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/0 up/down: 2/-48)             Total: -46 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-08-01 15:07:21 +02:00
James Byrne
6937487be7 libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d437 ("'simple' error message functions by
Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower
overhead call to bb_perror_msg() when only a string was being printed
with no parameters. This saves space for some CPU architectures because
it avoids the overhead of a call to a variadic function. However there
has never been a simple version of bb_error_msg(), and since 2007 many
new calls to bb_perror_msg() have been added that only take a single
parameter and so could have been using bb_simple_perror_message().

This changeset introduces 'simple' versions of bb_info_msg(),
bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and
bb_herror_msg_and_die(), and replaces all calls that only take a
single parameter, or use something like ("%s", arg), with calls to the
corresponding 'simple' version.

Since it is likely that single parameter calls to the variadic functions
may be accidentally reintroduced in the future a new debugging config
option WARN_SIMPLE_MSG has been introduced. This uses some macro magic
which will cause any such calls to generate a warning, but this is
turned off by default to avoid use of the unpleasant macros in normal
circumstances.

This is a large changeset due to the number of calls that have been
replaced. The only files that contain changes other than simple
substitution of function calls are libbb.h, libbb/herror_msg.c,
libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c,
networking/udhcp/common.h and util-linux/mdev.c additonal macros have
been added for logging so that single parameter and multiple parameter
logging variants exist.

The amount of space saved varies considerably by architecture, and was
found to be as follows (for 'defconfig' using GCC 7.4):

Arm:     -92 bytes
MIPS:    -52 bytes
PPC:   -1836 bytes
x86_64: -938 bytes

Note that for the MIPS architecture only an exception had to be made
disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h)
because it made these files larger on MIPS.

Signed-off-by: James Byrne <james.byrne@origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02 11:35:03 +02:00
Denys Vlasenko
eda83c9e69 comment fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-05-26 13:46:49 +02:00
Denys Vlasenko
cc71f79c1e libarchive: treat one "FIXME: avoid seek", take 2
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-05-26 13:43:06 +02:00
Denys Vlasenko
dff2bd733f libarchive: treat one "FIXME: avoid seek"
function                                             old     new   delta
xmalloc_read_with_initial_buf                          -     205    +205
setup_transformer_on_fd                              154     150      -4
xmalloc_open_zipped_read_close                       143     135      -8
xmalloc_read                                         201      10    -191
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/3 up/down: 205/-203)            Total: 2 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-05-24 17:03:28 +02:00