Compare commits

..
1057 Commits
Author SHA1 Message Date
Denys Vlasenko 6412da255d libbb: fix ioloop's limitation of fd < 1024
function                                             old     new   delta
grow_fdsets                                            -      90     +90
ioloop_run                                           438     485     +47
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/0 up/down: 137/0)             Total: 137 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-17 18:23:08 +01:00
Denys Vlasenko 25a61f0feb shell: in math evaluation, use malloc, not alloca
function                                             old     new   delta
evaluate_string                                     1315    1322      +7

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-17 14:44:30 +01:00
Denys Vlasenko d724d7d292 mkfs.vfat: fix creation of 2.5 kbyte FAT12 image
function                                             old     new   delta
mkfs_vfat_main                                      2463    2454      -9
.rodata                                           105036  105007     -29
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-38)             Total: -38 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-16 13:56:51 +01:00
Denys Vlasenko 8d79a6335c mkfs.vfat: fix write buffer allocation for tiny images
function                                             old     new   delta
mkfs_vfat_main                                      2460    2463      +3

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-15 23:06:39 +01:00
Denys Vlasenko 3441a0e4bc mkfs.vfat: add ignored option -a ("disable alignment")
function                                             old     new   delta
.rodata                                           105038  105036      -2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-15 22:44:24 +01:00
Denys Vlasenko f8f567fb54 mkfs.vfat: implement creation of FAT12/16 filesystems
function                                             old     new   delta
mkfs_vfat_main                                      1858    2460    +602
.rodata                                           105028  105038     +10
packed_usage                                       36569   36575      +6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 618/0)             Total: 618 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-15 19:18:08 +01:00
Denys Vlasenko 7b38885adf mkfs.vfat: code shrink
function                                             old     new   delta
mkfs_vfat_main                                      1874    1858     -16

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-14 20:04:56 +01:00
Denys Vlasenko 174ee36441 mkfs.vfat: code chrink, prepare for FAT16/12 support
function                                             old     new   delta
mkfs_vfat_main                                      1880    1874      -6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-14 16:14:12 +01:00
Denys Vlasenko cb53a88831 testsuite: modify 130GB mkfs.vfat test to actually have the very max cluster#
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-14 00:23:59 +01:00
Denys Vlasenko fb32719cb2 testsuite: add 130GB mkfs.vfat test
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-13 17:30:02 +01:00
Denys Vlasenko d3303c327e mkfs.vfat: add -s SECTORS_PER_CLUSTER
function                                             old     new   delta
mkfs_vfat_main                                      1800    1880     +80
.rodata                                           105000  105028     +28
packed_usage                                       36552   36549      -3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 108/-3)            Total: 105 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-13 16:55:59 +01:00
Denys Vlasenko 9f435d8347 mkfs.vfat: if -C, avoid unnecessary zero-filling of newly-created image file
This can save hundreds of megabytes for a QEMU-operated virtual FAT32 disk.

function                                             old     new   delta
mkfs_vfat_main                                      1766    1800     +34
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 34/0)               Total: 34 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-13 15:09:33 +01:00
Denys Vlasenko 484da7a2b3 mkfs.vfat: add support for -S SECTOR_SIZE
mkfs.vfat -v -F32 -S4096 -C IMAGE_16TB $((1024*1024*1024*16 - 0x10000))
tested to work.

function                                             old     new   delta
mkfs_vfat_main                                      1613    1686     +73
packed_usage                                       36498   36552     +54
.rodata                                           104988  105000     +12
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 139/0)             Total: 139 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-13 14:49:44 +01:00
Denys Vlasenko d99c769ce3 mkfs.vfat: make -n "NO NAME " create the volume label as requested.
"NO NAME    " has special meaning _only_ in boot sector, not in rootdir's label.

function                                             old     new   delta
mkfs_vfat_main                                      1621    1613      -8

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-13 13:53:13 +01:00
Denys Vlasenko c743bd3a9d libbb: if get_volume_size_in_bytes() detects too-small block device, warn about it
The "mkfs.vfar BLOCKDEV 1000000" case where BLOCKDEV is smaller.

function                                             old     new   delta
.rodata                                           104938  104988     +50
get_volume_size_in_bytes                             262     293     +31
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 81/0)               Total: 81 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-13 13:44:25 +01:00
Denys Vlasenko 8eea53bb7a libbb: introduce and use xfstat_mode() and xfstat_size()
function                                             old     new   delta
xfstat_size                                            -      28     +28
add_remove_shell_main                                312     302     -10
mkfs_ext2_main                                      2299    2285     -14
mesg_main                                            157     136     -21
ar_main                                              565     527     -38
ubi_tools_main                                      1164    1125     -39
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/5 up/down: 28/-122)           Total: -94 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-12 16:40:57 +01:00
Denys Vlasenko 10c9c7faec mkfs.vfat: code shrink
function                                             old     new   delta
xfstat_mode                                            -      26     +26
mkfs_vfat_main                                      2106    1621    -485
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/1 up/down: 26/-485)          Total: -459 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-12 16:05:41 +01:00
Denys Vlasenko e18ddc4ad3 mkfs.vfat: print how many sectors we ignore on large volumes
It's quite useful to know whether you lose 123 sectors, or 123 gigabytes.

function                                             old     new   delta
mkfs_vfat_main                                      2096    2106     +10
.rodata                                           104951  104938     -13
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 10/-13)             Total: -3 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-12 16:04:41 +01:00
Denys Vlasenko 67a351f7c0 mkfs.vfat: code shrink, tweak comments
function                                             old     new   delta
mkfs_vfat_main                                      2102    2096      -6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-12 12:33:16 +01:00
Denys Vlasenko 7de358fa8e mkfs.vfat: explain big filesystem sizes with 32 sectors/cluster, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-12 11:11:29 +01:00
Denys Vlasenko 3e4beef20c mkfs.vfat: support -b N -R N - allows creation of tiny 3KB FAT32 image
function                                             old     new   delta
mkfs_vfat_main                                      1586    2102    +516
.rodata                                           104913  104951     +38
packed_usage                                       36467   36498     +31
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 585/0)             Total: 585 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-12 10:48:49 +01:00
Denys Vlasenko 4f986c0f9d mkfs.vfat: make it possible to create tiny 5KB images
function                                             old     new   delta
mkfs_vfat_main                                      1539    1586     +47
mkswap_main                                          253     256      +3
mkfs_minix_main                                     2575    2578      +3
mkfs_ext2_main                                      2297    2299      +2
.rodata                                           104946  104913     -33
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/1 up/down: 55/-33)             Total: 22 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-10 18:19:26 +01:00
Denys Vlasenko d03387ebf3 mkfs.vfat: correctly handle huge images with total sectors above 2^32
function                                             old     new   delta
.rodata                                           104897  104946     +49
mkfs_vfat_main                                      1526    1539     +13
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 62/0)               Total: 62 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-10 16:21:24 +01:00
Denys Vlasenko 292ec317a3 mkfs.ext2: fix "can't open '(null)': Bad address"
function                                             old     new   delta
.rodata                                           104893  104897      +4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-10 14:32:38 +01:00
Denys Vlasenko f227dc2eb7 mkfs.vfat: implement -C
function                                             old     new   delta
packed_usage                                       36438   36467     +29
mkfs_vfat_main                                      1518    1526      +8
.rodata                                           104894  104893      -1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 37/-1)              Total: 36 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-10 14:29:07 +01:00
Denys Vlasenko a096845640 testsuite: add mkfs.vfat and blkid tests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-10 11:46:15 +01:00
Denys Vlasenko 6a839afdee volume_id/fat: follow kernel example in deciding what is FAT32
This will allow detection of small FAT32 volumes which
are mountable by kernel - before this change we misdetected them,
and likely failed to fetch volume label.

While at it, avoid running off FAT if FAT is smaller than necessary
to cover entire data area, and rootdir has clusters beyond this
"shorter FAT". (This matches kernel behavior too)

function                                             old     new   delta
volume_id_probe_vfat                                 856     886     +30

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-10 03:25:03 +01:00
Denys Vlasenko bd8c4f7ce9 volume_id/fat: decrease maximum valid FAT table size to 0x02000000 sectors
It's still enormous (16GByte FAT tables). Real-world maximum
is 16 times smaller since cluster numbers are 28-bit.

function                                             old     new   delta
volume_id_probe_vfat                                 867     856     -11

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-10 00:43:35 +01:00
Denys Vlasenko 8015168a75 Share "NO NAME " string
function                                             old     new   delta
bb_NO_NAME_11                                          -      12     +12
static.NO_NAME_11                                     12       -     -12
.rodata                                           104906  104894     -12
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 0/1 up/down: 12/-24)            Total: -12 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-09 23:43:17 +01:00
Denys Vlasenko d04e804bee volume_id/fat: in root dir scan, stop at first cluster# larger than FAT size
Otherwise, we can read non-FAT area and try to interpret it as FAT.

function                                             old     new   delta
volume_id_probe_vfat                                 851     867     +16

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-09 12:50:07 +01:00
Denys Vlasenko 0c1060dee1 volume_id/fat: add validity checks for FAT12/16 (rootdir can't have 0 sectors)
function                                             old     new   delta
volume_id_probe_vfat                                 815     852     +37
mkfs_vfat_main                                      1523    1518      -5
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 37/-5)              Total: 32 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-09 12:37:21 +01:00
Denys Vlasenko 484e887ce6 volume_id/fat: avoid rereading of 1st sector - use it when we have it initially
function                                             old     new   delta
volume_id_probe_vfat                                 856     815     -41

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-08 21:13:58 +01:00
Denys Vlasenko 0338bee40e volume_id/fat: allow FAT partitions with one FAT, tighten some validity checks
function                                             old     new   delta
volume_id_probe_vfat                                 829     856     +27

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-08 20:54:48 +01:00
Denys Vlasenko 7584233f64 volume_id/fat: remove test for non-zero head count in FAT superblock probe.
From util-linux:

    This change enables the auto-detection of the internal storage on a VTech
    Kidizoom camera, which has a zero head count value in the superblock.

    Microsoft documentation, "FAT: General Overview of On-Disk Format", states
    that the sectors and heads fields are only relevant for media that have
    a geometry.

    The Linux kernel also does not require a non-zero head count, and can
    manually mount the filesystem.

function                                             old     new   delta
volume_id_probe_vfat                                 841     829     -12

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-08 19:20:57 +01:00
Denys Vlasenko b7c89c493a volume_id/fat: prevent possible division by zero and crash
function                                             old     new   delta
volume_id_probe_vfat                                 830     841     +11

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-08 18:25:22 +01:00
Dominique Martinet d68f55fc29 tunctl: fix segfault on ioctl failure
libbb now takes "" instead of NULL as format string for nomsg functions,
but this caller had not been updated making busybox segfault on tunctl
commands when ioctl fails.
This can be reproduced by running `tunctl -t tun0` in gdb and blocking
with the tun open after being created, and running `tunctl -d tun0` in
another shell: the later will fail with EBUSY after fixing:
> tunctl: Device or resource busy

function                                             old     new   delta
tunctl_main                                          393     409     +16

Fixes: 4bd70463c7 ("libbb: pass "" rather than NULL as format string in _nomsg functions")
Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-08 17:24:12 +01:00
Denys Vlasenko 17080dd399 shell/math: speed up handling of short arithmetic expansions
function                                             old     new   delta
evaluate_string                                     1291    1315     +24

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-08 16:31:12 +01:00
Denys Vlasenko d03670c64e mount: remove support for "swap" and "sw" mount options, they were added by mistake
Review of git log shows that they were mistakenly added during a rewrite
(confused with *FS type string* "swap" used in fstab to specify swap partitions).
util-linux's mount does not support this.
There is no reason to keep this incompatible extension.

function                                             old     new   delta
mount_main                                          1250    1249      -1
mount_options                                        188     180      -8
mount_option_str                                     385     377      -8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-17)             Total: -17 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-08 13:17:40 +01:00
Denys Vlasenko 604470bec4 mount: disallow -o OPTS, -T ALT_FSTAB, -a,r,w,n,f,i for non-root mount invocations
function                                             old     new   delta
mount_main                                          1259    1250      -9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-9)               Total: -9 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-08 03:05:09 +01:00
Denys Vlasenko c64ffa2e2b nsloopup: tighten up length checks to avoid out-of-bounds reads
function                                             old     new   delta
parse_reply                                          979    1030     +51

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-07 20:30:35 +01:00
Denys Vlasenko 5450a8ed71 rpm: bail out if headers have abnormally large entry counts
function                                             old     new   delta
.rodata                                           104880  104906     +26
rpm_gettags                                          419     443     +24
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 50/0)               Total: 50 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-07 20:02:28 +01:00
Denys Vlasenko f3ca54f688 tftp: add commented-out code with non-ISREG check
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-07 16:14:03 +01:00
Denys Vlasenko 56e9d36bb6 udhcpc[6]: check minimum packet size after reducing it to ip.tot_len
For DHCPv6, also require that all fields up until option array exist in the packet.
I did not find a definitive info that DHCPv6 requires at least one option
to be present, and the code appears to handle empty option array correctly.

function                                             old     new   delta
d6_recv_raw_packet                                   228     230      +2
d4_recv_raw_packet                                   500     501      +1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 3/0)                 Total: 3 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-07 14:05:35 +01:00
Denys Vlasenko b67f7b7d14 tftpd: make DIR argiment work for non-root too, strip leading /
function                                             old     new   delta
tftpd_main                                           573     589     +16

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-06 20:33:51 +01:00
Denys Vlasenko 7022247743 tftp(d): code shrink by not having two copies of option value
function                                             old     new   delta
tftp_protocol                                       1985    1938     -47

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-06 19:01:51 +01:00
Denys Vlasenko 1d363c609f tftpd: code shrink
function                                             old     new   delta
tftp_get_option                                      102      93      -9

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-06 18:09:10 +01:00
Denys Vlasenko 11edcd9eb0 tftpd: comment tweak
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-06 16:56:02 +01:00
Denys Vlasenko 1a80c25d30 tftpd: increase minimum supported block size to approx. 64
function                                             old     new   delta
tftp_protocol                                       2001    1985     -16

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-06 16:43:33 +01:00
Denys Vlasenko 8650079721 tftpd: improve sanitization of remote strings in error messages
function                                             old     new   delta
tftp_blksize_check                                    57      64      +7
tftp_protocol                                       2009    2001      -8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 7/-8)               Total: -1 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-06 16:18:47 +01:00
Michael Pfeifroth 2d6925708e awk: fix mktime() for dates beyond 2038
do_mktime() returned the result of mktime() as int. Since int is
32 bits wide even on LP64 systems, any time at or after
2038-01-19 03:14:08 UTC was truncated, even with a 64-bit time_t:

  $ TZ=UTC busybox awk 'BEGIN { printf "%.0f\n", mktime("2038 01 19 03 14 08") }'
  -2147483648

Return time_t instead and add a testcase.

function                                             old     new   delta
exec_builtin                                        1130    1136      +6
do_mktime                                            119     121      +2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 8/0)                 Total: 8 bytes

Signed-off-by: Michael Pfeifroth <micpf@westermo.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-06 15:33:22 +01:00
Denys Vlasenko 3a381903ce lzop: comment out unused variables
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-05 11:02:54 +01:00
Denys Vlasenko 7e4137b6bd init: set RC_REBOOT=YES if shutdown actions are running for reboot (not shutdown)
function                                             old     new   delta
.rodata                                           104866  104880     +14
check_delayed_sigs                                   341     354     +13
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 27/0)               Total: 27 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-11-05 10:57:54 +01:00
Denys Vlasenko 5eee8017a8 ash: do not read past the text of an unset MAIL
Patch by Florian Schmaus <florian.schmaus@codasip.com>:

ash stores each variable as a single "NAME=value" string in var_text,
and accessor macros like mailval() simply skip over the "NAME=" prefix
(var_text + 5). Per the comment above them, they return the null
string for unset variables. That only works if an unset variable's
text still has a NUL where the value would start.

MAIL and MAILPATH are unset by default, and their initial texts are
"MAIL" and "MAILPATH". For "MAIL" (5 bytes including the NUL)
mailval() therefore points one byte past the end of the string. When
MAILPATH is not set, chkmail() falls back to mailval() and hands that
pointer to padvance_magic(), which parses the memory following "MAIL"
as a colon-separated list of mail files. This happens before every
interactive prompt, unless the user sets MAIL or MAILPATH.

What gets read there depends on the binary layout. In an x86_64
defconfig build "MAIL" is directly followed by "MAILPATH", so ash
stat()s ./MAILPATH before every prompt and prints "you have mail"
when a file of that name in the current directory changes. This
stat() of ./MAILPATH was already noticed in 2016 [1], and the
overread itself was recently reported after fuzzing ash with
AddressSanitizer [2].

The texts used to be "MAIL\0" and "MAILPATH\0", as they still are in
dash. Commit 8837c5dec4 ("ash: remove one redundant function,
improve string sharing, better field names") dropped the extra NUL
from all unset-by-default variables, so the literals become plain
strings the compiler can put in mergeable string sections. That is
fine for RANDOM, LC_ALL, LC_CTYPE and HISTFILE, whose values are only
read through lookupvar(), which checks VUNSET. But mailval() is
used without such a check.

Fix the out-of-bounds read by restoring the trailing NULs for MAIL
and MAILPATH, so that mailval() and mpathval() again yield "" for an
unset variable. This matches setvar(), which already allocates a
zeroed buffer of name length + 2 when unsetting a variable at
runtime. MAILPATH is not strictly affected, since mpathval() is only
used after mpathset(), but this keeps both accessors consistent.
Neither literal is shared with any other string, so the cost is two
bytes of .rodata:

function                                             old     new   delta
.rodata                                           102098  102100      +2

We ran into this on a CHERI [3, 4] system. CHERI's architectural
capabilities bound each memory region precisely, so it catches
out-of-bounds accesses that MMU-based protection misses. Here the
one-byte overread of the "MAIL" string literal is a capability length
violation, and every interactive ash dies with SIGSEGV on start-up.

1: https://github.com/gliderlabs/docker-alpine/issues/163
2: https://github.com/vda-linux/busybox_mirror/issues/47
3: https://www.cl.cam.ac.uk/research/security/ctsrd/cheri/
4: https://codasip.com/solutions/riscv-processor-safety-security/cheri/

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-22 07:31:22 +02:00
Denys Vlasenko 87e54246b6 swapon/off: revert the non-portable change made in 2014: use setmntent, not fopen
function                                             old     new   delta
swap_on_off_main                                     449     474     +25

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-22 06:36:05 +02:00
Denys Vlasenko daf8ec40e0 mount: allow longer /proc/mounts lines
Based on patch by Natanael Copa <ncopa@alpinelinux.org>:

Use a bigger buffer for getmntent_r so we can handle entries
with lines longer that 504 chars.

This solves issue when running `mount -o remount,rw ...` in a docker
container on Fedora 43.

ref: https://github.com/k0sproject/k0s/issues/6774
ref: https://lists.busybox.net/pipermail/busybox/2025-December/091859.html

function                                             old     new   delta
mount_main                                          1219    1259     +40
singlemount                                         1315    1323      +8
verbose_mount                                         94      96      +2
mount_it_now                                         358     359      +1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/0 up/down: 51/0)               Total: 51 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-18 18:44:01 +02:00
Denys Vlasenko 38e2124b32 examples/var_service/dhcp_if/: improve selection of implied router
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-18 18:17:22 +02:00
Denys Vlasenko e58cb22366 volume_id: code shrink
function                                             old     new   delta
resolve_mount_spec                                    87     158     +71
mount_main                                          1211    1219      +8
fsck_device                                          453     451      -2
findfs_main                                           76      74      -2
blkid_main                                            41      39      -2
display_uuid_cache                                   109     105      -4
get_devname_from_uuid                                 56       -     -56
get_devname_from_label                                62       -     -62
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 2/4 up/down: 79/-128)           Total: -49 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-18 16:55:01 +02:00
Denys Vlasenko bad78f5e96 fsck: code shrink, improve code comments on resolve_mount_spec() alloc
function                                             old     new   delta
create_fs_device                                     155     140     -15

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-18 16:31:49 +02:00
Natanael Copa 6fb8efcd6c fsck: resolve LABEL=.../UUID=... spec to device
function                                             old     new   delta
fsck_device                                          433     453     +20

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-18 15:34:07 +02:00
Sören Tempel 9d961aff6f Install lsblk to /bin instead of /usr/bin
On Alpine, the util-linux lsblk utility is installed in /bin and
since BusyBox only gained support for that applet recently, we
should make sure to install it to the same location.

Otherwise, the BusyBox symlink is not overwritten by the lsblk pkg.

Signed-off-by: Sören Tempel <soeren+git@soeren-tempel.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-12 12:35:36 +02:00
Natanael Copa 531d9db7b4 app location for cpio, vi and lspci
Adjust location to where alpine linux installs them

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-12 12:34:42 +02:00
Sören Tempel ec9036610f nologin: Install applet to /sbin instead of /usr/sbin
This is required to retain compatibility with our old custom nologin
applet written in C which was also installed to /sbin.

Compatibility with the old path is required because login shell paths
are hardcoded in /etc/passwd.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-12 12:34:42 +02:00
Sören Tempel 2e57f66cba adduser: default to /sbin/nologin as shell for system accounts
Signed-off-by: Sören Tempel <soeren+git@soeren-tempel.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-12 12:34:42 +02:00
Lauri Tirkkonen 30a8277fa0 blkdiscard: ship link to /sbin instead of /usr/bin
util-linux ships blkdiscard in /sbin, so follow what it does.

Link: https://git.kernel.org/pub/scm/utils/util-linux/util-linux.git/tree/sys-utils/Makemodule.am?id=5a75fb2b9e384c61a4b2afd13fe9bba219d5bd93#n194
Signed-off-by: Lauri Tirkkonen <lauri@hacktheplanet.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-12 12:34:42 +02:00
Denys Vlasenko 45ad4ce552 tests: fix tarball creation
Without this patch, the chmod 644 invocation takes away the executable
bit from the input_dir directory, thus preventing the chmod of the files
within the input_dir directory (due to lack of x-bit).

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-12 00:00:55 +02:00
Sören Tempel de40fe3350 tests: musl doesn't seem to recognize UTC0 as a timezone
UTC works though.

TODO: Figure out if musl /should/ regonize UTC0.

Signed-off-by: Sören Tempel <soeren+git@soeren-tempel.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-11 23:51:14 +02:00
Natanael Copa b58d7e51b0 Add flag for not following symlinks when recursing
function                                             old     new   delta
.rodata                                             7934    7967     +33
diff_longopts                                        253     270     +17
packed_usage                                        1704    1720     +16
diff_main                                           1665    1662      -3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/1 up/down: 66/-3)              Total: 63 bytes

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-11 23:46:42 +02:00
Sören Tempel 97e373643d hexdump: skip additional hexdump test on big-endian systems
This one fails on s390x.

Signed-off-by: Sören Tempel <soeren+git@soeren-tempel.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-11 23:39:01 +02:00
Natanael Copa 7476cd280d hexdump: fix regression with -n4 -e '"%u"'
Fix bug introduced in busybox 1.37.0 that broke kernel builds.

Fixes commit e2287f99fe (od: for !DESKTOP, match output more closely
to GNU coreutils 9.1, implement -s)

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-11 23:36:27 +02:00
Natanael Copa b9f5de0352 wget: add header Accept: */*
Some servers (like https://netfilter.org) returns failure if the Accept
header is missing. Both GNU wget and curl adds this header, so make
busybox do the same.

fixes: https://bugs.busybox.net/show_bug.cgi?id=15982

function                                             old     new   delta
wget_main                                           3120    3144     +24
.rodata                                            79296   79310     +14
wget_user_headers                                     76      84      +8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 46/0)               Total: 46 bytes
   text	   data	    bss	    dec	    hex	filename
 825278	  14260	   2008	 841546	  cd74a	busybox_old
 825324	  14260	   2008	 841592	  cd778	busybox_unstripped

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-11 23:36:27 +02:00
Denys Vlasenko f0e5be9fbc awk: fix handling of literal backslashes in replacement
Follow actual gawk behavior.
    https://www.gnu.org/software/gawk/manual/html_node/Gory-Details.html
Erm... wait. Follow *actual* gawk behavior - as seen in testing,
because even Gory-Details.html do not tell the whole awful truth.

function                                             old     new   delta
awk_sub                                              550     658    +108

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-11 23:15:35 +02:00
Denys Vlasenko 538499b65a ash,hush: fix read builtin versus already-handled signal
function                                             old     new   delta
builtin_read                                         178     205     +27
shell_builtin_read                                  1340    1350     +10
pgetc                                                623     633     +10
dotrap                                               157     164      +7
check_and_run_traps                                  278     285      +7
readcmd                                              227     222      -5
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 5/1 up/down: 61/-5)              Total: 56 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-11 18:17:43 +02:00
Denys Vlasenko fcdc004c5c ash: docunebt that "timed out waiting for input" goes to stdout
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-11 16:05:24 +02:00
Denys Vlasenko 049ae38950 ash,hush: print sugnal-related "beautification" (^C etc) to stderr, not stdout
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-11 15:54:21 +02:00
Denys Vlasenko 1c7e871e0a less: accept/ignore -T TAGFILE
Patch by Sören Tempel <soeren@soeren-tempel.net>

This option is passed by mandoc(1), while we don't implement the
actual functionality here, this patch allows using tagfile support
with mandoc(1) when a more feature-full less(1) implementation is
installed.

Otherwise, we would have to detect support for -T option in the
pager at run-time in mandoc(1), which would occur run-time costs.
Note that other option (-s and -X) are already ignored by BusyBox
less(1), so this seems like a good solution for mandoc(1) compat.

function                                             old     new   delta
less_main                                           2062    2064      +2
.rodata                                           104845  104847      +2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-11 15:52:33 +02:00
Denys Vlasenko 8d4ac0d17b udhcpc: code shrink by reusing "deconfig" code path
function                                             old     new   delta
udhcpc_main                                         2544    2501     -43

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-11 15:52:33 +02:00
Denys Vlasenko 15e0ea385d udhcpc6: code shrink by reusing "deconfig" code path
function                                             old     new   delta
udhcpc6_main                                        2772    2651    -121

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-11 15:52:33 +02:00
Jake Buchholz Göktürk a65bea40f4 udhcpc6: restart acquisition after a zero valid lifetime
A Reply with a zero valid lifetime revokes an address or delegated
prefix. The current client instead applies its minimum lease time and
keeps renewing the revoked lease. When both IA_NA and IA_PD are requested,
the zero can also be replaced by the other IA's nonzero lifetime.

Check the lifetimes of requested IAs before combining or clamping them.
On zero, run deconfig and return to INIT_SELECTING. Clear the requested
address hint, remaining lease, elapsed time and packet counter. Use the
same three-second delay as the existing DHCPv6 NAK recovery path to avoid
repeatedly soliciting an unusable lease. Deconfiguration happens
immediately; the delay applies only to restarting acquisition. This is
an existing implementation convention, not an RFC requirement. Do not
report bound or renew, or honor quit-after-lease, for an unusable lease.

Use option_mask32, which includes the default address request and the
-r no/-l overrides. A zero preferred lifetime with a positive valid
lifetime remains accepted. Stateful address and prefix acquisition
still share one client state: revoking either restarts both.

This addresses the existing zero-lease TODO. It does not implement
independent IA renewal or processing of multiple leases per IA.
Existing partial-Reply handling is unchanged: if a requested companion
IA is missing, the Reply is ignored before this revocation check.

Tested on aarch64: address and prefix revocation, combined leases with
one or both lifetimes zero, replacement acquisition and renewal,
zero first Reply, persistent zero Replies, quit-after-lease, deprecated
addresses, and stateless Information-request. The unpatched baseline
continues renewing revoked state.

Native aarch64, GCC 15.2.0, Alpine configuration; relative to
the preceding patch in this series. Data and BSS are unchanged.

bloat-o-meter:
function                                             old     new   delta
udhcpc6_main                                        3024    3120     +96
.rodata                                            69449   69484     +35
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 131/0)             Total: 131 bytes

Signed-off-by: Jake Buchholz Göktürk <tomalok@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-11 03:08:34 +02:00
Jake Buchholz Göktürk 57c5bba044 udhcpc6: send proper Rebind messages
The REBINDING state uses the Renew packet builder, so its multicast
fallback sends another Renew containing the original server ID. It
cannot ask a different server to extend the lease.

Reuse the existing builder for both message types. Send D6_MSG_REBIND
without a server ID in REBINDING, preserving the client options and
IA_NA/IA_PD contents. Start a new transaction and reset elapsed time
when entering that state; retransmissions retain the transaction ID.
This follows RFC 9915 section 18.2.5 and resolves the TODO in the
REBINDING state asking whether send_d6_renew() should use D6_MSG_REBIND
instead of D6_MSG_RENEW.

Keep the renewal schedule, retry limits, and multicast option behavior
unchanged.

Tested on aarch64 with Alpine's configuration: initial acquisition and
Renew, server failover with IA_NA, IA_PD, and both, Rebind retransmissions,
and stateless Information-request. The unpatched tree loses its lease
in the same failover test. Packet captures verify the message type,
options, transaction ID, and elapsed time.

Native aarch64, GCC 15.2.0, Alpine configuration; relative to
the preceding patch in this series. Data and BSS are unchanged.

bloat-o-meter:
function                                             old     new   delta
static.send_d6_renew                                 208     256     +48
udhcpc6_main                                        3000    3024     +24
.rodata                                            69447   69449      +2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 74/0)               Total: 74 bytes

Signed-off-by: Jake Buchholz Göktürk <tomalok@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-11 02:41:42 +02:00
Jake Buchholz Göktürk 89032255bb udhcp: export IPv6 preferred_lifetime to the script
Export the DHCPv6 preferred address lifetime alongside the existing
valid lifetime in lease.

function                                             old     new   delta
option_to_env                                        711     739     +28
.rodata                                           104781  104808     +27
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 55/0)               Total: 55 bytes

Signed-off-by: Jake Buchholz Göktürk <tomalok@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-11 02:36:32 +02:00
Ron Yorston 5e57539acb test: fix POSIX -nt and -ot when "older" is missing
These should evaluate true if the newer file exists and the older is
missing or older, but it was never true if older is missing.

Note: 'test X -nt Y' is identical to 'test Y -ot X'

  https://pubs.opengroup.org/onlinepubs/9799919799/utilities/test.html

function                                             old     new   delta
binop                                                593     634     +41
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 41/0)               Total: 41 bytes

Signed-off-by: Avi Halachmi (:avih) <avihpit@yahoo.com>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-10 18:29:56 +02:00
Ron Yorston aeaa7f547c ash: PSSYNTAX: preserve \\ in addition to \$
'\\t' in PS1 was incorrectly displayed as a timestamp instead of
the intended '\t' because '\\' was not preserved.

function                                             old     new   delta
readtoken1                                          3072    3079      +7
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 7/0)                 Total: 7 bytes

Signed-off-by: Avi Halachmi (:avih) <avihpit@yahoo.com>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-10 18:28:51 +02:00
Denys Vlasenko 32653c392c libarchive: comment tweak
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-09 16:56:50 +02:00
Denys Vlasenko 382008b3f0 tar: protect against Symlink+Hardlink attack
function                                             old     new   delta
create_links_from_list                                93     190     +97

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-09 16:45:23 +02:00
Denys Vlasenko 5da20102b5 tar: ".." is also an unsafe filename, treat as such
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-09 15:09:26 +02:00
Denys Vlasenko a040aa2826 ash: follow bash in allowing multiple !s: "! ! CMD" is the same as "CMD"
function                                             old     new   delta
pipeline                                             167     165      -2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-09 13:36:11 +02:00
Denys Vlasenko 4a9fe5a0c2 ash: fix !BASH_COMPAT build, tweak variable names, add comments
The work to improve "wait -n" is based on patches by
    Luiz Angelo Daros de Luca <luizluca@gmail.com>
and
    Dominique Martinet <dominique.martinet@atmark-techno.com>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-09 12:26:51 +02:00
Denys Vlasenko e3e1ad1587 ash: fix "wait -n PID %JOBSPEC" behavior
function                                             old     new   delta
dowait_n                                               -     565    +565
waitcmd                                              346     569    +223
getjob_match_last_pid                                  -      29     +29
waitforjob                                           100     103      +3
showjobs                                              56      59      +3
dowait                                               557       -    -557
------------------------------------------------------------------------------
(add/remove: 2/1 grow/shrink: 3/0 up/down: 823/-557)          Total: 266 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-07 23:45:35 +02:00
Denys Vlasenko 30f2f883bd ash: fix "wait -n" behavior wrt already-exited jobs
function                                             old     new   delta
waitcmd                                              318     346     +28
kill_main                                            907     919     +12
dowait                                               553     557      +4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 44/0)               Total: 44 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-07 11:15:37 +02:00
Denys Vlasenko 730f515626 ash: fix !ASH_BASH_COMPAT build
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-07 00:13:59 +02:00
Denys Vlasenko b829bba950 httpd: do not try to use obviously bogus password from /etc/passwd
If password is 'x' or '*' and yet, /etc/shadow has no entry,
do not run the crypt machinery - go to the next entry.

function                                             old     new   delta
check_user_passwd                                    444     462     +18

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-06 00:00:32 +02:00
Ron Yorston f15a204bb2 xxd: '-p -c 0' outputs a single line
vim's xxd allows the combination of options '-p -c 0' to output
a single line of text [1].  A use case is handling cryptographic
material [2].

Add this feature to BusyBox xxd.

[1] https://github.com/vim/vim/pull/9524
[2] https://stackoverflow.com/questions/42192490/aes-cbc-incorrect-usage

function                                             old     new   delta
xxd_main                                            1496    1526     +30
packed_usage                                       35515   35511      -4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 30/-4)              Total: 26 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-05 21:18:44 +02:00
Denys Vlasenko db7dfff800 ash: make "wait -n" pick up last job, if there is no running processes
This is bash compat

function                                             old     new   delta
waitcmd                                              281     318     +37
dowait                                               546     553      +7
waitforjob                                            98     100      +2
showjobs                                              54      56      +2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/0 up/down: 48/0)               Total: 48 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-05 20:43:43 +02:00
Denys Vlasenko ef673ec65a ash: propagate exitstatus to wait -n for correct $? value
function                                             old     new   delta
dowait                                               533     532      -1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-05 17:40:47 +02:00
Denys Vlasenko f4406b2d09 ash: rename "int err" in waitproc() to "pid"
function                                             old     new   delta
dowait                                               530     533      +3

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-05 17:40:47 +02:00
Denys Vlasenko 3920b0a994 ash: dowait: remove incorrect looping
Prev code:

         rpid = 1;
         do {
                 pid = waitone(block, jp);
                 rpid &= !!pid; <<<<<<<<<<<<<<<<<< HERE
                 if (!pid || (jp && jp->state != JOBRUNNING))
                         block = DOWAIT_NONBLOCK;
         } while (pid >= 0);
         return rpid;

If we got pid == 0, it happens in exactly one case:
we did waitpid(WNOHANG), got 0 ("children exist but none yet
changed its state"), then waited for a signal and got one,
which wasn't SIGCHLD.

The above behavior is requested by only one caller: waitcmd()
- the "wait" builtin.

"wait" builtin is required to be interruptible by signals and
to set exitcode to (128 + sig).

Therefore, if we got pid == 0, we don't need to wait
for any more processes. We need to return to waitcmd()
and let it set $? accordingly.

Instead, we do yet another loop.

I'm not saying that we know
that there are no more processes that finished.

I'm saying we don't care at this point: we know
that we are "wait" builtin and we got interrupted by a signal.

Fix this by not looping if "pid == 0" indicates we got a signal.
ONLY loop if we got a pid > 0 and we either do not wait for a specific job,
or this scpecific job is still RUNNING.

function                                             old     new   delta
dowait                                               546     530     -16

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-05 17:40:47 +02:00
Denys Vlasenko e054f9fb4b ash: waiting machinery: add comments explaining the code
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-05 17:40:47 +02:00
Denys Vlasenko cdd442ebd2 ash: waitproc: unobfuscate and explain what the code does
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-05 17:40:47 +02:00
Wojtek Kaniewski 85efaab179 id: Fix output in case of groups error
On a severely constrained system (m68k-nommu) I got confusing output from
`id` command:

    ~ # id
    uid=0 gid=0id: can't get groups

After this change it's a bit more readable:

    ~ # id
    uid=0 gid=0
    id: can't get groups

function                                             old     new   delta
id_main                                              474     484     +10

Signed-off-by: Wojtek Kaniewski <wojtekka@toxygen.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-05 00:52:46 +02:00
Denys Vlasenko 6644e8376e ash simplify PS1 initialization
function                                             old     new   delta
.rodata                                           104788  104781      -7
init                                                 432     422     -10
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-17)             Total: -17 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-05 00:36:08 +02:00
Denys Vlasenko 93bacaa199 ash: remove stray semicolon to fix prompt in !EDITING_FANCY_PROMPT case
Patch by Robert Sandholzer.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-05 00:35:36 +02:00
Michele Dionisio via busybox e65b560038 chrt: add -R to set SCHED_RESET_ON_FORK
Add the -R option, as in util-linux's chrt, which ORs the
SCHED_RESET_ON_FORK flag into the policy passed to sched_setscheduler().
Children created by fork() then do not inherit privileged scheduling
policies and priorities.

Provide a fallback definition of SCHED_RESET_ON_FORK for libcs whose
headers lack it, so the #ifdef around the flag masking in the -p query
path is no longer needed.

function                                             old     new   delta
chrt_main                                            474     501     +27
packed_usage                                       36406   36428     +22
.rodata                                           104787  104788      +1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 50/0)               Total: 50 bytes

Signed-off-by: Michele Dionisio <michele.dionisio@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-04 19:41:03 +02:00
Karthik D K c6c7ab979e libbb: enable fixed 4k pagesize on RISC-V
function             old     new   delta
dd_main             2728    2760     +32
time_main           1300    1288     -12
procps_scan          884     868     -16
devmem_main          648     632     -16
hexedit_main        1416    1392     -24
mkswap_main          408     372     -36
alloc_buf             64       -     -64
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/5 up/down: 32/-168)  Total: -136 bytes

Signed-off-by: Karthik D K <karthikdk1998@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-04 18:40:20 +02:00
Harald van Dijk f96d33d28a printf: fix handling of omitted arguments
For numeric formats, this is meant to behave as a "0" literal zero
argument, not an "" empty string argument.

Add a test to ensure that an explicit "" empty string argument still is
treated as an error.

function                                             old     new   delta
printf_main                                          837    1209    +372
print_direc                                          432       -    -432
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/0 up/down: 372/-432)          Total: -60 bytes

Signed-off-by: Harald van Dijk <harald@gigawatt.nl>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-04 17:48:06 +02:00
Denys Vlasenko b68024b2b8 fatlabel: do not require the 55,AA "bootable" signature
function                                             old     new   delta
fatlabel_main                                        396     384     -12

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-04 17:27:43 +02:00
Denys Vlasenko 4da3f6df05 fatlabel: require dir_entries = 0 in FAT32 check; fix typos
function                                             old     new   delta
fatlabel_main                                        392     396      +4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-04 17:00:56 +02:00
Denys Vlasenko 4366618a25 tls_aes: use bytes for AES state
This is not a code size win on i686. It is "accidentally" a win on x86_64:
my gcc stops trying to use SSE operations for xoring, which is smaller code.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-04 03:03:37 +02:00
Denys Vlasenko ca70514d85 tftp: fix maximum allowed block size from 65564 to 65464 (location #2)
Patch by Valentin. He did send the patch. Which I didn't notice
in the email, decided "bug clear enough, can do it myself",
missed the second location with a buggy constant,
forgot to attribute the fix, and made *two* typos in the commit message.
:(

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-04 01:28:33 +02:00
Denys Vlasenko 0625fac9fe tftp: fix maximum allowed blcok size form 65564 to 65464
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-03 15:26:15 +02:00
Denys Vlasenko 14f6b6b580 bunzip2: reject blocks whose run-length count overflows
Based ob the patch by Matt Turner <mattst88@gmail.com>:
> get_next_block() accumulates a run length in the unsigned 32-bit runCnt:
>
>         runCnt += (runPos << nextSym);
>
> A crafted stream with a long enough RUNA/RUNB sequence can drive runCnt
> up to ~2^32. Once it is that large, the existing guard
>
>         if (dbufCount + runCnt > bd->dbufSize)
>
> is bypassed: dbufCount + runCnt overflows the unsigned addition and
> wraps to a small value, so the check passes. The following
> byteCount[tmp_byte] += runCnt then overflows byteCount[] (an int) to a
> negative value. The inverse Burrows-Wheeler sort loop computes negative
> cumulative offsets from it and writes before the start of dbuf[], an
> out-of-bounds heap write (confirmed with AddressSanitizer as a write 48
> bytes before the dbuf allocation).

function                                             old     new   delta
get_next_block                                      1452    1458      +6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-02 20:35:04 +02:00
Denys Vlasenko 904511662e nmeter: make it able to sleep for hours: -d %((60*60*1000))
function                                             old     new   delta
nmeter_main                                          786    1031    +245
packed_usage                                       36379   36406     +27
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 272/0)             Total: 272 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-01 17:28:51 +02:00
Denys Vlasenko c824119226 nmeter: document why %[nIF] format prepends a space
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-10-01 15:48:05 +02:00
Denys Vlasenko e6302b2711 swapon: with no arguments, show /proc/swaps (mimic util-linux 2.41.1)
function                                             old     new   delta
swap_on_off_main                                     419     449     +30

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-29 00:00:42 +02:00
Denys Vlasenko e8cb0a1d14 fdisk: util-linux compat wrt meaning of -u
function                                             old     new   delta
menu                                                 261     282     +21
.rodata                                           104779  104787      +8
packed_usage                                       36390   36379     -11
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 29/-11)             Total: 18 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-28 18:07:32 +02:00
Denys Vlasenko c1289d58d5 fdisk: add a test of adding a 1-sector primary partition
function                                             old     new   delta
packed_usage                                       36323   36390     +67
read_int                                             450     457      +7
read_line_input                                     2664    2669      +5
get_boot                                            1426    1423      -3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/1 up/down: 79/-3)              Total: 76 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-28 17:24:03 +02:00
Denys Vlasenko 928b0384cf fdisk: more readable code in read_extended_chain()
function                                             old     new   delta
get_boot                                            1426    1423      -3

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-28 12:22:10 +02:00
Denys Vlasenko ccf1e30fa2 fdisk: consider partition empty only when it's all-zeros, not merely type 0
Our own message in the source says that Linux does not consider type 0
as "empty". (Linux thinks that size of 0 sectors means "empty").

function                                             old     new   delta
verify                                               726     767     +41
wrong_p_order                                         86     119     +33
get_geometry                                         437     460     +23
get_boot                                            1412    1426     +14
fill_bounds                                          115     124      +9
x_dos_print_disklabel                                227     232      +5
delete_partition                                     334     337      +3
add_logical                                          106     109      +3
fdisk_main                                          2590    2576     -14
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 8/1 up/down: 131/-14)           Total: 117 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-28 11:44:00 +02:00
Denys Vlasenko bfdf3560d6 fdisk: DOS compat flag off by default - mimic util-linux 2.41.1
function                                             old     new   delta
fdisk_main                                          2610    2590     -20

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-28 11:16:02 +02:00
Denys Vlasenko 4c9b0e45da fdisk: in add_partition(), only fully zeroed partition entry is free
function                                             old     new   delta
add_partition                                       1038    1041      +3

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-28 04:04:56 +02:00
Denys Vlasenko 152c6227d0 fdisk: simplify new_partition()
function                                             old     new   delta
input_partition_number                                 -      73     +73
fdisk_main                                          2547    2610     +63
get_partition                                         73       -     -73
get_nonexisting_partition                            100       -    -100
.rodata                                           104879  104779    -100
------------------------------------------------------------------------------
(add/remove: 1/2 grow/shrink: 1/1 up/down: 136/-273)         Total: -137 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-28 03:23:26 +02:00
Denys Vlasenko 659644d8d6 fdisk: explain how extended partitions work on-disk
Improve messages about "DOS compatibility flag"

function                                             old     new   delta
menu                                                 231     261     +30
valid_55AA_signature                                   -      26     +26
fdisk_main                                          2534    2547     +13
get_boot                                            1406    1412      +6
valid_part_table_flag                                 26       -     -26
.rodata                                           104913  104879     -34
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 3/1 up/down: 75/-60)             Total: 15 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-28 02:49:08 +02:00
Denys Vlasenko 25c50c4805 fdisk: remove "devfs kludge"
function                                             old     new   delta
partname                                             184     136     -48

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-27 23:21:23 +02:00
Denys Vlasenko 03293bc06c fdisk: remove dead code in open_list_and_close()
delete_partition() which deals with extended partition is unnecessary
since we are inside "fdisk -l".
"if (LABEL_IS_AIX) ..." is false since only after successful get_boot()
we can have a detected AIX label.

function                                             old     new   delta
open_list_and_close                                  424     392     -32

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-27 22:57:52 +02:00
Denys Vlasenko 3fc725d413 fdsik: reduce local char mesg[256] to [64]
function                                             old     new   delta
add_partition                                       1246    1038    -208

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-27 22:50:02 +02:00
Denys Vlasenko dcb8ae589b fdisk: group menu functions together
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-27 22:31:46 +02:00
Denys Vlasenko ef63f4dec2 fdisk: standardize on XYZ_print_disklabel() as the function for 'p'
list_disk_name_and_sizes() shouldn't be used by gpt's print_disklabel(),
just use it unconditionally for all partition types.

function                                             old     new   delta
static.print_disklabel                                 -     775    +775
x_dos_print_disklabel                                  -     227    +227
print_disk_name_and_sizes                              -      80     +80
print_disk_geometry                                    -      66     +66
open_list_and_close                                  419     424      +5
.rodata                                           104928  104913     -15
list_disk_geometry                                    71       -     -71
list_disk_name_and_sizes                              80       -     -80
x_list_table                                         227       -    -227
static.list_table                                    775       -    -775
------------------------------------------------------------------------------
(add/remove: 4/4 grow/shrink: 1/1 up/down: 1153/-1168)        Total: -15 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-27 20:32:07 +02:00
Denys Vlasenko 6853c796be fdisk: rename bsd_select() -> if_osf_label_loop_in_menu_until_r()
Much clearer to read the call site.
While at it, shiffle fdisk_osf.c to reduce forward references.
Shorten sprintf() in xbsd_get_part_index().

function                                             old     new   delta
if_osf_label_loop_in_menu_until_r                      -    1546   +1546
xbsd_get_part_index                                   69      67      -2
bsd_select                                          1546       -   -1546
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 0/1 up/down: 1546/-1548)         Total: -2 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-27 19:44:34 +02:00
Denys Vlasenko 4839711dce fdisk: consistently use uint8_t (not char) for binary data
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-27 19:00:36 +02:00
Denys Vlasenko e5588888c8 fdisk: rename struct partition to dos_partition
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-27 18:34:08 +02:00
Denys Vlasenko 8ce86eb361 fdisk: show "Changes will remain in memory only" more prominently
function                                             old     new   delta
.rodata                                           104735  104928    +193
fdisk_main                                          2522    2534     +12
create_doslabel                                       99      93      -6
msg_part_already_defined                              61       -     -61
msg_building_new_label                               142       -    -142
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 2/1 up/down: 205/-209)           Total: -4 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-27 18:29:42 +02:00
Denys Vlasenko 8c43e2409e fdisk: make write_table_and_exit() NORETURN
function                                             old     new   delta
write_table_and_exit                                   -     153    +153
fdisk_main                                          2537    2522     -15
write_table                                          159       -    -159
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 0/1 up/down: 153/-174)          Total: -21 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-27 18:10:34 +02:00
Denys Vlasenko fbfc949b26 fdisk: remove get_boot() -> create_doslabel() -> get_boot() recursion
It works, but
get_boot() [table is bad] -> create_doslabel() -> get_boot(CREATE_EMPTY_DOS)
is a mind bender

function                                             old     new   delta
dos_reset_primary_partition_info                       -      73     +73
get_existing_partition                               113     110      -3
fdisk_main                                          2543    2537      -6
create_doslabel                                      108      99      -9
get_boot                                            1477    1406     -71
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/4 up/down: 73/-89)            Total: -16 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-27 18:02:02 +02:00
Denys Vlasenko 946aba349c fdisk: remove vestiges of SUN and SGI labels support
function                                             old     new   delta
menu                                                 262     231     -31
.rodata                                           104770  104735     -35
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-66)             Total: -66 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-27 16:46:13 +02:00
Denys Vlasenko e1aeba03f4 fdisk: remove SUN and SGI labels support - obsolete (20+ years)
function                                             old     new   delta
static.list_table                                      -     775    +775
packed_usage                                       36304   36323     +19
read_int                                             434     450     +16
fdisk_swap32                                           3       -      -3
open_list_and_close                                  431     419     -12
verify                                               742     726     -16
partition_type                                        49      28     -21
get_partition                                        100      73     -27
menu                                                 293     262     -31
read_maybe_empty                                      38       -     -38
verify_sun_cmp                                        39       -     -39
get_boot                                            1532    1477     -55
sun_sys_types                                         56       -     -56
write_table                                          251     159     -92
delete_partition                                     432     334     -98
set_sun_partition                                    100       -    -100
get_geometry                                         538     437    -101
print_buffer                                         102       -    -102
fetch_sun                                            207       -    -207
check_sun_label                                      208       -    -208
sun_autoconfigure_scsi                               395       -    -395
verify_sun                                           447       -    -447
sun_drives                                           456       -    -456
new_partition                                       1066       -   -1066
list_table                                          1370       -   -1370
fdisk_main                                          4622    2543   -2079
.rodata                                           107469  104770   -2699
------------------------------------------------------------------------------
(add/remove: 1/13 grow/shrink: 2/11 up/down: 810/-9718)     Total: -8908 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-27 16:38:02 +02:00
Denys Vlasenko 274a087cdc *: users of get_volume_size_in_bytes() should open their file O_RDWR
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-26 19:52:10 +02:00
Denys Vlasenko 69dd61ccbf nc: show connect() errors always, not only with -v or -vv
function                                             old     new   delta
display                                             1485    1481      -4
nc_main                                             1018     992     -26
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-30)             Total: -30 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-26 19:45:56 +02:00
Denys Vlasenko 13562b9351 volume_id: add FAST_FUNCs
function                                             old     new   delta
volume_id_set_unicode16                              167     181     +14
volume_id_probe_btrfs                                131     139      +8
volume_id_probe_vfat                                 824     830      +6
volume_id_probe_sysv                                 188     193      +5
volume_id_probe_romfs                                 97     100      +3
volume_id_probe_iso9660                              315     316      +1
volume_id_probe_nilfs                                 97      96      -1
volume_id_probe_lfs                                   59      58      -1
volume_id_probe_ext                                  122     121      -1
volume_id_probe_erofs                                 86      85      -1
volume_id_probe_reiserfs                             243     241      -2
volume_id_probe_linux_raid                           128     126      -2
volume_id_free_buffer                                 67      65      -2
volume_id_probe_xfs                                   98      95      -3
volume_id_probe_ocfs2                                107     104      -3
volume_id_probe_linux_swap                           248     245      -3
volume_id_probe_jfs                                  107     104      -3
volume_id_probe_bcache                               104     101      -3
volume_id_set_label_string                            81      77      -4
volume_id_probe_ubifs                                 64      60      -4
volume_id_probe_squashfs                              83      79      -4
volume_id_probe_minix                                 82      78      -4
volume_id_probe_f2fs                                 104     100      -4
volume_id_probe_cramfs                                64      60      -4
volume_id_get_buffer                                 372     368      -4
volume_id_probe_luks                                  89      83      -6
volume_id_probe_udf                                  538     531      -7
volume_id_probe_exfat                                282     275      -7
volume_id_set_label_unicode16                         31      23      -8
volume_id_probe_ntfs                                 285     277      -8
volume_id_probe_all                                  123     113     -10
volume_id_set_uuid                                   178     166     -12
volume_id_probe_hfs_hfsplus                          494     470     -24
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 6/27 up/down: 37/-135)          Total: -98 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-24 16:20:36 +02:00
Denys Vlasenko 30d2839a7c fatlabel: new applet
function                                             old     new   delta
fatlabel_main                                          -     392    +392
.rodata                                           107413  107469     +56
applet_names                                        2885    2894      +9
applet_main                                         1660    1664      +4
packed_usage                                       36307   36304      -3
swaplabel_main                                       274     270      -4
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 3/2 up/down: 461/-7)            Total: 454 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-24 11:52:58 +02:00
Denys Vlasenko f5c0543fd1 swaplabel: new applet
While at it, make get_volume_size_in_bytes() messages more informative;
do not write to file unless _have to_ extend it.

function                                             old     new   delta
swaplabel_main                                         -     274    +274
.rodata                                           107344  107413     +69
get_volume_size_in_bytes                             221     262     +41
bb_SWAPSPACE2                                          -      10     +10
applet_names                                        2875    2885     +10
packed_usage                                       36298   36307      +9
applet_main                                         1656    1660      +4
applet_install_loc                                   207     208      +1
SWAPSPACE2                                            10       -     -10
------------------------------------------------------------------------------
(add/remove: 3/1 grow/shrink: 6/0 up/down: 418/-10)           Total: 408 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-24 02:21:18 +02:00
Denys Vlasenko d3c8cfa674 tr: special-case "\-" before trying to parse it as escape
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-23 06:41:53 +02:00
Ron Yorston 0e09d2f857 tr: an escaped dash doesn't indicate a range
Commit d683c5c2f1 (tr: support octal ranges) broke the previous
behaviour that an escaped dash doesn't indicate a range:
'[p\-r]' should match 'p', '-' or 'r', not 'p', 'q' or 'r'.

Add a special case to handle this.

function                                             old     new   delta
expand                                               641     657     +16
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 16/0)               Total: 16 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-23 06:41:53 +02:00
Denys Vlasenko a21eaf440d *: fix Unicode damage
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-23 02:53:30 +02:00
Denys Vlasenko c9e11ef570 telnet: make put_iac_subopt_XYZ() more readable
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-23 02:23:46 +02:00
Denys Vlasenko 5cea24cf6c telnet: remove superfluous bit clearing
function                                             old     new   delta
write_to_net                                         625     621      -4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-23 02:07:23 +02:00
Denys Vlasenko bf9ebfe168 wget: fix progress bar and message placement on unexpected EOF (and retry)
Correct behavior: "wget: connection closed..." on new line:

$ wget http://127.0.0.1/50g -O/dev/null
Connecting to 127.0.0.1 (127.0.0.1:80)
saving to '/dev/null'
null                   8% |**                       | 4531M  0:00:30 ETA
wget: connection closed at byte 4751158460
Connecting to 127.0.0.1 (127.0.0.1:80)
saving to '/dev/null'
null                  10% |***_

function                                             old     new   delta
progress_meter                                       182     195     +13
retrieve_file_data                                   705     697      -8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 13/-8)               Total: 5 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-23 01:25:45 +02:00
Denys Vlasenko 218f328625 wget: support multiple restarts, -t NUM controls how many
function                                             old     new   delta
retrieve_file_data                                   621     705     +84
wget_main                                           2581    2657     +76
ftpcmd                                               133     151     +18
packed_usage                                       36282   36298     +16
get_sanitized_hdr                                    150     156      +6
fgets_trim_sanitize                                  134     137      +3
reset_beg_range_to_zero                               44      46      +2
.rodata                                           107342  107344      +2
progress_meter                                       189     182      -7
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 8/1 up/down: 207/-7)            Total: 200 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-23 00:36:36 +02:00
Denys Vlasenko 61e244e5ee dpkk: stop allowing spaces in NAME: parts. Debian does not do this, it seems
Add mode docs in comments. We probably do not follow them correctly yet.

function                                             old     new   delta
read_package_field                                   211     170     -41

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-22 16:12:33 +02:00
Denys Vlasenko 39c2dc8c49 httpd: document that P: proxying is not checking passwords
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-22 13:26:19 +02:00
Denys Vlasenko e97224f8fb tls: fix off-by-one access past the end of the received packet.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-22 02:38:38 +02:00
Denys Vlasenko c2dec52d37 libpwdgrp: tokenizer fix for trailing whitespace removeal.
The tokenize() function trims trailing whitespace via
overlapping_strcpy() but continues to reference the stale *end
pointer. Fixing this.

function                                             old     new   delta
tokenize                                             120     119      -1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-22 02:19:06 +02:00
Denys Vlasenko 556567f403 mount: document a possible bug in comment, no code changes.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-22 01:55:03 +02:00
Denys Vlasenko 9f5cbdcaa5 httpd: allow yescrypt passwords ("$y$....")
function                                             old     new   delta
check_user_passwd                                    439     444      +5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-22 01:14:47 +02:00
Denys Vlasenko d5cc94063b dpkg: fix field handling in write_status_file()
function                                             old     new   delta
dpkg_main                                           3943    3934      -9

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-22 01:05:07 +02:00
Denys Vlasenko 7a055991de dpkg: improve --help
function                                             old     new   delta
packed_usage                                       36247   36282     +35

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-22 00:48:46 +02:00
Denys Vlasenko e8a55de7ec dpkg-deb: add a rudimentary test
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-21 23:34:12 +02:00
Denys Vlasenko 6b366627e1 dpkg: remove const from non-pointer variables
This does not improve anything, only makes code more verbose.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-21 23:32:37 +02:00
Denys Vlasenko 89a2512144 dpkg: code shrink by improving make_hash() API
function                                             old     new   delta
search_status_hashtable                              109     113      +4
search_name_hashtable                                104     103      -1
make_hash                                            116     113      -3
search_package_hashtable                             120      99     -21
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/3 up/down: 4/-25)             Total: -21 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-21 22:33:15 +02:00
Denys Vlasenko bef7bcf4ce dpkg: improve --help
function                                             old     new   delta
packed_usage                                       36243   36247      +4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-21 22:30:23 +02:00
Denys Vlasenko 21f9c36676 dpkg: avoid strlen in fill_package_struct()
function                                             old     new   delta
fill_package_struct                                  306     291     -15

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-21 17:16:17 +02:00
Denys Vlasenko 7c611860df dpkg: deindent read_package_field(), rename variables. No logic changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-21 17:13:27 +02:00
Denys Vlasenko f5a4a02a15 dpkg: fix cases where read_package_field() returns offset past NUL
function                                             old     new   delta
read_package_field                                   169     211     +42

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-21 16:59:56 +02:00
Denys Vlasenko 43a9d7d315 dpkg: reformat code in read_package_field(), exposing why it's buggy
function                                             old     new   delta
read_package_field                                   184     169     -15

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-21 16:32:43 +02:00
Denys Vlasenko e2c5cc0420 dpkg: free results of read_package_field(), preliminary cleanups in read_package_field()
function                                             old     new   delta
dpkg_main                                           3910    3943     +33
write_buffer_no_status                                92     114     +22
read_package_field                                   204     184     -20
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 55/-20)             Total: 35 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-21 16:16:47 +02:00
Denys Vlasenko fd1972099f udhcpc: ensure packet.data.cookie exists before we access it
function                                             old     new   delta
d4_recv_raw_packet                                   497     500      +3

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-21 12:15:19 +02:00
Denys Vlasenko 9073c1d15c volume_id/romfs: limit the maximum size of label to VOLUME_ID_LABEL_SIZE
function                                             old     new   delta
volume_id_set_label_string                            71      81     +10
volume_id_probe_romfs                                 94      97      +3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 13/0)               Total: 13 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-21 05:34:19 +02:00
Denys Vlasenko d0143f8da1 httpd: remove one unnecessary check
function                                             old     new   delta
scan_ip                                              170     165      -5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-21 05:20:06 +02:00
Denys Vlasenko 339e3c62f5 httpd: fix handling of "D:1.2.3/999"
An error in allow/deny rule should be interpreted as D:0/0
("deny all") but was interpreted as D:IP/0. Fix this.

function                                             old     new   delta
parse_conf                                          1323    1330      +7

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-21 04:40:37 +02:00
Denys Vlasenko 89ac82774f tls: fix undersized buffer calculation
All callers of pstm_montgomery_reduce() are currently in pstm_exptmod()
and they all pass a preallocated temporary buffer, so the incorrect code
is unreachable. But fix it anyway.

function                                             old     new   delta
pstm_montgomery_reduce                               431     430      -1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-21 03:20:39 +02:00
Denys Vlasenko 1b4f8e2a87 awk: allow OFMT='prefix:%SPEC suffix with %%'
function                                             old     new   delta
fmt_num                                              380     394     +14

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-09-14 01:46:32 +02:00
Ali Ahmet Memis 74ac096e89 sort: compute -k END.ENDCHAR from the end field, not the line start
get_key() locates a key in two passes: j=0 walks to the start of the
START field, j=1 walks to the end of the END field. When END carries
an ENDCHAR (-kSTART,N.ENDCHAR), that char position is supposed to be
counted from the start of field N. Instead the code overwrote 'end'
with the raw parsed value, an offset from the very start of the line:

	if (key->range[3]) {
		end = key->range[3];

For END field 1 this happens to be the same thing, but for any later
field it is not. The result usually lands before 'start', which then
gets clamped to 'start', producing an empty key. Sort has an ASCII
whole-line fallback when keys tie, so it silently sorts by the whole
line instead of the requested key:

	$ printf '%s\n' 'b:aa' 'a:ba' 'a:aa' | busybox sort -t : -k 2.1,2.1
	a:aa
	a:ba
	b:aa
	$ printf '%s\n' 'b:aa' 'a:ba' 'a:aa' | sort -t : -k 2.1,2.1
	a:aa
	b:aa
	a:ba

Make the j=1 pass stop at the start of field N instead of its end when
ENDCHAR is given, one field-skip short of the usual pass, and add the
ENDCHAR offset from there. This mirrors how STARTCHAR is already
applied relative to the start of the START field. Verified against
several -k combinations (endchar past the field's own length, multiple
fields skipped, startchar and endchar together) matching GNU sort.

Add a regression test; the existing ENDCHAR test only exercises field
1, where the old absolute offset and the correct field-relative one
happen to coincide.

function                                             old     new   delta
get_key                                              490     516     +26

Signed-off-by: Ali Ahmet Memis <ali@iusegentoo.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-08-31 22:54:31 +02:00
Denys Vlasenko 8f4dc3b405 platform.h: UNINITIALIZED_VAR() macro for suppressing gcc warnings
With gcc-15.0.1:

function                                             old     new   delta
tftpd_main                                           603     617     +14
expand_one_var                                      1923    1929      +6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 20/0)               Total: 20 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-08-31 20:03:33 +02:00
Denys Vlasenko c8047030dc vi: explain what vim 9.2 is doing with ":e FILE" escaping
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-08-31 16:50:46 +02:00
Denys Vlasenko 6ab4e2a0de vi: code shrink
function                                             old     new   delta
expand_args                                          186     181      -5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-08-31 10:21:20 +02:00
Denys Vlasenko 7406d7a74f inetd: build fix if RPC is selected in .config
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-08-31 02:00:36 +02:00
Denys Vlasenko fe215e35d6 devfsd: heed warnings
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-08-31 01:55:03 +02:00
Denys Vlasenko 452a4f1ad5 hush: heed warnings about strchr() returning const char*
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-08-31 01:14:51 +02:00
Denys Vlasenko 6885d4c310 *: selinux: replace deprecated security_context_t with char*
Suppresses a lot of selinux warnings.
This does not change the code.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-08-31 01:02:03 +02:00
Romain Guyard 4a2a446472 hdparm: fix ATA identification string output
print_ascii() is intended to skip leading spaces before printing ATA
IDENTIFY strings, but the condition is inverted and skips non-space
characters instead.

As a result, left-justified strings such as serial numbers and firmware
revisions can be printed as empty, while strings containing embedded
spaces, such as model names, are truncated up to the first space.

Fix the condition so only leading spaces are skipped, and add a regression
test covering left-justified strings, embedded spaces, and leading-space
padding.

function                                             old     new   delta
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/0 up/down: 0/0)                 Total: 0 bytes

Signed-off-by: Romain Guyard <foss@romainguyard.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-08-30 20:06:15 +02:00
Denys Vlasenko 9958bbd70a awk: disallow OFMT/CONVFMT to have more than one %SPEC, implement %s
function                                             old     new   delta
fmt_num                                              257     380    +123
.rodata                                           107332  107342     +10
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 133/0)             Total: 133 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-08-30 18:55:07 +02:00
Anton Skorup 436223e2b7 tar: Sanitize verbose file names
function                                             old     new   delta
writeTarHeader                                       859     869     +10

Signed-off-by: Anton Skorup <anton.skorup@axis.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-08-30 13:27:23 +02:00
Ediz 15666f3e9a awk: fix 1-byte heap-buffer-overflow in next_token() string parse
When the awk program ends with \<newline> right after the last string
token, nextchar() eats the newline and then reads the terminating NUL
that xmalloc_read_with_initial_buf() appends, advancing past the end
of the buffer. The string-scan loop in next_token() then dereferences
one byte past the buffer (heap-buffer-overflow, READ of size 1).

Fix: test every nextchar() return for NULs.

Reproducer (ASan build):
awk 'BEGIN { print "string\
'

function                                             old     new   delta
next_token                                           934     933      -1

Signed-off-by: Ediz <ediz.research@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-08-24 10:56:25 +02:00
Denys Vlasenko 92ad65c3a2 stat: code shrink
function                                             old     new   delta
printf_llu                                             -      35     +35
printf_lx                                              -      30     +30
printf_lu                                              -      30     +30
printf_s                                               -      28     +28
printfs                                               28       -     -28
print_statfs                                         338     260     -78
print_stat                                           858     761     -97
------------------------------------------------------------------------------
(add/remove: 4/1 grow/shrink: 0/2 up/down: 123/-203)          Total: -80 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-08-24 09:49:01 +02:00
Benjamin Robin a61d158d54 stat: fix negative %X/%Y/%Z timestamps after Y2038 on 32-bit builds
Introduce a utility function to always print `time_t` values using either
`long long` or `unsigned long long`, depending on whether `time_t` is
signed. This fixes the bug reported in [1].

Previously, `time_t` values were cast to `long`, which is a 32-bit value
on 32-bit builds.

[1]: https://lists.busybox.net/pipermail/busybox/2026-August/092413.html

function                                             old     new   delta
print_stat                                           869     858     -11

Signed-off-by: Benjamin Robin <benjamin.robin@bootlin.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-08-24 09:27:10 +02:00
Thorsten B 7473045ad3 tar: fix verbose output with extract-to-stdout
Combining the verbose (-v) and extract-to-stdout (-O) options caused
verbose output and extracted file data to be interleaved unpredictably on
stdout. Verbose listing uses buffered stdio (printf()/puts()), while file
contents are written directly to the stdout file descriptor.

GNU tar also combines buffered verbose output with unbuffered writes for
"-vO", however, GNU tar writes verbose output to stderr, so the two streams
remain separate and consistent.

Fix this by making "tar xvO" send output to stderr.

function                                             old     new   delta
header_verbose_list                                  244     279     +35
header_list                                           15      49     +34
get_header_tar                                      1764    1769      +5
header_verbose_list_ar                                77      78      +1
get_header_ar                                        542     540      -2
get_header_cpio                                      959     948     -11
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/2 up/down: 75/-13)             Total: 62 bytes

Signed-off-by: Thorsten B <brehmt@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-08-10 06:30:18 +02:00
Ron Yorston d057384504 rpm2cpio: print name of unknown compression method
Commit f13f68288 (rpm2cpio: extract cpio even if compression is
not known) added an error message if the compression method was
unknown.  When support for lzma was disabled this resulted in a
null pointer being passed to bb_error_msg().

The call to rpm_getstr0() to fetch the name of the compression
method shouldn't depend on lzma being supported.

This doesn't affect the size of a default build.  In a build with
lzma disabled:

function                                             old     new   delta
rpm2cpio_main                                        110     121     +11
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 11/0)               Total: 11 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-08-10 05:36:59 +02:00
Ron Yorston fce9d7f35e shell: correctly count backslashes in read built-in
When the read built-in's '-n' option is used to limit the number
of characters read, backslashes should only be counted if the '-r'
option is also suppiled.  This matches how bash behaves.

function                                             old     new   delta
shell_builtin_read                                  1360    1358      -2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-2)               Total: -2 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-08-09 06:51:46 +02:00
Denys Vlasenko 9ad78b4180 shell: read: if poll() fails, attempt to process any data collected so far
This was already done on read() failure, why not on poll()?
Making it consistent.

function                                             old     new   delta
shell_builtin_read                                  1318    1308     -10

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-08-09 06:49:14 +02:00
Ron Yorston 9b21bb0f89 patch: handle files with no final newline
GNU and BSD patch both handle patches which include the annotation
'\ No newline at end of file'.  BusyBox patch doesn't, even though
its diff emits it.

Implement this feature and add some tests.

function                                             old     new   delta
patch_main                                          1912    2002     +90
do_line                                               88     116     +28
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 118/0)             Total: 118 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-08-09 06:39:10 +02:00
Denys Vlasenko 3db20fa07b grep: support --quiet
function                                             old     new   delta
static.grep_longopts                                   -      17     +17
packed_usage                                       36237   36243      +6
.rodata                                           107341  107332      -9
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/1 up/down: 23/-9)              Total: 14 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-07-24 18:38:38 +02:00
Denys Vlasenko ec0c5cc142 cp: fix --sparse to have mandatory argument, fix --remove-destination bit position
cp --remove-destination was broken by commit 56bbbfae "cp: implement -n"

function                                             old     new   delta
cp_main                                              527     533      +6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-07-14 23:14:24 +02:00
Denys Vlasenko 17908bf760 cp: accept --sparse=ANYTHING
function                                             old     new   delta
cp_main                                              514     527     +13
.rodata                                           107332  107341      +9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 22/0)               Total: 22 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-07-14 19:00:02 +02:00
Denys Vlasenko 8f0533c576 join: code shrink by making some variables "global"
function                                             old     new   delta
readfields                                           442     437      -5
printfields                                          462     457      -5
join_main                                            843     760     -83
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-93)             Total: -93 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-07-08 14:38:07 +02:00
Ron Yorston a058289401 join: new applet
function                                             old     new   delta
join_main                                              -     843    +843
printfields                                            -     462    +462
readfields                                             -     442    +442
.rodata                                           107120  107332    +212
packed_usage                                       36078   36237    +159
applet_names                                        2870    2875      +5
applet_main                                         1652    1656      +4
------------------------------------------------------------------------------
(add/remove: 4/0 grow/shrink: 4/0 up/down: 2127/0)           Total: 2127 bytes
   text	   data	    bss	    dec	    hex	filename
1080964	    555	   4992	1086511	 10942f	busybox_old
1083091	    555	   4992	1088638	 109c7e	busybox_unstripped

v2: Add a missing return statement which broke the '-t' option.
    Thanks to Roberto A. Foglietta for pointing this out.

Signed-off-by: Morgan Bartlett <mjmouse9999@gmail.com>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-07-08 07:01:03 +02:00
Sanghyun Park a448b6d5b2 ash: fix out-of-bounds read in ifsbreakup()
ifsfree() does not only release allocated ifsregion nodes; it also clears
the global IFS region state used by ifsbreakup(). If argstr() raises an
error while expanding an argument, ash longjmps out of expandarg() before
that cleanup runs, leaving stale IFS split offsets behind.

A later expansion can reuse the stack for a shorter string. ifsbreakup()
then sees the stale IFS state, trusts the old offsets, and can walk past
the current stack block before dereferencing p.

Follow dash's root-cause fix: when an expansion-related handler catches
EXERROR and continues, restore the handler and call ifsfree(). Apply
the cleanup to redirectsafe(), expandstr(), and evaltree().

Upstream commit:

    Date:   Mon Dec 5 23:02:01 2022 +0800
    expand: Add ifsfree to expand to fix a logic error that causes a buffer over-read

    On Mon, Jun 20, 2022 at 02:27:10PM -0400, Alex Gorinson wrote:
    > Due to a logic error in the ifsbreakup function in expand.c if a
    > heredoc and normal command is run one after the other by means of a
    > semi-colon, when the second command drops into ifsbreakup the command
    > will be evaluated with the ifslastp/ifsfirst struct that was set when
    > the here doc was evaluated. This results in a buffer over-read that
    > can leak the program's heap, stack, and arena addresses which can be
    > used to beat ASLR.
    >
    > Steps to Reproduce:
    > First bug:
    > cmd args: ~/exampleDir/example> dash
    > $ M='AAAAAAAAAAAAAAAAA'    <note: 17 A's>
    > $ q00(){
    > $ <<000;echo
    > $ ${D?$M$M$M$M$M$M}        <note: 6 $M's>
    > $ 000
    > $ }
    > $ q00                      <note: After the q00 is typed in, the leak
    > should be echo'd out; this works with ash, busybox ash, and dash and
    > with all option args.>
    >
    > Patch:
    > Adding the following to expand.c will fix both bugs in one go.
    > (Thank you to Harald van Dijk and Michael Greenberg for doing the
    > heavy lifting for this patch!)
    > ==========================
    > --- a/src/expand.c
    > +++ b/src/expand.c
    > @@ -859,6 +859,7 @@
    > if (discard)
    > return -1;
    >
    > +ifsfree();
    > sh_error("Bad substitution");
    > }
    >
    > @@ -1739,6 +1740,7 @@
    > } else
    > msg = umsg;
    > }
    > +ifsfree();
    > sh_error("%.*s: %s%s", end - var - 1, var, msg, tail);
    >  }
    > ==========================

    Thanks for the report!

    I think it's better to add the ifsfree() call to the exception
    handling path as other sh_error calls may trigger this too.

function                                             old     new   delta
restore_handler_expandarg                              -      33     +33
evaltree                                             725     711     -14
static.redirectsafe                                  141     124     -17
expandstr                                            262     242     -20
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/3 up/down: 36/-45)            Total: -18 bytes

Signed-off-by: Sanghyun Park <sanghyun.park.cnu@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-07-06 10:30:30 +02:00
Denys Vlasenko 5de0780eaf awk: fix printf "%o\n", -1
function                                             old     new   delta
awk_printf                                          1381    1387      +6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-07-06 04:37:44 +02:00
Denys Vlasenko cd8427b8ec svlogd: fix buffer overrun
Patch by mjmouse9999@gmail.com

When running svlogd -tt with a long line of input, the code assumes a buffer
of at least linemax+26 length, but that is two bytes longer than the
actual buffer with the default of linemax = 1000.

fixing that.

No code size change.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-07-03 08:17:51 +02:00
Anubhav Kokane 71f9960b33 cmp: add KMG suffix for cmp -n MAXCOUNT
Change input to getopt32 from int to char * so that
max_count is parsed as string. Use xatol_sfx to convert
string to long.

function                                             old     new   delta
cmp_main                                             595     631     +36
.rodata                                           107121  107120      -1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 36/-1)              Total: 35 bytes

Signed-off-by: Anubhav Kokane <dev.anubhavk@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-07-03 08:14:23 +02:00
Denys Vlasenko 1332023051 awk: optimize 'print "no format specs here\n"' case
function                                             old     new   delta
awk_printf                                          1349    1381     +32

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-07-02 05:57:28 +02:00
Denys Vlasenko a0667b2def awk: fix printing of very large numbers with printf("%d")
function                                             old     new   delta
awk_printf                                          1086    1349    +263
.rodata                                           107108  107121     +13
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 276/0)             Total: 276 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-07-02 04:58:08 +02:00
Denys Vlasenko 4e981fe00f awk: rename variables in awk_printf(), no code changes
awk_printf() got bigger, and now variables need better names,
even if this makes them longer.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-07-02 00:05:11 +02:00
Denys Vlasenko 6ba81ddb0d awk: add '*' as a valid specifier for width and precision in printf
Based on a patch by Anubhav Kokane <dev.anubhavk@gmail.com>

function                                             old     new   delta
awk_printf                                           640    1086    +446
.rodata                                           107131  107108     -23
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 446/-23)           Total: 423 bytes
   text	   data	    bss	    dec	    hex	filename
1080210	    555	   4992	1085757	 10913d	busybox_old
1080633	    555	   4992	1086180	 1092e4	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-07-01 23:38:27 +02:00
Denys Vlasenko 244c0a01ee testing stripts: allow to skip "awk gsub erroneous word start match" test
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-05-14 16:26:10 +02:00
Denys Vlasenko 0309c02980 hush: placate warning: 'print_pfx_escaped_nl' defined but not used
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-05-14 16:22:40 +02:00
Denys Vlasenko 8fc70b52e6 tls: use bb_simple_error_msg where appropriate
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-05-14 16:08:13 +02:00
Denys Vlasenko c83394922e Start 1.39.0 development cycle
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-05-13 05:24:28 +02:00
Denys Vlasenko fc71374dfc Bump version to 1.38.0
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-05-13 04:20:15 +02:00
Denys Vlasenko ead17e7808 Optimize !ENABLE_SHOW_USAGE config
function                                             old     new   delta
bb_show_usage                                          6       -      -6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-05-02 12:05:32 +02:00
Denys Vlasenko 25b756f789 cpio.tests: fix false positive
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-04-30 10:04:47 +02:00
Denys Vlasenko 3b3d0fc535 cpio.tests: do not use "ls" to detect that file does not exist
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-04-30 08:05:42 +02:00
Denys Vlasenko 48c7b48f95 tar: unicode fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-04-30 07:29:37 +02:00
Denys Vlasenko 4f11a4b25d cpio.tests: fix false positive when -o support is not enabled
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-04-30 06:46:44 +02:00
Denys Vlasenko 6908229d4f cpio: fix a bug (wrong free() address) in !FEATURE_TAR_LONG_OPTIONS config
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-04-30 05:56:58 +02:00
Denys Vlasenko fb10ad3b5c start-stop-daemon.tests: fix false positive if longopts are not enabled
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-04-29 15:55:44 +02:00
Denys Vlasenko c8eb861406 Fix "undefined reference to 'skip_unsafe_prefix' build failure
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-04-29 08:46:56 +02:00
Denys Vlasenko fdca28aaf4 fdisk: fix build failure on glibc
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-04-29 07:32:26 +02:00
Denys Vlasenko a0a98f0700 Fix randomtest to not select TC on glibc
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-04-29 07:30:13 +02:00
Denys Vlasenko 7e2b9a4d9c httpd: fix build for !FEATURE_HTTPD_CGI config
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-04-29 07:09:30 +02:00
Denys Vlasenko a588fb9703 Fix randomtest to never select a debug config
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-04-29 07:04:30 +02:00
Denys Vlasenko a9e7466e5c telnet: fix build for !TELNETD config
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-04-29 06:49:48 +02:00
Denys Vlasenko de26b74b1d httpd: fix build for !FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR config
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-04-29 06:36:39 +02:00
Denys Vlasenko 0519429ea1 hush: fix build for !HUSH_CASE config
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-04-29 06:31:55 +02:00
Denys Vlasenko 2f3b16fc1b libbb: rename two fields in ioloop_state, no logic changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-04-12 16:20:09 +02:00
Denys Vlasenko bee252057c trylink: remove "local" bashism
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-03-16 14:49:42 +01:00
Christian Stewart 764df2555d trylink: detect linker flag support for non-GNU linkers
wasm-ld does not support --start-group/--end-group, --warn-common,
--verbose, or -Map flags. Add check_cc tests so these are only used
when the linker supports them, following the existing --sort-section
and --sort-common patterns.

Signed-off-by: Christian Stewart <christian@aperture.us>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-03-15 16:35:32 +01:00
Denys Vlasenko 60221ded38 less: fix ":d" command
function                                             old     new   delta
less_main                                           2105    2062     -43

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-03-15 16:12:23 +01:00
Denys Vlasenko ca0eb211b0 runsv: fix open error check (fd < -1 should be fd < 0)
From: Weixie Cui <cuiweixie@gmail.com>

function                                             old     new   delta
update_status                                        608     607      -1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-03-13 00:46:19 +01:00
Denys Vlasenko d368f3f783 udhcpc6: check the size of D6_OPT_IAPREFIX option
function                                             old     new   delta
option_to_env                                        694     711     +17

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-03-12 13:23:48 +01:00
Denys Vlasenko 42202bfb1e udhcpc6: fix buffer overflow
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-03-12 07:25:38 +01:00
Ron Yorston e527bd22db ash: fix here strings causing segfault in function invocation
The size of the NFROMSTR struct wasn't initialised in the nodesize
array, so we got:

   $ ./busybox sh
   $ f() { cat <<< hello; }
   $ f
   Segmentation fault         (core dumped) ./busybox sh

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-03-09 15:23:59 +01:00
Ron Yorston ea01f254b4 paste: fix output when file lengths differ
If the files being pasted had different numbers of lines the
output was incorrect.

Rewrite the loop over all lines to allow for this.  Add tests for
such conditions.

function                                             old     new   delta
paste_main                                           458     526     +68

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-03-05 21:46:04 +01:00
Ron Yorston via busybox b59b003231 ash: fix help builtin and tab completion of builtins
Commit 56143ea63 (ash: code shrink: eliminate pstrcmp1()) changed
the layout of struct builtincmd so the name member points to the
start of the name, not the flag in the first element of the string.
This broke the help builtin and tab completion of builtins.

Remove the unnecessary '+ 1' in ash_command_name() and helpcmd().

ash_command_name                                      92      91      -1
helpcmd                                              106     102      -4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-5)               Total: -5 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-28 11:25:05 +01:00
Radoslav Kolev 599f5dd8fa tar: only strip unsafe components from hardlinks, not symlinks
commit 3fb6b31c7 introduced a check for unsafe components in
tar archive hardlinks, but it was being applied to symlinks too
which broke "Symlinks and hardlinks coexist" tar test.

Signed-off-by: Radoslav Kolev <radoslav.kolev@suse.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-28 05:59:18 +01:00
Denys Vlasenko 138ec0e0d8 less: unbreak EAGAIN propagation
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-27 12:25:28 +01:00
Denys Vlasenko 1068aa8220 less: make read error reporting actually visible
function                                             old     new   delta
m_status_print                                       252     275     +23
status_print                                         111     122     +11
read_lines                                           783     775      -8
.rodata                                           107141  107131     -10
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/2 up/down: 34/-18)             Total: 16 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-27 11:57:50 +01:00
Denys Vlasenko ca3f4c6639 less: improve O_NONBLOCK manipulations on stdin
"less FILE" case needs it to be set just once. In other cases,
manipulate it less often.

function                                             old     new   delta
read_lines                                           702     783     +81
reinitialize                                         198     199      +1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 82/0)               Total: 82 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-27 11:01:04 +01:00
Denys Vlasenko f51819afa5 less: do not retry reads of stdin if got EAGAIN
Also: fewer syscalls to set/clear O_NONBLOCK, skip trying to read keyboard
if poll() told us it's not ready.

function                                             old     new   delta
reinitialize                                         184     198     +14
getch_nowait                                         251     258      +7
sched_yield                                           25       -     -25
read_lines                                           815     702    -113
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 2/1 up/down: 21/-138)          Total: -117 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-27 08:09:30 +01:00
Denys Vlasenko ad88be9e7e *: don't use getservbyname, it links in a static buffer
function                                             old     new   delta
bb_get_servport_by_name                                -     348    +348
bb_lookup_port                                        83     111     +28
reread_config_file                                   886     907     +21
static.se                                             16       -     -16
getservbyname                                         53       -     -53
getservbyname_r                                      284       -    -284
------------------------------------------------------------------------------
(add/remove: 2/5 grow/shrink: 2/0 up/down: 397/-353)           Total: 44 bytes
   text	   data	    bss	    dec	    hex	filename
1080084	    555	   5024	1085663	 1090df	busybox_old
1080144	    555	   4992	1085691	 1090fb	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-25 02:35:32 +01:00
Denys Vlasenko c920ecd73d telnet: fix false positive "Error writing to foreign host"
function                                             old     new   delta
write_to_net                                         620     625      +5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-24 23:47:52 +01:00
Denys Vlasenko 1ecee61787 netstat: fix breakage due to last commit
function                                             old     new   delta
bb_get_servname_by_port                              182     195     +13
ip_port_str                                          121     120      -1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 13/-1)              Total: 12 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-24 23:11:21 +01:00
Denys Vlasenko c0037a9974 netstat,pscan: don't use getservbyport(), it links in a static buffer
function                                             old     new   delta
bb_get_servname_by_port                                -     182    +182
ip_port_str                                          112     121      +9
pscan_main                                           594     591      -3
getservbyport                                         53       -     -53
getservbyport_r                                      430       -    -430
------------------------------------------------------------------------------
(add/remove: 2/4 grow/shrink: 1/1 up/down: 191/-486)         Total: -295 bytes
   text	   data	    bss	    dec	    hex	filename
1080362	    555	   5056	1085973	 109215	busybox_old
1080067	    555	   5024	1085646	 1090ce	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-24 22:42:30 +01:00
Denys Vlasenko b86f0198d6 telnet: fixes after testing against some MUD servers
A few size tests were not tight enough. More importantly,
the logic "is this a telnet server?" made more robust.

TTYPE seems to be understood by the MUD server I tried,
for some reason NAWS is not?

function                                             old     new   delta
packed_usage                                       36040   36078     +38
write_to_net                                         598     620     +22
telnet_main                                          455     462      +7
handle_SIGWINCH                                       15      21      +6
read_from_net                                        534     539      +5
show_menu                                            212     203      -9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 5/1 up/down: 78/-9)              Total: 69 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-24 07:16:16 +01:00
Denys Vlasenko 4bdbb7cc0a telnetd: if vfork in make_new_session() fails, do close socket.
function                                             old     new   delta
telnetd_main                                         372     385     +13
make_new_session                                     550     552      +2
xgetpty                                               81      78      -3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 15/-3)              Total: 12 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-24 00:03:20 +01:00
Denys Vlasenko 0ac0492b37 telnet: code shrink
function                                             old     new   delta
write_to_stdout                                      105     113      +8
put_iac                                               28      35      +7
write_to_net                                         596     598      +2
read_from_stdin                                      227     229      +2
read_from_net                                        543     534      -9
telnet_main                                          476     455     -21
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/2 up/down: 19/-30)            Total: -11 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-23 15:42:43 +01:00
Denys Vlasenko 87fcfe7dfe telnet: rewrite to use ioloop()
Now should never block on network I/O. Also, window resizing is dynamic now.

function                                             old     new   delta
write_to_net                                           -     596    +596
read_from_net                                          -     543    +543
read_from_stdin                                        -     227    +227
show_menu                                              -     212    +212
write_to_stdout                                        -     105    +105
have_data_to_write_to_net                              -      72     +72
have_data_to_write_to_stdout                           -      38     +38
put_iac_byte_escaped                                   -      32     +32
ioloop_run                                           411     438     +27
have_buffer_to_read_from_stdin                         -      25     +25
have_buffer_to_read_from_net                           -      25     +25
.rodata                                           107125  107141     +16
handle_SIGWINCH                                        -      15     +15
put_iac                                               36      28      -8
put_iac4_msb_lsb                                      19       -     -19
iac_flush                                             36       -     -36
setConMode                                            87       -     -87
handle_net_output                                    110       -    -110
con_escape                                           271       -    -271
telnet_main                                         1232     476    -756
------------------------------------------------------------------------------
(add/remove: 11/5 grow/shrink: 2/2 up/down: 1933/-1287)       Total: 646 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-23 14:47:17 +01:00
Denys Vlasenko 3017f2becf telnetd: do not send stray \r\n before /etc/issue.net
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-23 00:09:10 +01:00
Denys Vlasenko da09ae3451 telnetd: do not wait for more input after 10-byte NAWS is received
If the the screen is resized to 255 columns without any
subsequent data received, the server won't parse and react
to the NAWS (until eventually at least one more byte arrives).

function                                             old     new   delta
read_byte_unescaping_IAC                              28      31      +3
net_to_pty__have_data_to_write                       551     552      +1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 4/0)                 Total: 4 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-22 21:20:59 +01:00
Denys Vlasenko 8738c3102f telnetd: fix handshake: had one wrong, but harmless element
function                                             old     new   delta
static.iacs_to_send                                   12       9      -3

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-22 20:04:41 +01:00
Denys Vlasenko 44e86427f4 telnetd: correct handling of screen sizes with any dimension equal to 255
IOW: teach NAWS parser how to IAC-unescape.

function                                             old     new   delta
net_to_pty__have_data_to_write                       429     551    +122
read_byte_unescaping_IAC                               -      28     +28
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/0 up/down: 150/0)             Total: 150 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-22 09:45:03 +01:00
Denys Vlasenko 20387b703b telnetd: do close pty when network read returns EOF; try to cause EOF-on-read
function                                             old     new   delta
fabricate_ctrl_D_on_pty                                -      65     +65
net_to_pty__have_data_to_write                       368     429     +61
.rodata                                           107096  107125     +29
telnetd_main                                         367     372      +5
net_to_pty__have_buffer_to_read_into                 164     162      -2
packed_usage                                       36066   36040     -26
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 3/2 up/down: 160/-28)           Total: 132 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-22 07:11:16 +01:00
Denys Vlasenko dc6e92c990 libbb: add generic "fd polling and I/O" loop, use it in telnetd
We do it, badly, in many places. Better to use one robust implementation.
Can be buggy yet.
Initial use is in a rather old, rarely used tech: telnet.

The I/O in telnetd should be fully non-blocking now,
including pty delays handling.

Several bugs in telnetd handling of IACs are fixed.

function                                             old     new   delta
ioloop_run                                             -     411    +411
net_to_pty__have_data_to_write                         -     368    +368
pty_to_net__write                                      -     318    +318
net_to_pty__write                                      -     180    +180
pty_to_net__read                                       -     171    +171
net_to_pty__have_buffer_to_read_into                   -     164    +164
pty_to_net__have_buffer_to_read_into                   -      90     +90
net_to_pty__read                                       -      87     +87
pty_to_net__have_data_to_write                         -      59     +59
make_new_session                                     491     550     +59
conn_close_fds                                         -      52     +52
accept_conn__accept                                    -      49     +49
conn_close_fds_remove_and_free                         -      27     +27
ioloop_remove_conn                                     -      22     +22
remove_and_free_to_pty                                 -      19     +19
ioloop_insert_conn                                     -      10     +10
accept_conn__can_accept                                -       6      +6
accept_conn__return_zero                               -       3      +3
static.ayt_response                                    -       2      +2
handle_sigchld                                        59      61      +2
free_session                                         130       -    -130
telnetd_main                                        1797     367   -1430
------------------------------------------------------------------------------
(add/remove: 19/1 grow/shrink: 2/1 up/down: 2099/-1560)       Total: 539 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-21 16:54:35 +01:00
Denys Vlasenko ef892681f9 tls: code shrink
function                                             old     new   delta
tls_handshake_as_server                             2408    2400      -8

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-21 01:36:01 +01:00
Denys Vlasenko 22b66febbd tls: server: fix incorrect key_block assignments - now works against openssl s_client
function                                             old     new   delta
privRsaEncryptSignedElement                            -     236    +236
tls_handshake_as_server                             2033    2264    +231
.rodata                                           108079  108301    +222
initialize_aes_keys                                    -      77     +77
xwrite_encrypted                                     507     506      -1
tls_handshake                                       1519    1500     -19
derive_master_secret_and_keys                        154     123     -31
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 2/3 up/down: 766/-51)           Total: 715 bytes

Totoal growth compared to code before TLS server code:

function                                             old     new   delta
tls_handshake_as_server                                -    2264   +2264
.rodata                                           107074  108301   +1227
psRsaCrypt                                             -     577    +577
load_rsa_priv_key                                      -     282    +282
ssl_server_main                                        -     279    +279
privRsaEncryptSignedElement                            -     236    +236
ssl_client_main                                      137     363    +226
psRsaDecryptPriv                                       -     171    +171
set_cipher_parameters                                  -     161    +161
derive_master_secret_and_keys                          -     123    +123
packed_usage                                       36034   36146    +112
sp_ecc_make_key_256                                    -     103    +103
send_finished                                          -      94     +94
get_change_cipher_spec                                 -      88     +88
initialize_aes_keys                                    -      77     +77
static.BLOCK_NAMES                                     -      70     +70
curve_P256_compute_premaster                           -      65     +65
der_binary_to_pstm                                     -      50     +50
curve_x25519_generate_keypair                          -      44     +44
get_finished                                           -      42     +42
get_outbuf_fill_handshake_record                       -      37     +37
client_hello_ciphers                                   -      32     +32
curve_P256_generate_keypair                            -      27     +27
sp_256_from_bin_8                                      -      26     +26
tls_xread_record                                     681     704     +23
curve_x25519_compute_premaster                         -      15     +15
applet_names                                        2870    2881     +11
applet_main                                         1652    1656      +4
xwrite_encrypted                                     507     506      -1
xwrite_and_update_handshake_hash                      76      59     -17
sp_256_point_from_bin2x32                             70      43     -27
curve_x25519_compute_pubkey_and_premaster             71      39     -32
curve_P256_compute_pubkey_and_premaster              167      65    -102
psRsaEncryptPub                                      395     199    -196
tls_handshake                                       2069    1500    -569
------------------------------------------------------------------------------
(add/remove: 23/0 grow/shrink: 6/7 up/down: 6466/-944)       Total: 5522 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-15 15:26:31 +01:00
Denys Vlasenko 7773faa878 tls: make ECDHE_RSA work against our client (openssl s_client not yet)
function                                             old     new   delta
tls_handshake_as_server                             1601    2033    +432
sp_ecc_make_key_256                                    -     103    +103
curve_P256_compute_premaster                           -      65     +65
.rodata                                           108023  108079     +56
curve_x25519_generate_keypair                          -      44     +44
tls_get_zeroed_outbuf                                  -      28     +28
curve_P256_generate_keypair                            -      27     +27
sp_256_from_bin_8                                      -      26     +26
curve_x25519_compute_premaster                         -      15     +15
tls_xread_record                                     708     704      -4
tls_handshake                                       1530    1519     -11
get_outbuf_fill_handshake_record                      51      37     -14
sp_256_point_from_bin2x32                             70      43     -27
curve_x25519_compute_pubkey_and_premaster             71      39     -32
curve_P256_compute_pubkey_and_premaster              167      65    -102
------------------------------------------------------------------------------
(add/remove: 7/0 grow/shrink: 2/6 up/down: 796/-190)          Total: 606 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-15 15:16:26 +01:00
Denys Vlasenko 2ab2c25847 tls: remove unnecessary malloc/free in psRsaDecryptPriv()
function                                             old     new   delta
.rodata                                           108007  108023     +16
psRsaDecryptPriv                                     200     171     -29
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 16/-29)            Total: -13 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-15 15:16:26 +01:00
Denys Vlasenko 5a1bcdf036 tls: fix cipher-id selection in server mode
ECDSA keys still don't work, and currently will be ignored

function                                             old     new   delta
tls_handshake_as_server                              824    1601    +777
.rodata                                           107764  108007    +243
set_cipher_parameters                                  -     161    +161
packed_usage                                       36072   36146     +74
static.BLOCK_NAMES                                     -      70     +70
client_hello_ciphers                                   -      32     +32
ssl_server_main                                      288     279      -9
load_rsa_priv_key                                    329     282     -47
tls_handshake                                       1676    1530    -146
------------------------------------------------------------------------------
(add/remove: 3/0 grow/shrink: 3/3 up/down: 1357/-202)        Total: 1155 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-15 15:16:26 +01:00
Denys Vlasenko 456abad825 tls: eliminate unnecessary ENCRYPT_ON_WRITE, merge tls_get_zeroed_outbuf() with fill_handshake_record_hdr()
function                                             old     new   delta
get_outbuf_fill_handshake_record                       -      51     +51
send_finished                                         95      94      -1
tls_handshake                                       1690    1676     -14
xwrite_and_update_handshake_hash                      76      59     -17
tls_handshake_as_server                              852     824     -28
tls_get_zeroed_outbuf                                 28       -     -28
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 0/4 up/down: 51/-88)            Total: -37 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-15 15:16:26 +01:00
Denys Vlasenko e17bc84d4c tls: fix up debug printouts wrt newlines
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-15 15:16:26 +01:00
Denys Vlasenko 657fbcd62c tls: implement server code
function                                             old     new   delta
tls_handshake_as_server                                7     852    +845
.rodata                                           107103  107764    +661
psRsaCrypt                                             -     577    +577
load_rsa_priv_key                                      -     329    +329
psRsaDecryptPriv                                       -     200    +200
derive_master_secret_and_keys                          -     154    +154
send_finished                                          -      95     +95
get_change_cipher_spec                                 -      88     +88
der_binary_to_pstm                                     -      50     +50
get_finished                                           -      42     +42
tls_xread_record                                     681     708     +27
ssl_server_main                                      285     288      +3
psRsaEncryptPub                                      395     199    -196
tls_handshake                                       2069    1690    -379
------------------------------------------------------------------------------
(add/remove: 8/0 grow/shrink: 4/2 up/down: 3071/-575)        Total: 2496 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-15 15:16:26 +01:00
Denys Vlasenko 61055ef909 ssl_server: new applet, not functional yet
function                                             old     new   delta
ssl_server_main                                        -     285    +285
ssl_client_main                                      137     363    +226
packed_usage                                       36034   36072     +38
.rodata                                           107074  107103     +29
applet_names                                        2870    2881     +11
tls_handshake_as_server                                -       7      +7
applet_main                                         1652    1656      +4
------------------------------------------------------------------------------
(add/remove: 3/0 grow/shrink: 5/0 up/down: 600/0)             Total: 600 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-15 15:16:26 +01:00
Denys Vlasenko d972f56837 libbb: better comments in read_key()
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-15 15:16:26 +01:00
Denys Vlasenko b668e52c90 *: placate warnings where strchr/strstr returns constant pointer
Newer glibc is now smarter and can propagate const-ness from those!

function                                             old     new   delta
readtoken1                                          3111    3108      -3

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-15 15:15:30 +01:00
Denys Vlasenko 9e8f8a1968 fdisk: implement -t PARTTYPE
This allows to operate on MBR even if disk also has GPT.

function                                             old     new   delta
.rodata                                           107019  107074     +55
packed_usage                                       36009   36034     +25
get_boot                                            1513    1532     +19
fdisk_main                                          4618    4622      +4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/0 up/down: 103/0)             Total: 103 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-15 15:15:30 +01:00
Denys Vlasenko 8424dc436a main: !CONFIG_BUSYBOX: "busybox --OPT" is not a call to applet "-OPT"
This was confusing:

$ busybox --help
-help: applet not found

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-08 11:45:57 +01:00
Denys Vlasenko 391fdea73b *: whitespace cleanup
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-08 08:31:13 +01:00
Denys Vlasenko 8289b34626 tls: document PSTM_64BIT + PSTM_X86_64 optimizations better
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-08 08:30:03 +01:00
Denys Vlasenko 91075de0a7 vi: code shrink
function                                             old     new   delta
.rodata                                           107007  107019     +12
run_cmds                                              62      50     -12
indicate_error                                        78      55     -23
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 12/-35)            Total: -23 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-07 12:53:27 +01:00
Denys Vlasenko 1380df7a5a vi: fix last commit - do terminate the :CMD on the first whitespace
function                                             old     new   delta
colon                                               3942    3952     +10

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-07 03:20:26 +01:00
Denys Vlasenko 9693daaaef *: use is_prefixed_with() where appropriate
function                                             old     new   delta
resume_main                                          560     556      -4
uuidcache_check_device                               107     101      -6
ntp_init                                            1005     997      -8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-18)             Total: -18 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-07 01:10:55 +01:00
Denys Vlasenko 79d35b5a0e vi: fix ":list" command
function                                             old     new   delta
.rodata                                           107010  107007      -3
show_status_line                                     372     362     -10
colon                                               3989    3942     -47
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-60)             Total: -60 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-07 00:52:49 +01:00
Denys Vlasenko 5de7222395 vi: code shrink
function                                             old     new   delta
colon                                               4005    3989     -16

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-06 23:22:49 +01:00
Denys Vlasenko 3620c4ee67 vi: fix "s /find/repl" with whitespace before /
function                                             old     new   delta
colon                                               3977    4005     +28

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-06 22:56:16 +01:00
Denys Vlasenko 80ce9e3998 vi: code shrink, optimize: do not call count_lines() unless needed
function                                             old     new   delta
colon                                               4010    3980     -30

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-06 20:50:47 +01:00
Denys Vlasenko c8cbd3516d *: use xasprintf_inplace() and concat_path_file() where appropriate
function                                             old     new   delta
acpid_main                                          1059    1063      +4
resume_main                                          561     560      -1
unpack_package                                       642     640      -2
adduser_main                                         861     859      -2
getty_main                                          1517    1512      -5
ftpd_main                                           2149    2142      -7
.rodata                                           107018  107010      -8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/6 up/down: 4/-25)             Total: -21 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-06 13:16:36 +01:00
Denys Vlasenko 9b2a50efe2 *: use xasprintf_inplace() in more places
function                                             old     new   delta
.rodata                                           107009  107018      +9
parse_stream                                        3075    3069      -6
buffer_print                                         612     603      -9
expand_args                                          159     144     -15
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/3 up/down: 9/-30)             Total: -21 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-06 11:19:11 +01:00
Denys Vlasenko 89f37ebe8c man: fix following links if run inside manpage dir
function                                             old     new   delta
run_man_pipe                                         369     420     +51

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-05 14:28:20 +01:00
Denys Vlasenko fddd93edbd libbb: introduce and use xasprintf_inplace()
function                                             old     new   delta
xasprintf_and_free                                     -      49     +49
watch_main                                           269     282     +13
singlemount                                         1313    1315      +2
append_mount_options                                 157     149      -8
ip_port_str                                          122     112     -10
lsblk_main                                           869     858     -11
add_cmd                                             1178    1167     -11
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 2/4 up/down: 64/-40)             Total: 24 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-05 13:36:27 +01:00
Denys Vlasenko 3d572a8cc3 watch: implement -x
function                                             old     new   delta
packed_usage                                       35949   36009     +60
watch_main                                           229     269     +40
.rodata                                           107008  107009      +1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 101/0)             Total: 101 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-05 12:23:32 +01:00
Denys Vlasenko e33bd4aaa2 libbb: use narrow isqrt() when 64-bit one is not needed (only "factor" uses it)
function                                             old     new   delta
isqrt_ull                                              -      84     +84
create_J                                            1809    1808      -1
isqrt                                                106      38     -68
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/2 up/down: 84/-69)             Total: 15 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-04 19:47:11 +01:00
Denys Vlasenko cdcb4ce314 volume_id: improve handling of too-small (usually zero-byte or erroring) blockdevs
function                                             old     new   delta
volume_id_get_buffer                                 327     372     +45
volume_id_open_node                                   17      24      +7
volume_id_probe_all                                  133     123     -10
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 52/-10)             Total: 42 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-04 15:59:33 +01:00
Alyssa Ross via busybox 7310339e73 volume_id: volume_id_get_buffer with small FSes
I was working with some very small ext4 filesystems, used for
overlaying on immutable VM/container images.  If it's only desired to
overlay a single config file, these filesystems can be very small
indeed, and so ran afoul of this length check.

Since 4fc5ec56f ("device matching against UUIDs: do not try
floppies") (from 2009), floppy drives are skipped before this function
is even called.  Reading from an unused loop device returns 0, so it
should be fine to reduce  the minimum length.

Signed-off-by: Alyssa Ross via busybox <busybox@busybox.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-04 13:30:24 +01:00
Denys Vlasenko 72fbc81224 fdisk: code shrink
function                                             old     new   delta
new_partition                                       1054    1066     +12
list_table                                          1366    1370      +4
update_units                                          32      35      +3
list_disk_geometry                                    68      71      +3
get_geometry                                         535     538      +3
fdisk_fatal                                           38      41      +3
warn_cylinders                                        42      44      +2
xbsd_print_disklabel                                 836     834      -2
create_doslabel                                      110     108      -2
change_units                                          49      45      -4
xbsd_new_part                                        477     456     -21
add_partition                                       1278    1246     -32
.rodata                                           107059  107008     -51
fdisk_main                                          4775    4618    -157
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 7/7 up/down: 30/-269)          Total: -239 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-04 12:03:33 +01:00
Denys Vlasenko 8aba5f6347 fdisk: comment out "not a multiple of 512 bytes" warning
function                                             old     new   delta
bb_getsize_in_512sect                                187     163     -24
.rodata                                           107088  107059     -29
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-53)             Total: -53 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-04 10:30:45 +01:00
Denys Vlasenko 36eed984b8 fdisk: several fixes for 4K sector size
function                                             old     new   delta
bb_getsize_in_512sect                                  -     187    +187
list_disk_name_and_sizes                               -      80     +80
get_geometry                                         511     535     +24
.rodata                                           107066  107088     +22
msg_building_new_label                               143     142      -1
fdisk_main                                          4781    4775      -6
list_table                                          1423    1366     -57
list_disk_geometry                                   143      68     -75
bb_BLKGETSIZE_sectors                                191       -    -191
------------------------------------------------------------------------------
(add/remove: 2/1 grow/shrink: 2/4 up/down: 313/-330)          Total: -17 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-04 09:46:54 +01:00
Denys Vlasenko 93b684fe9f findfs: tweak --help
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-03 11:40:41 +01:00
Denys Vlasenko 3e80101963 uuidgen: move UUID formatting to libbb
function                                             old     new   delta
format_uuid_DCE_37_chars                               -      94     +94
uuidgen_main                                          71      53     -18
.rodata                                           107089  107066     -23
mkswap_main                                          278     253     -25
volume_id_set_uuid                                   258     178     -80
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/4 up/down: 94/-146)           Total: -52 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-03 09:10:25 +01:00
Denys Vlasenko 4855fbe6a8 fdisk: uncomment -s support
function                                             old     new   delta
bb_BLKGETSIZE_sectors                                  -     191    +191
fdisk_main                                          4674    4774    +100
packed_usage                                       35941   35997     +56
.rodata                                           107069  107089     +20
get_geometry                                         665     511    -154
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 3/1 up/down: 367/-154)          Total: 213 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-02 15:26:03 +01:00
Denys Vlasenko 705c9b3487 devfsd: constify, code shrink
function                                             old     new   delta
static.copy_inode                                    613     608      -5
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-5)               Total: -5 bytes
   text	   data	    bss	    dec	    hex	filename
1087619	    827	   5088	1093534	 10af9e	busybox_old
1087654	    787	   5088	1093529	 10af99	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-02 08:49:11 +01:00
Denys Vlasenko 4e815cd7b3 fdisk_sgi: formatting fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-02 05:19:26 +01:00
Denys Vlasenko 3b19867d97 fdisk: fix spurious warning about zero unused sectors
while at it, deindent nested for()

function                                             old     new   delta
verify_sun                                           429     447     +18

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-01 14:36:06 +01:00
Denys Vlasenko 47775e8e6a fdisk: simplify start/len calcualtions for Sun labels
function                                             old     new   delta
new_partition                                       1060    1054      -6
fetch_sun                                            219     207     -12
verify_sun_cmp                                        54      39     -15
verify_sun                                           508     429     -79
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/4 up/down: 0/-112)           Total: -112 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-01 14:23:00 +01:00
Denys Vlasenko 7ac2bd6917 fdisk: eliminate static variables, fix GPT disk size (32x32->32 overflow)
function                                             old     new   delta
verify_sun                                           481     508     +27
.rodata                                           107016  107022      +6
verify_sun_cmp                                        51      54      +3
sun_other_endian                                       1       -      -1
scsi_disk                                              1       -      -1
floppy                                                 1       -      -1
xbsd_print_disklabel                                 838     836      -2
xbsd_new_part                                        479     477      -2
xbsd_write_bootstrap                                 397     394      -3
set_sun_partition                                    103     100      -3
delete_partition                                     435     432      -3
xbsd_part_index                                        4       -      -4
xbsd_part                                              4       -      -4
verify_sun_starts                                      4       -      -4
part_entry_len                                         4       -      -4
part_array                                             4       -      -4
n_parts                                                4       -      -4
gpt_hdr                                                4       -      -4
check_sun_label                                      214     208      -6
list_table                                          1433    1423     -10
fetch_sun                                            233     219     -14
bsd_select                                          1564    1546     -18
get_geometry                                         691     665     -26
get_boot                                            1539    1513     -26
fdisk_main                                          4737    4674     -63
------------------------------------------------------------------------------
(add/remove: 0/10 grow/shrink: 3/12 up/down: 36/-207)        Total: -171 bytes
   text	   data	    bss	    dec	    hex	filename
1078472	    555	   5088	1084115	 108ad3	busybox_old
1078332	    555	   5056	1083943	 108a27	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-01 13:44:54 +01:00
Osama Abdelkader via busybox 405afbd551 util-linux: add minimal uuidgen implementation
Add a simple uuidgen utility that generates RFC 4122 compliant
UUIDs (version 4, random). Uses the existing generate_uuid()
function from libbb and volume_id_set_uuid() for formatting.

Implementation suggested by Ulli.

Features:
- Generates standard format UUIDs: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
- RFC 4122 version 4 compliant
- Minimal implementation (~1.1 kb)
- NOFORK applet for efficiency
- Uses existing volume_id infrastructure for UUID formatting

function                                             old     new   delta
uuidgen_main                                           -      71     +71
applet_names                                        2862    2870      +8
.rodata                                           107010  107016      +6
applet_main                                         1648    1652      +4
applet_suid                                          103     104      +1
applet_install_loc                                   206     207      +1
applet_flags                                         103     104      +1
packed_usage                                       35952   35941     -11
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 6/1 up/down: 92/-11)             Total: 81 bytes

Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-02-01 11:41:08 +01:00
Denys Vlasenko 2bfe3753d9 lkblk: list multiple MOUNTPOINTS
function                                             old     new   delta
lsblk_main                                           550     869    +319
.rodata                                           106977  107010     +33
process__sys_block_NAME                              461     356    -105
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 352/-105)          Total: 247 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-30 21:16:30 +01:00
Denys Vlasenko 8463ce06ca lsblk: add error messages and exit code when non-blockdevs are given
function                                             old     new   delta
process__sys_block_NAME                                -     461    +461
lsblk_main                                           511     550     +39
.rodata                                           106960  106977     +17
process_SYS_BLOCK_entry                              460       -    -460
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 2/0 up/down: 517/-460)           Total: 57 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-30 20:16:59 +01:00
Osama Abdelkader 8a347fd31a lsblk: new applet
Add a simple lsblk utility that lists information about block devices.
Reads from /sys/block to enumerate devices and displays their size,
type, and mount point.

Features:
- Lists all block devices or specific devices
- Shows device size in human-readable format (B, K, M, G, T, P)
- Shows device type (disk, loop, partition)
- Shows mount point if device is mounted
- Sorts devices alphabetically
- Minimal implementation (~2.5 kb)

Mostly rewritten by vda.linux

function                                             old     new   delta
lsblk_main                                             -     511    +511
process_SYS_BLOCK_entry                                -     460    +460
.rodata                                           106856  106960    +104
read_ull                                               -      81     +81
packed_usage                                       35924   35952     +28
compare_devices                                        -      25     +25
applet_names                                        2856    2862      +6
applet_main                                         1644    1648      +4
------------------------------------------------------------------------------
(add/remove: 5/0 grow/shrink: 4/0 up/down: 1219/0)           Total: 1219 bytes

Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-30 12:23:42 +01:00
Denys Vlasenko 3fb6b31c71 tar: strip unsafe hardlink components - GNU tar does the same
Defends against files like these (python reproducer):

import tarfile
ti = tarfile.TarInfo("leak_hosts")
ti.type = tarfile.LNKTYPE
ti.linkname = "/etc/hosts"  # or "../etc/hosts" or ".."
ti.size = 0
with tarfile.open("/tmp/hardlink.tar", "w") as t:
	t.addfile(ti)

function                                             old     new   delta
skip_unsafe_prefix                                     -     127    +127
get_header_tar                                      1752    1754      +2
.rodata                                           106861  106856      -5
unzip_main                                          2715    2706      -9
strip_unsafe_prefix                                  102      18     -84
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/3 up/down: 129/-98)            Total: 31 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-29 12:01:56 +01:00
Denys Vlasenko 768ab5384c httpd: do not use a global variable in index.cgi
text	   data	    bss	    dec	    hex	filename
   3255	      0	      0	   3255	    cb7	httpd_indexcgi.o
   3253	      0	      4	   3257	    cb9	httpd_indexcgi.o.old

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-29 02:39:31 +01:00
Denys Vlasenko df1ef312a0 httpd: handle bare "Location: URL" redirects from CGIs
Many sites on the Web give those as valid CGI examples -
no "Status:", just "Location:".

function                                             old     new   delta
cgi_io_loop_and_exit                                 620     684     +64
log_cgi_status                                         -      49     +49
.rodata                                           106846  106861     +15
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 2/0 up/down: 128/0)             Total: 128 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-28 17:45:37 +01:00
Denys Vlasenko 03d6d1014a ash: fix \ooo octal printout in DEBUG code
function                                             old     new   delta
ash_main                                            1624    1645     +21

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-28 15:12:43 +01:00
Denys Vlasenko 56143ea63f ash: code shrink: eliminate pstrcmp1()
function                                             old     new   delta
find_command                                         961     963      +2
evalcommand                                         1631    1633      +2
hashcmd                                              299     300      +1
describe_command                                     320     321      +1
clearcmdentry                                         93      94      +1
cdcmd                                                695     696      +1
pstrcmp1                                              16       -     -16
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 6/0 up/down: 8/-16)              Total: -8 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-28 09:23:54 +01:00
Denys Vlasenko 758c948a63 ash: remove non-standard chdir builtin
function                                             old     new   delta
.rodata                                           106853  106846      -7
builtintab                                           352     344      -8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-15)             Total: -15 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-28 01:34:13 +01:00
Denys Vlasenko 77d242d7ac ash: get rid of a static in cmdlookup()/delete_cmd_entry()
function                                             old     new   delta
cmdlookup_pp                                           -     120    +120
find_command                                         953     961      +8
unsetcmd                                              74      76      +2
hashcmd                                              297     299      +2
lastcmdentry                                           4       -      -4
delete_cmd_entry                                      47      43      -4
cmdlookup                                            132       -    -132
------------------------------------------------------------------------------
(add/remove: 1/2 grow/shrink: 3/1 up/down: 132/-140)           Total: -8 bytes
   text	   data	    bss	    dec	    hex	filename
  47470	      8	    149	  47627	   ba0b	shell/ash.o.orig
  47466	      8	    145	  47619	   ba03	shell/ash.o

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-28 01:01:15 +01:00
Denys Vlasenko 2051c69358 ash: group command hashing/searching code together, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-28 00:34:22 +01:00
Denys Vlasenko e05b922c89 ash: move casematch() directly to its only caller, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-27 23:44:06 +01:00
Denys Vlasenko c9af9073b8 ash: reorder functions to reduce forward declarations, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-27 17:08:12 +01:00
Denys Vlasenko b715e82e1f ash: JOBSTOPPED can only be set if job control is compiled in - conditionalize code which depends on it
With !ASH_JOB_CONTROL:

function                                             old     new   delta
cmdloop                                              363     351     -12
exitcmd                                               47      31     -16
.rodata                                           106422  106398     -24
stoppedjobs                                           58       -     -58
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 0/3 up/down: 0/-110)           Total: -110 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-27 13:15:14 +01:00
Denys Vlasenko dee0168219 ash: reorder functions to reduce forward declarations, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-27 13:15:13 +01:00
Denys Vlasenko 97a7813971 ash: move applet handling out of tryexec() - making it similar to dash
function                                             old     new   delta
tryexec                                                -      60     +60
shellexec                                            476     349    -127
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/1 up/down: 60/-127)           Total: -67 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-27 11:17:38 +01:00
Denys Vlasenko e4f4bf95ac doc: update docs/nofork_noexec.txt
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-27 08:13:42 +01:00
Denys Vlasenko 22b96c0ddf ash: unset traps before entering NOEXEC programs after [v]fork
If we don't do that, if INT trap was set, ^C will set a flag
"run trap later" and _return_, which is not expected by the NOFORK!

function                                             old     new   delta
clear_traps                                            -     107    +107
evalcommand                                         1617    1631     +14
shellexec                                            471     476      +5
setsignal                                            333     327      -6
forkchild                                            620     480    -140
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 2/2 up/down: 126/-146)          Total: -20 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-27 08:03:15 +01:00
Denys Vlasenko 28e4d2b854 httpd: optimize example CGIs
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-26 07:21:11 +01:00
Wouter Franken 4e82d99460 libbb/loop: fix existence check for LOOP_CONFIGURE ioctl
The LOOP_CONFIGURE ioctl is supported in 5.8 kernels and up. To have
backwards compatibility there is a config option CONFIG_TRY_LOOP_CONFIGURE
that will check if the ioctl exists and if not fall back to old way of
configuring loop devices.

Normally errno will be set to EINVAL when this ioctl does not exist.
However, when kernel config CONFIG_COMPAT is enabled, then compat_ioctl
is called. In that case -ENOIOCTLCMD is returned by loop device driver
and generic ioctl wrapper will set errno to ENOTTY. Because busybox
does not expect this it will fail to mount loop devices in this case.

This patch fixes the check for the existence of the ioctl LOOP_CONFIGURE
by checking if errno is one of both: EINVAL or ENOTTY.

function                                             old     new   delta
set_loop                                             809     821     +12

Signed-off-by: Wouter Franken <wouter.franken_ext@softathome.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-26 05:43:17 +01:00
Denys Vlasenko 4da1badf13 networking/httpd_indexcgi.c: non-mallocing version
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-26 04:48:28 +01:00
Denys Vlasenko 052b253696 httpd: add a TODO, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-25 08:17:23 +01:00
Denys Vlasenko 1db8aa2b59 ash: code shrink
function                                             old     new   delta
fg_bgcmd                                             294     296      +2
killpg                                                43       -     -43
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 1/0 up/down: 2/-43)             Total: -41 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-24 23:14:33 +01:00
Denys Vlasenko ea7d310ad6 httpd: allow static files in /cgi-bin/, do not search for interpreter twice
function                                             old     new   delta
handle_incoming_and_exit                            2270    2334     +64
send_cgi_and_exit                                    790     754     -36
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 64/-36)             Total: 28 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-24 17:11:39 +01:00
Denys Vlasenko 898cffe5f9 ash,hush: allow 0x in arith (bash supports it for 0x$v case when v='')
function                                             old     new   delta
parse_with_base                                      174     196     +22

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-24 14:37:22 +01:00
Denys Vlasenko a2f8c89aec httpd: code shrink
function                                             old     new   delta
send_file_and_exit                                   931     933      +2
get_line                                             126     120      -6
httpd_main                                           968     959      -9
send_headers                                         708     694     -14
handle_incoming_and_exit                            2285    2270     -15
cgi_io_loop_and_exit                                 635     620     -15
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/5 up/down: 2/-59)             Total: -57 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-24 13:29:50 +01:00
Denys Vlasenko 5cba59e9ce awk: use more understandable form of "split-globals" trick
function                                             old     new   delta
parse_expr                                           986     998     +12
chain_group                                          633     640      +7
next_token                                           930     934      +4
getvar_s                                             102     101      -1
awk_main                                             891     888      -3
evaluate                                            3379    3355     -24
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/3 up/down: 23/-28)             Total: -5 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-24 05:43:45 +01:00
Denys Vlasenko 43982ed499 httpd: code shrink via "split-globals" trick
function                                             old     new   delta
httpd_main                                           957     968     +11
log_and_exit                                          25      26      +1
send_headers                                         712     708      -4
handle_incoming_and_exit                            2292    2285      -7
sigalrm_handler                                      102      93      -9
parse_conf                                          1332    1323      -9
send_cgi_and_exit                                    803     790     -13
cgi_io_loop_and_exit                                 656     635     -21
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/6 up/down: 12/-63)            Total: -51 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-24 05:22:33 +01:00
Denys Vlasenko 1a64fe3594 httpd: implement POSTDATA read timeout, and -K KILLSECS CGI lifetime control
function                                             old     new   delta
cgi_io_loop_and_exit                                 496     656    +160
sigalrm_handler                                        1     102    +101
.rodata                                           106814  106853     +39
send_cgi_and_exit                                    770     803     +33
packed_usage                                       35894   35924     +30
httpd_main                                           950     957      +7
handle_incoming_and_exit                            2297    2292      -5
send_REQUEST_TIMEOUT_and_exit                         10       -     -10
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 6/1 up/down: 370/-15)           Total: 355 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-24 02:01:42 +01:00
Denys Vlasenko 927ff335c5 httpd: fix incorrect == comparison in last commit, must be !=
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-23 11:32:32 +01:00
Denys Vlasenko 5d33dbb67c httpd: smarter handling of CGI's "Status: " header
Do one less write()

function                                             old     new   delta
handle_incoming_and_exit                            2290    2297      +7
cgi_io_loop_and_exit                                 498     500      +2
.rodata                                           106821  106814      -7
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 9/-7)                Total: 2 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-23 11:04:28 +01:00
Denys Vlasenko a5f120b620 httpd: simplify CGI headers handling, check "HTTP/1.1" prefix, not just "HTTP"
function                                             old     new   delta
cgi_io_loop_and_exit                                 477     498     +21
.rodata                                           106830  106821      -9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 21/-9)              Total: 12 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-23 10:14:04 +01:00
Denys Vlasenko 01ea35e81d httpd: simplify CGI code a bit, add a bunch of TODOs and FIXMEs
function                                             old     new   delta
log_and_exit                                          33      25      -8
handle_incoming_and_exit                            2298    2290      -8
send_cgi_and_exit                                    784     770     -14
cgi_io_loop_and_exit                                 538     477     -61
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/4 up/down: 0/-91)             Total: -91 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-23 02:18:30 +01:00
Denys Vlasenko 2d78809b74 httpd: do not force clean connection termination on write errors and timeouts
function                                             old     new   delta
send_file_and_exit                                   891     931     +40
send_EOF_and_exit                                      -      14     +14
cgi_io_loop_and_exit                                 535     538      +3
log_and_exit                                          44      33     -11
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 2/1 up/down: 57/-11)             Total: 46 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-22 22:35:58 +01:00
Denys Vlasenko 04d8729adb httpd: make timeout messages less confusing
function                                             old     new   delta
send_file_and_exit                                   891     930     +39

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-22 21:21:16 +01:00
Denys Vlasenko d8059bd827 httpd: time out data writes after 60 seconds of no progress
function                                             old     new   delta
prepare_write_timeout                                  -      29     +29
static.tv                                              -      16     +16
httpd_main                                           939     950     +11
send_file_and_exit                                   887     891      +4
handle_incoming_and_exit                            2306    2298      -8
cgi_io_loop_and_exit                                 552     535     -17
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 2/2 up/down: 60/-25)             Total: 35 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-22 17:22:06 +01:00
Denys Vlasenko c1ed0c4049 httpd: optimize header reading timeout code
Set up the signal handler once, outside of main loop.
Do not reset the timer if headers are big - they still are expected
to arrive quickly.

function                                             old     new   delta
httpd_main                                           913     939     +26
handle_incoming_and_exit                            2312    2306      -6
get_line                                             134     126      -8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 26/-14)             Total: 12 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-22 15:49:58 +01:00
Denys Vlasenko 52a88341d6 httpd: when reading headers, abort if they are too long
function                                             old     new   delta
get_line                                             130     134      +4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-22 15:33:42 +01:00
Denys Vlasenko f0a63eefae httpd: reject request line and headers with control chars
This removes the need to check various corner cases later.

function                                             old     new   delta
get_line                                             108     130     +22

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-22 14:33:22 +01:00
Denys Vlasenko 851992f070 httpd: allow http2 requests if proxying, tighten METHOD checks
function                                             old     new   delta
handle_incoming_and_exit                            2264    2312     +48
httpd_main                                           915     913      -2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 48/-2)              Total: 46 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-22 13:58:28 +01:00
Denys Vlasenko 649da41ca4 httpd: fix compilation script of httpd_ratelimit_cgi.c
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-22 10:42:20 +01:00
Denys Vlasenko 3f36fe9c2f httpd: add -M MAXCONN - do not accept unlimited number of connections
We were lacking even basic rate-limiting.

function                                             old     new   delta
httpd_main                                           648     915    +267
handle_incoming_and_exit                            2235    2264     +29
packed_usage                                       35868   35894     +26
cgi_io_loop_and_exit                                 537     552     +15
send_headers                                         704     712      +8
get_line                                             106     108      +2
.rodata                                           106829  106830      +1
send_file_and_exit                                   890     887      -3
mini_httpd                                           161       -    -161
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 7/1 up/down: 348/-164)          Total: 184 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-22 01:58:46 +01:00
Denys Vlasenko 5ac9d0a865 httpd: stop disabling/enabling SIGHUP in every child
function                                             old     new   delta
sighup_handler                                        30      47     +17
httpd_main                                           710     695     -15
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 17/-15)              Total: 2 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-21 19:16:29 +01:00
Denys Vlasenko 71c703c26b httpd: remove one close() from main loop
function                                             old     new   delta
httpd_main                                           701     710      +9

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-21 19:01:42 +01:00
Denys Vlasenko 58b46b7d67 networking/httpd_ratelimit_cgi.c: new example CGI handler
text	   data	    bss	    dec	    hex	filename
   4003	     40	    352	   4395	   112b	httpd_ratelimit_cgi

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-21 18:47:56 +01:00
Denys Vlasenko 38721685af httpd: expand logging: now can see what CGIs are started
function                                             old     new   delta
send_cgi_and_exit                                    711     784     +73
vmstat_main                                          657     708     +51
.rodata                                           106746  106778     +32
send_file_and_exit                                   877     887     +10
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/0 up/down: 166/0)             Total: 166 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-21 17:49:40 +01:00
Denys Vlasenko b96342799f vmstat: fix I/O, int and ctxt rates: need to be divided by seconds
function                                             old     new   delta
vmstat_main                                          657     708     +51

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-20 01:34:08 +01:00
Denys Vlasenko 3a8d2db1ce vmstat: fixes for >4TB memory and long sampling intervals
function                                             old     new   delta
load_row                                             661    1061    +400
vmstat_main                                          561     657     +96
.rodata                                           106716  106746     +30
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 526/0)             Total: 526 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-20 00:41:47 +01:00
Denys Vlasenko 1ef0c69db4 vmstat: fix "vmstat N 0" to act compatibly (do not print infinitely)
function                                             old     new   delta
vmstat_main                                          559     561      +2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-19 02:52:06 +01:00
Denys Vlasenko afb92adf47 vmstat: smarter handling of header re-printing
function                                             old     new   delta
vmstat_main                                          230     559    +329
print_row                                            340       -    -340
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/0 up/down: 329/-340)          Total: -11 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-19 02:16:10 +01:00
Denys Vlasenko fd2ce3fa27 vmstat: show shorter, human-readable accumulating counts if they grow large
function                                             old     new   delta
print_row                                            247     340     +93
.rodata                                           106717  106716      -1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 93/-1)              Total: 92 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-18 18:57:37 +01:00
Denys Vlasenko 6ba6f5f6ab vmstat: reduce the chances of misaligned columns
function                                             old     new   delta
print_row                                            215     247     +32

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-18 18:09:12 +01:00
Denys Vlasenko c21d8ff8c5 vmstat: code shrink
function                                             old     new   delta
load_row                                             667     661      -6
next_col                                             105      59     -46
coldescs                                             239     146     -93
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-145)           Total: -145 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-18 16:51:35 +01:00
David Leonard c385dac31c procps: new applet: vmstat
Adds a compact vmstat applet that matches the default behaviour
of procps's vmstat.

function                                             old     new   delta
load_row                                               -     667    +667
.rodata                                           106441  106717    +276
coldescs                                               -     239    +239
vmstat_main                                            -     230    +230
print_row                                              -     215    +215
next_col                                               -     105    +105
find_col                                               -      78     +78
packed_usage                                       35828   35868     +40
applet_names                                        2849    2856      +7
applet_main                                         1640    1644      +4
applet_install_loc                                   205     206      +1
------------------------------------------------------------------------------
(add/remove: 7/0 grow/shrink: 5/0 up/down: 1862/0)           Total: 1862 bytes

Signed-off-by: David Leonard <d+busybox@adaptive-enterprises.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-18 10:58:46 +01:00
Achill Gilgenast 6f43f948bc adduser: remove preconfigured GECOS full name field
Pre-configuring "Linux User" as Full Name is confusing a lot of users
downstream.[1] For example, in geary e-mails were sent out as "Linux
User"[2] and I also saw a couple of git commits with this name. This name
does not bring any more improvements than just leaving this field
empty, and let applications most likely fallback to the username.

Alternative would be to set the field to `&` (Capitalized username,
according to passwd(5)) or that we just set the GECOS field downstream.

[1] https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/issues/2214
[2] https://gitlab.gnome.org/GNOME/geary/-/issues/1486

function                                             old     new   delta
.rodata                                           106455  106441     -14

Signed-off-by: Achill Gilgenast <achill@achill.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-18 03:17:00 +01:00
Martin Storsjö 993d416d02 md5/sha1sum: Honor the -b flag in the output
The output of md5sum/sha1sum contains a character to indicate
what mode was used to read the file - '*' for binary, and ' '
for text or where binary is insignificant.

This flag character makes a difference for the ffmpeg testsuite.
This testsuite contains a number of reference files (e.g. [1]),
containing the expected md5sum output for those files, which is
checked verbatim.

By making busybox's md5sum honor this flag in the output,
ffmpeg's testsuite can run successfully on top of busybox.

The flag is only partially implemented; in coreutils md5sum,
a later "-t" option overrides an earlier "-b" option. Here,
just check if a "-b" option was specified or not. Neither
flag affects how the files actually are read.

[1] https://code.ffmpeg.org/FFmpeg/FFmpeg/src/commit/894da5ca7d742e4429ffb2af534fcda0103ef593/tests/ref/acodec/flac

Signed-off-by: Martin Storsjö <martin@martin.st>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-18 03:09:52 +01:00
Denys Vlasenko fc9d352b4c cmp: fix -n causing all diffs to be output, implement size suffixes for SKIP
function                                             old     new   delta
packed_usage                                       35802   35828     +26
cmp_main                                             616     595     -21
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 26/-21)              Total: 5 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-18 02:41:20 +01:00
Giorgi Tchankvetadze 3bfbce8312 cmp: stop skipping bytes if EOF is reached
Currently, if a skip value is larger than the file size, cmp will continue
to loop and call getc() until the skip count is satisfied, even though
EOF has been reached.

For large skip values (e.g., 1 billion), this results in significant
CPU waste and execution time (e.g., 11 seconds on a modern CPU).

This patch checks for EOF inside the skip loop and breaks early.

Test case:
$ touch empty.txt
$ time ./busybox cmp empty.txt empty.txt 1000000000 1000000000

Before:
real    0m10.937s

After:
real    0m0.002s

function                                             old     new   delta
cmp_main                                             594     616     +22

Signed-off-by: Giorgi Tchankvetadze <giorgitchankvetadze1997@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-18 01:41:19 +01:00
Denys Vlasenko 26e9afe22d coreutils: fixes for coreutils/id_test.sh script
Patch from Tito

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-18 01:37:53 +01:00
Giorgi Tchankvetadze 3b785b18d2 networking/udhcp: fix typo in comment
Signed-off-by: Giorgi Tchankvetadze <giorgitchankvetadze1997@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-14 08:08:26 +01:00
Denys Vlasenko d755846906 xxd: fix -pANYTHING handling (-pc50 does not mean -p -c50)
function                                             old     new   delta
packed_usage                                       35768   35802     +34
xxd_main                                            1447    1449      +2
.rodata                                           106438  106439      +1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 37/0)               Total: 37 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-11-30 06:13:15 +01:00
Denys Vlasenko b143b3f1d4 tls: better error message when TLS record is truncated
function                                             old     new   delta
.rodata                                           106388  106438     +50
tls_xread_record                                     650     681     +31
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 81/0)               Total: 81 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-11-25 02:47:10 +01:00
Denys Vlasenko 8d7ae80eda eject: fix missing -s option in trivial usage
Fixes missing [-s] option in trivial usage section of `eject --help`

function                                             old     new   delta
packed_usage                                       35125   35127      +2

Signed-off-by: Nir Lichtman <nir@lichtman.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-11-08 07:42:34 +01:00
Denys Vlasenko b8cf048880 dd: fix overflow for very large count/seek/skip values
function                                             old     new   delta
xatoull_range_sfx                                      -      49     +49
dd_main                                             1607    1640     +33
bb_banner                                             47      46      -1
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/1 up/down: 82/-1)              Total: 81 bytes

Signed-off-by: Sertonix <sertonix@posteo.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-11-08 07:42:34 +01:00
Denys Vlasenko 4ee218a2d2 pgrep/pkill: fix -x to also match comm field
When running `pgrep -x example` against a process `/bin/example --arg`,
BusyBox fails to match, while GNU pgrep succeeds. The reason is that the
comparison is done only against the full argv[0] rather than comm. This
patch changes pgrep -x to also try /proc/[pid]/comm for exact matching.

function                                             old     new   delta
pgrep_main                                           681     670     -11

Signed-off-by: Paulius Zaleckas <paulius.zaleckas@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-11-08 07:42:34 +01:00
Denys Vlasenko d549c8be86 ls: restore functionality of --color
Since commit 551bfdb97 (ls: implement -q, fix -w0, reduce startup
time) the '--color' option behaves as though the default argument
'always' had been specified.

This is due to an explicit short option for '--color' being given,
but without specifying that an argument is expected.

function                                             old     new   delta
.rodata                                           106027  106029      +2

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-11-08 07:42:34 +01:00
Denys Vlasenko 8cafd7a908 lineedit: fix PS1='\W' for root directory
'\W' in PS1 returned an empty string for the root directory.  bash
displays '/' in similar circumstances.

Avoid returning an empty string for the directory.

function                                             old     new   delta
parse_and_put_prompt                                 873     883     +10

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-11-08 07:42:34 +01:00
Denys Vlasenko 782e3fc2b4 last: fix ignoring the first login entry
The first login entry is ignored if a log file contains more than one
entry. To fix it, do not break the while loop if the offset is zero.

Signed-off-by: Dmitry Klochkov <dmitry.klochkov@bell-sw.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-11-08 07:42:34 +01:00
Denys Vlasenko b99a529177 busybox: optional --version support
function                                             old     new   delta
busybox_main                                         695     734     +39

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-10-13 21:56:47 +02:00
Denys Vlasenko 3ff3cb483d ntpd: set tmx.maxerror properly - avoid STA_UNSYNC
function                                             old     new   delta
update_local_clock                                   872     951     +79

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-10-11 23:48:04 +02:00
Denys Vlasenko 3621595939 nsenter,unshare: don't use xvfork_parent_waits_and_exits(), it SEGVs on ppc64le
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-10-08 14:49:26 +02:00
Denys Vlasenko a0017a5b50 cp: fix cp -aT overwriting symlink to directories
busybox cp refuses to overwrite another symlink to a directory due to
an incorrect stat() call that should be lstat(). When using -T, we want
to consider the target argument directly without resolving symlinks.

function                                             old     new   delta
cp_main                                              496     514     +18

Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-10-07 10:05:08 +02:00
Denys Vlasenko 3cc2460952 chrt: support passing -p 0 to operate on self
Specifying a PID of 0 for the -p option of chrt would previously result
in a "number 0... not in range" error. Now, it means instead that the
calling process (i.e. chrt itself) should be operated on; this is to be
consistent with the behavior of util-linux's version of chrt.

function                                             old     new   delta
chrt_main                                            462     474     +12

Signed-off-by: Zuo An <zuoan.penguin@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-10-07 10:05:08 +02:00
Denys Vlasenko 552003dbd6 selinux: fix potential segfault in sestatus
Remove the puts(cterm) call that was likely leftover debugging code.
The controlling terminal name is already properly displayed via the
'Controlling term:' label, so the raw terminal name output was redundant
and could cause issues when cterm is NULL.

Also add proper cleanup for the allocated cterm string.

function                                             old     new   delta
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/0 up/down: 0/0)                 Total: 0 bytes

Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-10-07 10:05:08 +02:00
Denys Vlasenko 9443b0bc5e vi: warn about range in ':!' command
Currently vi in Busybox doesn't support filtering text through an
external command with ':1,2!cmd'.  Instead it behaves as if no
range had been supplied and displays the output of the command.

Issue a warning and do nothing in such cases.

function                                             old     new   delta
colon                                               3993    4010     +17

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-10-07 10:05:08 +02:00
Denys Vlasenko f5e1bf966b archival/libarchive: sanitize filenames on output (prevent control sequence attacks
This fixes CVE-2025-46394 (terminal escape sequence injection)

Original credit: Ian.Norton at entrust.com

function                                             old     new   delta
header_list                                            9      15      +6
header_verbose_list                                  239     244      +5
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 11/0)               Total: 11 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-09-24 03:30:12 +02:00
Denys Vlasenko 381a40a049 ash: change procargs() to match recent dash change
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-09-23 04:46:49 +02:00
Denys Vlasenko 3681b5f618 hush: changes to comments and whitespace, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-09-03 13:36:35 +02:00
Denys Vlasenko 106546961d ash: implement <<<here_string syntax
function                                             old     new   delta
write2pipe                                             -     133    +133
.rodata                                           105992  106009     +17
readtoken1                                          3101    3111     +10
cmdtxt                                               631     641     +10
nodesize                                              27      28      +1
redirect                                             961     916     -45
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 4/1 up/down: 171/-45)           Total: 126 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-09-02 11:46:11 +02:00
Denys Vlasenko b4cedd4c9a hush: fix several syntax corner cases with function definitions
function                                             old     new   delta
parse_stream                                        3063    3075     +12
done_word                                            777     784      +7
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 19/0)               Total: 19 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-18 14:52:46 +02:00
Denys Vlasenko 5d66c8a602 hush: shrink "function" code
function                                             old     new   delta
done_word                                            766     777     +11
static.reserved_match                                 16      12      -4
reserved_list                                        240     168     -72
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 11/-76)            Total: -65 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-18 13:55:09 +02:00
Denys Vlasenko 5c2c2916fc hush: do not SEGV on if { echo foo; } then { echo bar; } fi
For some reason, it was only happening in interactive use

function                                             old     new   delta
initialize_context                                    39      54     +15
parse_stream                                        3077    3063     -14
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 15/-14)              Total: 1 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-18 13:37:09 +02:00
Denys Vlasenko 2bdec03def hush: disentangle keyword detection, no logic changes
function                                             old     new   delta
done_word                                            790     766     -24

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-18 13:14:26 +02:00
Denys Vlasenko 2ccb891819 hush: make "function" keyword support optional
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-17 17:59:30 +02:00
Denys Vlasenko 84d4ac3754 hush: with --login, errors /etc/profile in must not exit shell
function                                             old     new   delta
die_if_script                                         28      34      +6
hush_main                                           1146    1150      +4
run_list                                            1031    1028      -3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 10/-3)               Total: 7 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-17 17:39:04 +02:00
Denys Vlasenko 96466951bf hush: recognize "function FUNC { cmd; }" syntax
function                                             old     new   delta
reserved_list                                          -     240    +240
parse_stream                                        2923    3077    +154
done_word                                            771     790     +19
.rodata                                           105975  105992     +17
static.reserved_match                                 12      16      +4
static.reserved_list                                 168       -    -168
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 4/0 up/down: 434/-168)          Total: 266 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-17 14:33:00 +02:00
Denys Vlasenko a30882dec5 hush: remove always-true conditional
function                                             old     new   delta
parse_stream                                        2940    2923     -17

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-17 13:47:34 +02:00
Denys Vlasenko 36f1b16b05 hush: fix infinite loop expanding alias a="nice&&a"
function                                             old     new   delta
parse_stream                                        2857    2940     +83
i_peek                                                55      69     +14
i_free_alias_buffer                                   33      37      +4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 101/0)             Total: 101 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-17 05:03:41 +02:00
Denys Vlasenko 1a947654b5 hush: comment fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-17 04:17:45 +02:00
Denys Vlasenko 94cb769b65 hush: make "alias" print aliases in properly escaped form
function                                             old     new   delta
print_pfx_escaped_nl                                   -      83     +83
builtin_alias                                        216     218      +2
.rodata                                           105985  105975     -10
parse_stream                                        2873    2857     -16
builtin_set                                          301     259     -42
builtin_readonly                                     107      59     -48
builtin_export                                       145      93     -52
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/5 up/down: 85/-168)           Total: -83 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-17 04:07:42 +02:00
Denys Vlasenko 7423bbbe98 hush: fix nested alias expansion
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-17 03:24:13 +02:00
Denys Vlasenko 5ba6ad7733 hush: optional alias support
function                                             old     new   delta
parse_stream                                        2540    2873    +333
i_getch                                               85     410    +325
builtin_alias                                          -     216    +216
builtin_unalias                                        -     185    +185
.rodata                                           105806  105985    +179
word_matches_alias                                     -      82     +82
find_alias_slot                                        -      77     +77
end_of_alias_name                                      -      69     +69
builtin_type                                         128     179     +51
i_free_alias_buffer                                    -      33     +33
enable_all_aliases                                     -      29     +29
bltins1                                              396     420     +24
o_reset_to_empty_unquoted                              -      21     +21
run_pipe                                            1554    1566     +12
i_peek                                                57      55      -2
parse_redirect                                       351     346      -5
redirect_opt_num                                      63      53     -10
encode_then_append_var_plusminus                     552     532     -20
done_word                                            796     771     -25
i_getch_interactive                                  308       -    -308
------------------------------------------------------------------------------
(add/remove: 8/1 grow/shrink: 6/5 up/down: 1636/-370)        Total: 1266 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-17 02:51:35 +02:00
Denys Vlasenko 5806d2a3db hush: optimization in set_local_var()
function                                             old     new   delta
set_local_var                                        416     409      -7

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-16 01:53:46 +02:00
Denys Vlasenko 3e766dce5f hush: implement <<<here_string syntax
function                                             old     new   delta
setup_heredoc                                        299     351     +52
parse_stream                                        2514    2540     +26
parse_redirect                                       335     351     +16
redir_table                                           40      48      +8
static.setup_redirects                               394     400      +6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 5/0 up/down: 108/0)             Total: 108 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-15 00:08:11 +02:00
Denys Vlasenko 0d1f6a54f7 hush: allow faster parsing for "./:@" characters
function                                             old     new   delta
parse_stream                                        2513    2514      +1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-14 20:08:19 +02:00
Denys Vlasenko a8f20420a5 hush: shrink syntax error handling
Was trying to add code to reject more invalid "case" syntaxes, but it's not that easy

function                                             old     new   delta
done_word                                            795     796      +1
parse_stream                                        2529    2513     -16
.rodata                                           105825  105806     -19
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 1/-35)             Total: -34 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-14 19:47:20 +02:00
Denys Vlasenko 6cc3380105 hush: undo incorrect change which allows a'b'=c to be assignment
While at it, remove now-unused WORD_IS_KEYWORD

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-14 16:19:58 +02:00
Denys Vlasenko cad5a79bd4 hush: explain "empty quoted str marker" trick
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-14 12:03:24 +02:00
Denys Vlasenko 4343ca9aa8 hush: improve code readability, no logic changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-14 11:08:08 +02:00
Denys Vlasenko 279371471e hush: move tickquote1.tests to hush-bugs/ - it's a known bug
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-14 05:02:07 +02:00
Denys Vlasenko d029e80187 hush: remove the is_blank dance
function                                             old     new   delta
parse_stream                                        2566    2524     -42

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-14 04:04:57 +02:00
Denys Vlasenko 2bb8b9b2a4 hush: remove two strchr's from the hottest parsing loop
function                                             old     new   delta
parse_stream                                        2572    2566      -6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-14 02:30:32 +02:00
Denys Vlasenko 438b92efdd hush: optimize decoding of $'str' - avoid extra function call if we can
function                                             old     new   delta
parse_stream                                        2565    2572      +7

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-13 23:20:10 +02:00
Denys Vlasenko f29ab91763 hush: shrink i_getch, rename two functions
Final link with: <none>
function                                             old     new   delta
i_getch_interactive                                    -     308    +308
i_getch                                              102      85     -17
fgetc_interactive                                    309       -    -309
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 0/1 up/down: 308/-326)          Total: -18 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-13 17:30:48 +02:00
Denys Vlasenko 187f24b490 hush: ~5% faster parsing of typical shell scripts
0-9,A-Z,a-z are never special and just go into the current word.

function                                             old     new   delta
parse_stream                                        2476    2565     +89

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-13 10:01:16 +02:00
Denys Vlasenko a5cf673c9c hush: create a macro IS_NULL_WORD to test for null shell word
No logic changes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-13 02:30:09 +02:00
Denys Vlasenko 1847fee2d4 hush: fix a corner case in "case" stmt, ctx_dsemicolon is in fact unused
function                                             old     new   delta
parse_stream                                        2446    2476     +30
done_word                                            797     800      +3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 33/0)               Total: 33 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-13 00:51:44 +02:00
Denys Vlasenko f161bc628f hush: allow nested negation "! ! ! CMD" - bash 5.2.15 allows it
Also, deindent "ch == EOF" code branch in parse_stream()

function                                             old     new   delta
done_word                                            799     797      -2
parse_stream                                        2453    2446      -7
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-9)               Total: -9 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-12 20:29:26 +02:00
Denys Vlasenko 2b0b74e8b4 hush: drop ctx_inverted, use pipe->pi_inverted
function                                             old     new   delta
done_word                                            776     799     +23
parse_stream                                        2456    2453      -3
done_pipe                                            252     242     -10
.rodata                                           105837  105825     -12
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/3 up/down: 23/-25)             Total: -2 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-12 20:29:26 +02:00
Denys Vlasenko 5ecbed0e26 hush: do not segfault on "for </dev/null v in..."
This is not accepted by bash, we may also disallow this,
but for now, at least do not crash

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-12 17:56:58 +02:00
Denys Vlasenko ab1de7df99 hush: test for, and disallow several invalid syntaxes
function                                             old     new   delta
parse_stream                                        2292    2456    +164
done_pipe                                            231     252     +21
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 185/0)             Total: 185 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-11 23:18:01 +02:00
Denys Vlasenko 1cd53c15a2 ash: parser: Invalid redirections are run-time, not syntax errors
Upstream commit

    Date: Wed, 14 Dec 2022 02:06:05 +0100
    parser: Invalid redirections are run-time, not syntax errors

    This fixes a long-standing bug where
      echo 'echo >&a' | sh
    errors out with
      sh: 2: Syntax error: Bad fd number
    despite the error being on line 1

    This patch makes the error
      sh: 1: Bad fd number: a
    as expected

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-11 18:43:02 +02:00
Denys Vlasenko 0da6c813e1 hush: fix var_backslash1.tests
function                                             old     new   delta
o_addqblock                                            -     131    +131
append_str_maybe_ifs_split                            53     100     +47
expand_one_var                                      1872    1897     +25
encode_then_expand_vararg                            380     399     +19
sig_unblock                                           41      43      +2
sig_block                                             41      40      -1
sigprocmask_allsigs                                   33      31      -2
expand_vars_to_list                                 1080    1077      -3
wait_for_child_or_signal                             202     193      -9
o_addQstr                                            175      42    -133
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 4/5 up/down: 224/-148)           Total: 76 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-11 17:36:02 +02:00
Denys Vlasenko d18c9eadf0 shells: testcase: add another test for EINTR on fifo open
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-11 14:10:17 +02:00
Denys Vlasenko e660eab458 *: code shrink using sigprocmask2() where appropriate
function                                             old     new   delta
sig_unblock                                           41      43      +2
sig_block                                             41      40      -1
sigprocmask_allsigs                                   33      31      -2
wait_for_child_or_signal                             202     193      -9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/3 up/down: 2/-12)             Total: -10 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-11 01:17:02 +02:00
Denys Vlasenko ea2022efb3 ash: converge waiting code to dash in its form, add comments, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-10 23:39:44 +02:00
Denys Vlasenko f6fb3c603a ash: move 100 bytes off global .data / .bss, no logic changes
text	   data	    bss	    dec	    hex	filename
1067871	    559	   5184	1073614	 1061ce	busybox_old
1068067	    555	   5088	1073710	 10622e	busybox_unstripped
            ^^^^^^^^^^^
function                                             old     new   delta
pgetc                                                580     623     +43
parse_command                                       1633    1651     +18
ash_main                                            1226    1239     +13
popstring                                            115     126     +11
redirect                                             951     961     +10
popfile                                              105     115     +10
expandstr                                            252     262     +10
evalbltin                                            306     314      +8
pushstring                                           155     162      +7
pushfile                                              31      38      +7
freestrings                                           90      97      +7
setinputstring                                        68      74      +6
readtoken1                                          3095    3101      +6
pungetc                                                9      15      +6
nlprompt                                              39      45      +6
nlnoprompt                                            33      39      +6
unwindfiles                                           20      25      +5
dotcmd                                               309     314      +5
setinputfile                                         190     194      +4
init                                                 429     432      +3
forkchild                                            617     620      +3
evalcommand                                         1616    1617      +1
ash_vmsg                                             141     142      +1
g_parsefile                                            4       -      -4
commandname                                            4       -      -4
basepf                                                84       -     -84
------------------------------------------------------------------------------
(add/remove: 0/3 grow/shrink: 23/0 up/down: 196/-92)          Total: 104 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-10 20:18:10 +02:00
Denys Vlasenko 9b67dde8cd ash: redir: Retry open on EINTR
Upstream commit:

    Date: Thu, 28 May 2020 21:31:45 +1000
    redir: Retry open64 on EINTR

    It is possible for open64 to block on named pipes, and therefore
    it can be interrupted by signals and return EINTR.  We should only
    let it fail with EINTR if real signals are pending (i.e., it should
    not fail on SIGCHLD if SIGCHLD has not been trapped).

    This patch adds a new helper sh_open to retry the open64 call if
    necessary.  It also calls sh_error when appropriate.

    Fixes: 3800d4934391 ("[JOBS] Fix dowait signal race")

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-09 20:17:31 +02:00
Denys Vlasenko 81274d8b30 ash: eval: Reset handler when entering a subshell
Upstream commit:

    Date: Sun, 3 Mar 2019 21:57:50 +0800
    eval: Reset handler when entering a subshell

    As it is a subshell can execute code that is only meant for the
    parent shell when it executes a longjmp that is caught by something
    like evalcommand.  This patch fixes it by resetting the handler
    when entering a subshell.

function                                             old     new   delta
evalsubshell                                         169     183     +14
evalpipe                                             342     356     +14
argstr                                              1406    1416     +10
ash_main                                            1236    1226     -10
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/1 up/down: 65/-10)             Total: 28 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-09 17:52:09 +02:00
Denys Vlasenko 4ce8afe6b2 ahs: jobs: Block signals during tcsetpgrp
Upstream commit:

    Date: Wed, 6 Jan 2021 15:45:12 +1100
    jobs: Block signals during tcsetpgrp

    Harald van Dijk <harald@gigawatt.nl> wrote:
    > On 19/12/2020 22:21, Steffen Nurpmeso wrote:
    >> Steffen Nurpmeso wrote in
    >>   <20201219172838.1B-WB%steffen@sdaoden.eu>:
    >>   |Long story short, after falsely accusing BSD make of not working
    >>
    >> After dinner i shortened it a bit more, and attach it again, ok?
    >> It is terrible, but now less redundant than before.
    >> Sorry for being so terse, that problem crosses my head for about
    >> a week, and i was totally mislead and if you bang your head
    >> against the wall so many hours bugs or misbehaviours in a handful
    >> of other programs is not the expected outcome.
    >
    > I think a minimal test case is simply
    >
    > all:
    >         $(SHELL) -c 'trap "echo TTOU" TTOU; set -m; echo all good'
    >
    > unless I accidentally oversimplified.
    >
    > The SIGTTOU is caused by setjobctl's xtcsetpgrp(fd, pgrp) call to make
    > its newly started process group the foreground process group when job
    > control is enabled, where xtcsetpgrp is a wrapper for tcsetpgrp. (That's
    > in dash, the other variants may have some small differences.) tcsetpgrp
    > has this little bit in its specification:
    >
    >        Attempts to use tcsetpgrp() from a process which is a member of
    >        a background process group on a fildes associated with its con‐
    >        trolling  terminal  shall  cause the process group to be sent a
    >        SIGTTOU signal. If the calling thread is blocking SIGTTOU  sig‐
    >        nals  or  the  process is ignoring SIGTTOU signals, the process
    >        shall be allowed to perform the operation,  and  no  signal  is
    >        sent.
    >
    > Ordinarily, when job control is enabled, SIGTTOU is ignored. However,
    > when a trap action is specified for SIGTTOU, the signal is not ignored,
    > and there is no blocking in place either, so the tcsetpgrp() call is not
    > allowed.
    >
    > The lowest impact change to make here, the one that otherwise preserves
    > the existing shell behaviour, is to block signals before calling
    > tcsetpgrp and unblocking them afterwards. This ensures SIGTTOU does not
    > get raised here, but also ensures that if SIGTTOU is sent to the shell
    > for another reason, there is no window where it gets silently ignored.
    >
    > Another way to fix this is by not trying to make the shell start a new
    > process group, or at least not make it the foreground process group.
    > Most other shells appear to not try to do this.

    This patch implements the blocking of SIGTTOU (and everything else)
    while we call tcsetpgrp.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-09 17:39:44 +02:00
Denys Vlasenko df154028dc ash: eval: Add vfork support
Upstream commit:

    Date: Sat, 19 May 2018 02:39:56 +0800
    eval: Add vfork support

    This patch adds basic vfork support for the case of a simple command.

Upstream commit:

    Date: Tue, 12 Jan 2021 17:11:19 +1100
    jobs: Always reset SIGINT/SIGQUIT handlers

    On Fri, Jan 08, 2021 at 08:55:41PM +0000, Harald van Dijk wrote:
    > On 18/05/2018 19:39, Herbert Xu wrote:
    > > This patch adds basic vfork support for the case of a simple command.
    > > ...  @@ -879,17 +892,30 @@ forkchild(struct job *jp, union node *n, int
    > > mode)
    > >   		}
    > >   	}
    > >   	if (!oldlvl && iflag) {
    > > -		setsignal(SIGINT);
    > > -		setsignal(SIGQUIT);
    > > +		if (mode != FORK_BG) {
    > > +			setsignal(SIGINT);
    > > +			setsignal(SIGQUIT);
    > > +		}
    > >   		setsignal(SIGTERM);
    > >   	}
    > > +
    > > +	if (lvforked)
    > > +		return;
    > > +
    > >   	for (jp = curjob; jp; jp = jp->prev_job)
    > >   		freejob(jp);
    > >   }
    >
    > This leaves SIGQUIT ignored in background jobs in interactive shells.
    >
    >   ENV= dash -ic 'dash -c "kill -QUIT \$\$; echo huh" & wait'
    >
    > As of dash 0.5.11, this prints "huh". Before, the subprocess process killed
    > itself before it could print anything. Other shells do not leave SIGQUIT
    > ignored.
    >
    > (In a few other shells, this also prints "huh", but in those other shells,
    > that is because the inner shell chooses to ignore SIGQUIT, not because the
    > outer shell leaves it ignored.)

    Thanks for catching this.  I have no idea how that got in there
    and it makes no sense whatsoever.  This patch removes the if
    conditional.

    Fixes: e94a964e7dd0 ("eval: Add vfork support")

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-09 17:36:18 +02:00
Denys Vlasenko 9f490785e0 ash: rename got_sigchld, doing_jobctl, and INT_ON/OFF to match dash
Comparing code with dash is more difficult with these differences.
(We didn't know back then that dash will be revived...)

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-09 17:17:48 +02:00
Denys Vlasenko 53b3854e81 ash: fix fallout of no-more-set commandname
Testsuite reports lots of message mismatches, fix that

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-09 17:04:16 +02:00
Denys Vlasenko c92755133b shells: fix a typo in var_backslash1.tests, expand it while at it
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-09 13:00:55 +02:00
Denys Vlasenko 4eb4141b22 ash: eval: Always set exitstatus in evaltree
Upstream commit:

    Date: Tue, 6 Dec 2022 16:49:14 +0800
    eval: Always set exitstatus in evaltree

    There is no harm in setting exitstatus unconditionally in evaltree.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-09 12:23:21 +02:00
Denys Vlasenko 6d44762589 ash: options: Do not set commandname in procargs
Upstream commit:

    Date:   Mon Feb 25 12:49:20 2019 +0800
    options: Do not set commandname in procargs

    We set commandname in procargs when we don't have to.  This results
    in a duplicated output of arg0 when an error occurs.

function                                             old     new   delta
ash_main                                            1256    1236     -20

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-09 02:26:51 +02:00
Denys Vlasenko 98b1a000c9 ash: jobs: drop unused node parameter in makejob()
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-09 02:02:04 +02:00
Denys Vlasenko fa82ef1a2e shells: add testsuite item
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-09 01:48:12 +02:00
Denys Vlasenko 5b3405594a ash: reuse vstype_suffix[] in debug code, shrink it
function                                             old     new   delta
vstype_suffix                                          -      39     +39
static.vstype                                         42       -     -42
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 0/0 up/down: 39/-42)             Total: -3 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-08 12:40:44 +02:00
Denys Vlasenko 422f4ede6f ash: fix cmdputs - was showing some variable forms incorrectly
function                                             old     new   delta
cmdputs                                              402     418     +16
static.vstype                                         48      42      -6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 16/-6)              Total: 10 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-07 23:42:45 +02:00
Denys Vlasenko 34948f1858 hush: smarter optimization for not-globbing [ and [[
function                                             old     new   delta
o_save_ptr                                           176     167      -9

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-07 02:46:04 +02:00
Denys Vlasenko abab146b82 ash: fix heredoc.tests broken by last commit
function                                             old     new   delta
readtoken1                                          3053    3095     +42
xxreadtoken                                          215     212      -3
expandstr                                            255     252      -3
parseheredoc                                         148     127     -21
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/3 up/down: 42/-27)             Total: 15 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-07 02:26:25 +02:00
Denys Vlasenko 7648dc721e ash,hush: fix corner cases with backslash-newlines in heredocs
function                                             old     new   delta
fetch_heredocs                                       477     485      +8

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-07 01:30:57 +02:00
Denys Vlasenko 558ef4962d hush: optimization: do not glob words "[" and "[["
function                                             old     new   delta
glob_needed                                           71      86     +15

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-07 00:20:56 +02:00
Denys Vlasenko 8f5d890071 showkey: make -a, -k, -s mutually exclusive
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-06 21:52:04 +02:00
Denys Vlasenko 0b05a4e71e top,pmap: speed up /smaps parsing
function                                             old     new   delta
procps_read_smaps                                    515     529     +14
procps_get_maps                                      685     665     -20
.rodata                                           105847  105820     -27
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 14/-47)            Total: -33 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-06 14:42:06 +02:00
Denys Vlasenko 47d27cdaff libbb: fix too-narrow variable in procps_read_smaps() causing incorrect sizes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-06 14:04:49 +02:00
Denys Vlasenko 40c2d01da2 libbb: make read_cmdline() replace chars 1..31 with '?', not space
Space was too inconspicuous on output

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-06 14:02:05 +02:00
Denys Vlasenko 8bde71eb15 top: simplify command line reading
function                                             old     new   delta
cmdline_to_line_buf_and_print                          -      48     +48
read_cmdline                                         326     327      +1
display_topmem_process_list                          523     505     -18
display_process_list                                1186    1161     -25
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/2 up/down: 49/-43)              Total: 6 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-06 00:42:05 +02:00
Denys Vlasenko 1bd8d714ca top: disentangle printing logic
function                                             old     new   delta
print_line_buf                                         -      78     +78
print_line_bold                                        -      50     +50
top_main                                            1043    1091     +48
handle_input                                         708     714      +6
do_stats                                             186     192      +6
.rodata                                           115543  115526     -17
display_topmem_process_list                          748     523    -225
display_process_list                                1432    1186    -246
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 3/3 up/down: 188/-488)         Total: -300 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-06 00:05:44 +02:00
Denys Vlasenko 2363938883 top: consistently NOT use the last column of the display
function                                             old     new   delta
.rodata                                           115537  115543      +6
top_main                                            1047    1043      -4
display_process_list                                1459    1432     -27
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 6/-31)             Total: -25 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-05 19:37:43 +02:00
Denys Vlasenko 5a8c03039f pmap: increase max handled command line length to 4k
function                                             old     new   delta
procps_get_maps                                      181     779    +598
read_smaps                                           563       -    -563
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/0 up/down: 598/-563)           Total: 35 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-05 14:35:14 +02:00
Denys Vlasenko d16bde623c top,pmap: do not use common code for reading /proc/PID/smaps
The logic is in fact quite far from common.

While at it, stop accounting "---p" mappings as mapped (e.g. VSZ in top).
Nothing is mapped there (why would kernel waste RAM to map pages
which can't be accessed?).

function                                             old     new   delta
read_smaps                                             -     562    +562
read_cmdline                                         315     326     +11
print_smaprec                                         97     101      +4
procps_scan                                         1219    1211      -8
.rodata                                           115541  115533      -8
skip_whitespace_if_prefixed_with                      25       -     -25
procps_read_smaps                                    864     577    -287
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 2/3 up/down: 577/-328)          Total: 249 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-05 14:21:51 +02:00
Denys Vlasenko 58b2353baa top: improve response time to keyboard input
function                                             old     new   delta
handle_input                                         674     708     +34
top_main                                            1019    1047     +28
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 62/0)               Total: 62 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-05 04:30:59 +02:00
Denys Vlasenko 3aa2bee269 top: reduce flicker: redraw screen with "clear to EOL" commands, not one "clear screen"
function                                             old     new   delta
display_topmem_process_list                          680     748     +68
display_process_list                                1403    1459     +56
.rodata                                           115512  115541     +29
top_main                                            1014    1019      +5
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/0 up/down: 158/0)             Total: 158 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-05 03:40:36 +02:00
Denys Vlasenko 1044533ea9 top: make uppercase 'S' walk topmem in opposite direction
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-05 03:13:01 +02:00
Denys Vlasenko d647d8aaba top: show RSS instead of VSF, virtual mapped size is often meaningless
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-05 03:07:40 +02:00
Denys Vlasenko c229982b33 top: fix display of very large VSZ
function                                             old     new   delta
display_process_list                                1366    1403     +37
handle_input                                         628     636      +8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 45/0)               Total: 45 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-05 02:57:05 +02:00
Denys Vlasenko c1b5c35246 top: do not rescan processes on second 's'
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-05 01:25:01 +02:00
Denys Vlasenko 5f3a986c9e libbb: simplify concat_path_file()
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-04 22:27:40 +02:00
Denys Vlasenko a33ce612b5 libbb: much faster concat_path_file()
function                                             old     new   delta
concat_path_file                                      68     127     +59

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-04 19:21:45 +02:00
Denys Vlasenko d7d8ffed87 shell: typo and whitespace fixes, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-03 23:29:35 +02:00
Denys Vlasenko 02b518db1c hush: fix memory leak caused by compiler optimizing out a store
function                                             old     new   delta
generate_stream_from_string                          222     232     +10
setup_heredoc                                        329     330      +1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 11/0)               Total: 11 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-03 20:42:52 +02:00
Denys Vlasenko 58a54fbd5a hush: disentangle interactiveness/job_control setup code
...and discover that we can do away with 1-3 initialization syscalls.

function                                             old     new   delta
hush_main                                           1152    1146      -6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-03 17:37:32 +02:00
Denys Vlasenko 778fce3e70 hush: fix build failure if !CONFIG_HUSH_JOB
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-03 16:22:21 +02:00
Denys Vlasenko dba57344b5 hush: make NORETURN declarations lees verbose, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-03 16:14:19 +02:00
Denys Vlasenko 4539262b6a hush: do not save history on xfunc error, it's unsafe
Also, make second calls to install_special_sighandlers() less haphazard.
It's not a fix for anything, but looking more organized now.

function                                             old     new   delta
fflush_restore_ttypgrp_and__exit                       -      20     +20
restore_ttypgrp_and__exit                             21       -     -21
hush_main                                           1181    1152     -29
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 0/1 up/down: 20/-50)            Total: -30 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-03 16:12:00 +02:00
Noelle Leigh 26fdc7c6ef docs: Add links to cmd description from cmd list
In the generated `docs/busybox.pod` file, add a link for each command in
the big command list that goes to that command's description, like a
compact table of contents. This seems to only affect the generated HTML
version of the usage page.

To add `id` attributes to each usage section title, each command now
uses `=head2` instead of `=item` for their section heading.

To add links to each command in the list, the list was unindented so
that it could use rich text, and each command was marked as code text
(C<>) so they are styled in monospace. These changes mean that the HTML
and mandoc command list will expand to fit the available width of the
viewport, rather than wrapping at a fixed line-length. The plain text
version retains its existing wrapping behavior.

Because of the new code text formatting, `--quotes=none` was added to
the pod2man and pod2text invocations in Makefile.custom to prevent the
command list from quoting every single command.

Signed-off-by: Noelle Leigh <noelle@noelle.dev>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-03 10:53:20 +02:00
Denys Vlasenko c2ef7c6dad hush: if !JOBS, skip tests which wouldn't work
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-03 09:32:36 +02:00
Denys Vlasenko cdbb6957f1 hush: don't save history in subshells; on NOMMU, don't be interactive on reexec
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-03 01:26:25 +02:00
Denys Vlasenko e591316e02 hush: rename hush_exit to save_history_run_exit_trap_and_exit, sigexit to restore_ttypgrp_and_killsig_or__exit
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-03 00:44:32 +02:00
Denys Vlasenko 7d782e8813 shell: fix the check of empty HISTFILE
The check for "" history file is done on a wrong state pointer.

Fixes: shell: empty HISTFILE disables history saving, just as unset one did

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-03 00:11:11 +02:00
Denys Vlasenko 91d8b4eb5c ftpd: code shrink, move replace_char() to libbb
function                                             old     new   delta
modprobe_main                                        803     804      +1
escape_text                                          127     122      -5
replace                                               18       -     -18
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/1 up/down: 1/-23)             Total: -22 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-02 07:18:56 +02:00
Denys Vlasenko 2d7ff2c909 ls: don't do unnecessary tty operations when called from ftpd
function                                             old     new   delta
ls_main                                              660     690     +30

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-01 18:16:46 +02:00
Denys Vlasenko 4f43bda947 ls: code shrink
Looks like gcc can figure this out by itself, but let's be explicit

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-01 12:10:22 +02:00
Denys Vlasenko 0fea54a983 libbb/dump: much faster formatting of %_u on x86
function                                             old     new   delta
display                                             1485    1481      -4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-01 03:01:38 +02:00
Denys Vlasenko e95086b2fa libbb/yescrypt: code shrink
function                                             old     new   delta
static.PBKDF2_SHA256                                 219     165     -54

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-01 02:21:38 +02:00
Denys Vlasenko 4f3a56dc12 ls: fix -Q to match GNU
function                                             old     new   delta
print_name                                           137     229     +92
display_files                                        375     402     +27
c_escape_conv_str00                                    -      24     +24
display                                             1476    1485      +9
conv_str                                              33       -     -33
------------------------------------------------------------------------------
(add/remove: 2/1 grow/shrink: 3/0 up/down: 152/-33)           Total: 119 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-01 01:02:43 +02:00
Denys Vlasenko bb18473216 ls: lack of -q should not suppress -Q
function                                             old     new   delta
print_name                                           134     137      +3
display_files                                        374     375      +1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 4/0)                 Total: 4 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-31 19:24:08 +02:00
Denys Vlasenko 551bfdb97f ls: implement -q, fix -w0, reduce startup time
function                                             old     new   delta
ls_main                                              598     660     +62
ls_longopts                                            -      47     +47
G_isatty                                               -      36     +36
print_name                                           102     134     +32
display_files                                        358     374     +16
.rodata                                           105829  105833      +4
vgetopt32                                           1330    1317     -13
static.ls_longopts                                    47       -     -47
------------------------------------------------------------------------------
(add/remove: 2/1 grow/shrink: 4/1 up/down: 197/-60)           Total: 137 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-31 18:35:11 +02:00
Denys Vlasenko a98b95b715 *: use safe_waitpid() or wait_any_nohang() where approppriate
function                                             old     new   delta
crond_main                                          1227    1237     +10
init_main                                            804     794     -10
wait_one                                             263     252     -11
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 10/-21)            Total: -11 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-30 20:02:23 +02:00
Valentin Lab 41f677ec5d crond: reap orphaned grandchildren to prevent zombie buildup
If a cron job launches a background task, e.g. `sh -c "sleep 5 &"`,
the shell exits immediately and the `sleep` process is re-parented to
PID 1.  When BusyBox `crond` itself happens to be PID 1 (common in a
minimal container), those orphans become direct children of `crond`.
Because `crond` only calls waitpid() for the PIDs it explicitly tracks,
these processes remain forever in Z state and the container slowly
fills with zombies.

Add a small `while (waitpid(-1, NULL, WNOHANG) > 0)` sweep at the end
of check_completions() so any stray children are reaped.  When `crond`
is not PID 1 the loop returns -ECHILD immediately, so behaviour and
overhead on a normal system are unchanged.

Size impact: +12 bytes on x86-64 (gcc 13.3.0 -Os, static)

Signed-off-by: Valentin Lab <valentin.lab@kalysto.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-30 19:49:23 +02:00
Ladislav Michl 427f808732 date: return failure exit code on clock_settime error
Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-30 19:44:39 +02:00
Denys Vlasenko 65deb9f7dd sha3sum: add -aBITS tests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-30 19:11:26 +02:00
Andy Knowles dcbb69e0a5 sha384sum: new applet
function                                             old     new   delta
sha512384_end                                          -     198    +198
packed_usage                                       35021   35134    +113
init384                                                -      80     +80
sha384_begin                                           -      19     +19
sha384_end                                             -      10     +10
applet_names                                        2823    2833     +10
md5_sha1_sum_main                                    501     507      +6
sha3_end                                              54      59      +5
applet_main                                         1628    1632      +4
show_usage_if_dash_dash_help                          79      72      -7
hash_file                                            358     344     -14
sha512_end                                           197      10    -187
------------------------------------------------------------------------------
(add/remove: 4/0 grow/shrink: 5/3 up/down: 445/-208)          Total: 237 bytes

Signed-off-by: Andy Knowles <aknowles@galleonec.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-30 18:39:46 +02:00
Denys Vlasenko 628a7b2f47 telnetd: improve --help
function                                             old     new   delta
packed_usage                                       34996   35021     +25

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-27 14:24:23 +02:00
Denys Vlasenko e022ff88d1 libbb: SHA-NI - document that unpckhpd also works, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-22 16:43:22 +02:00
Denys Vlasenko ed22c5bd4a libbb: SHA-NI code shrink
function                                             old     new   delta
sha256_process_block64_shaNI                         673     657     -16

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-22 00:12:54 +02:00
Denys Vlasenko d23ad55904 libbb: change define names in SHA-NI code to match kernel source more closely
No code changes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-21 08:45:02 +02:00
Denys Vlasenko 77a49a61b2 libbb/yescrypt: de-unroll salsa20()
function                                             old     new   delta
salsa20                                              760     296    -464

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-20 08:42:51 +02:00
Denys Vlasenko c6b9e76373 libbb: crypt_make_pw_salt(): fix yescrypt's random salt last char
function                                             old     new   delta
crypt_make_pw_salt                                   128     146     +18

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-19 18:42:32 +02:00
Denys Vlasenko 6979467a62 cryptpw: fix detection of crypt algo from salt (was broken if default isn't DES)
The symptom is: "cryptpw ... implicit" testsuite tests were failing
if CONFIG_FEATURE_DEFAULT_PASSWD_ALGO is not "des".

function                                             old     new   delta
cryptpw_main                                         223     283     +60
pw_encrypt                                           974     975      +1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 61/0)               Total: 61 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-19 18:20:01 +02:00
Denys Vlasenko 51b45ce28a libbb/yescrypt: code shrink
function                                             old     new   delta
blockmix_xor_save                                   1169     708    -461

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-19 17:20:35 +02:00
Denys Vlasenko 94591a1030 bootchartd: check the result of opendir("/proc")
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-19 02:26:20 +02:00
Denys Vlasenko ee2ef17cc7 tftp: use bb_error_msg instead of info_msg for a debug message
This is the only use of bb_info_msg in tftp.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-18 10:42:09 +02:00
Denys Vlasenko 27e1fc679e ntpd: replace two bb_info_msg's with bb_error_msg
All other messages are printed via bb_error_msg in this applet.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-18 10:34:17 +02:00
Denys Vlasenko 504f44436f sulogin: set ^C to SIG_DFL before execing the shell
function                                             old     new   delta
sulogin_main                                         331     340      +9

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-18 07:29:24 +02:00
Denys Vlasenko d2ef2c75c5 password applets: update help text
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-18 07:28:32 +02:00
Denys Vlasenko dde90f1d47 libbb.h: increase MAX_PW_SALT_LEN
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-17 17:34:14 +02:00
Denys Vlasenko b823735b7e libbb/yescrypt: actually, largest allowed salt is 86 chars, support that
function                                             old     new   delta
yescrypt_r                                           767     756     -11

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-17 17:01:40 +02:00
Denys Vlasenko abe0b45cd7 libbb/yescrypt: code shrink
function                                             old     new   delta
blockmix_xor                                        1177     702    -475

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-15 05:47:18 +02:00
Denys Vlasenko e62bfbcaed libbb/yescrypt: code shrink
function                                             old     new   delta
salsa20                                              684     650     -34
blockmix_salsa8                                      198     144     -54
blockmix                                             762     565    -197
blockmix_xor                                        1322    1028    -294
blockmix_xor_save                                   1499    1103    -396
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/5 up/down: 0/-975)           Total: -975 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-11 08:58:07 +02:00
Denys Vlasenko 95f169f3bb libbb/yescrypt: code shrink
function                                             old     new   delta
static.yescrypt_kdf32_body                           847     823     -24
yescrypt_r                                           805     767     -38
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-62)             Total: -62 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-09 10:38:11 +02:00
Denys Vlasenko 11d4c08d75 libbb/bitops.c: add inlining comment
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-09 08:21:47 +02:00
Denys Vlasenko c305c81c94 libbb: introduce and use block-XOR functions
On x86_64, they can be done in 16-byte blocks

64-bit:
function                                             old     new   delta
xorbuf_3                                               -      84     +84
xorbuf64_3_aligned64                                   -      58     +58
smix1                                                687     712     +25
xwrite_encrypted                                     520     534     +14
xorbuf16_aligned_long                                  -      13     +13
tls_xread_record                                     733     742      +9
xorbuf                                                21      13      -8
xorbuf_aligned_AES_BLOCK_SIZE                         15       -     -15
blockmix                                             814     762     -52
blockmix_salsa8                                      317     198    -119
blockmix_xor_save                                   1620    1499    -121
blockmix_xor                                        1543    1322    -221
------------------------------------------------------------------------------
(add/remove: 4/1 grow/shrink: 3/5 up/down: 203/-536)         Total: -333 bytes

32-bit:
function                                             old     new   delta
xorbuf_3                                               -      76     +76
xorbuf64_3_aligned64                                   -      36     +36
xorbuf16_aligned_long                                  -      23     +23
xwrite_encrypted                                     499     507      +8
tls_xread_record                                     646     650      +4
xorbuf                                                22      11     -11
xorbuf_aligned_AES_BLOCK_SIZE                         23       -     -23
blockmix                                            1083     938    -145
blockmix_salsa8                                      415     210    -205
blockmix_salsa8_xor                                  601     163    -438
blockmix_xor                                        2103    1533    -570
blockmix_xor_save                                   2614    1859    -755
------------------------------------------------------------------------------
(add/remove: 4/1 grow/shrink: 2/6 up/down: 147/-2147)       Total: -2000 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-09 07:00:59 +02:00
Denys Vlasenko e9c21c5c3a hush: fix SEGV on "echo << >" and such
function                                             old     new   delta
.rodata                                           105787  105823     +36
fetch_heredocs                                       461     477     +16
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 52/0)               Total: 52 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-08 10:36:12 +02:00
Denys Vlasenko 7b313c3465 libbb: code shrink in sha_crypt()
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-08 10:04:47 +02:00
Denys Vlasenko 0930708794 libbb/yescrypt: disable NROM code
function                                             old     new   delta
smix1                                                  -     595    +595
smix2                                                  -     414    +414
static.yescrypt_kdf32_body                           899     847     -52
static.smix2                                         420       -    -420
static.smix1                                         604       -    -604
------------------------------------------------------------------------------
(add/remove: 2/2 grow/shrink: 0/1 up/down: 1009/-1076)        Total: -67 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-08 06:52:27 +02:00
Denys Vlasenko d0f0874d57 libbb/yescrypt: disable code which accepts unusual yescrypt parameters
Almost any reasonable yescrypt hashes in /etc/shadow should only ever use
"jXY" parameters which set N and r. Fancy multi-byte-encoded
wide integers are not needed for that.

function                                             old     new   delta
static.yescrypt_kdf32_body                             -     899    +899
static.PBKDF2_SHA256                                 213     219      +6
decode64_uint32                                      141       -    -141
yescrypt_r                                           990     805    -185
yescrypt_kdf32_body                                 1423       -   -1423
------------------------------------------------------------------------------
(add/remove: 1/2 grow/shrink: 1/1 up/down: 905/-1749)        Total: -844 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-08 05:34:41 +02:00
Denys Vlasenko 78bd8a44b7 libbb/yescrypt: explain and shrink decode64_uint32()
function                                             old     new   delta
decode64_uint32                                      177     141     -36

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-08 03:47:48 +02:00
Denys Vlasenko d18ac080e4 libbb/yescrypt: code shrink
Setting EINVAL in errno is not necessary, just error return works.

function                                             old     new   delta
yescrypt_kdf32_body                                 1434    1423     -11
yescrypt_r                                          1029     990     -39
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-50)             Total: -50 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-08 00:16:56 +02:00
Denys Vlasenko 8466c3e78f libbb/yescrypt: madvise(MADV_HUGEPAGE) our usually very large allocation
Nearly ~2 faster run when buffer is gigabytes in size

function                                             old     new   delta
yescrypt_kdf32_body                                 1386    1406     +20

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-07 23:07:58 +02:00
Denys Vlasenko f8e9bd30d7 libbb/yescrypt: disable unrolling in two places
Also, make many define macros safer

function                                             old     new   delta
blockmix                                            2300     814   -1486
blockmix_xor                                        4606    1543   -3063
blockmix_xor_save                                   4737    1620   -3117
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-7666)         Total: -7666 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-07 22:34:31 +02:00
Denys Vlasenko e5d3a87633 libbb/yescrypt: 64-bit build fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-07 21:52:39 +02:00
Denys Vlasenko 7798f651a4 add libbb/yescrypt/PARAMETERS
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-07 21:36:31 +02:00
Denys Vlasenko 67b98c7b1b libbb/yescrypt: no need to find salt-terminating "$" twice
function                                             old     new   delta
yescrypt_r                                          1048    1029     -19

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-07 18:28:56 +02:00
Denys Vlasenko e3484095f9 libbb/yescrypt: code shrink
function                                             old     new   delta
yescrypt_r                                          1063    1048     -15

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-07 18:03:10 +02:00
Denys Vlasenko 5e9b95ff40 cryptpw: -m sha512crypt must also be accepted
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-07 17:42:35 +02:00
Denys Vlasenko 479d8db99f libbb/yescrypt: fix salts ending in dots (corresponding to binary zeros)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-07 17:26:47 +02:00
Denys Vlasenko 75758c7360 libbb/yescrypt: accept longer salts (up to 84 chars)
function                                             old     new   delta
cryptpw_main                                         214     223      +9
chpasswd_main                                        347     356      +9
passwd_main                                          931     934      +3
yescrypt_r                                          1084    1056     -28
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/1 up/down: 21/-28)             Total: -7 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-07 17:08:32 +02:00
Denys Vlasenko 63025e8bca libbb/yescrypt: remove forgotten SHA256 HMAC header file
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-07 10:51:13 +02:00
Denys Vlasenko f464be22bd libbb/yescrypt: make it possible to set constant parameters, and set YESCRYPT_RW
function                                             old     new   delta
yescrypt_kdf32_body                                 1052    1420    +368
yescrypt_r                                          1133    1084     -49
static.smix                                          762       -    -762
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/1 up/down: 368/-811)         Total: -443 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-07 10:39:14 +02:00
Denys Vlasenko c11730490a libbb/yescrypt: remove redundant SHA256 HMAC implementation
function                                             old     new   delta
hmac_blocks                                            -      88     +88
static.PBKDF2_SHA256                                 176     213     +37
yescrypt_kdf32_body                                 1046    1052      +6
static.smix                                          759     762      +3
hmac_block                                            88      64     -24
HMAC_SHA256_Final                                     53       -     -53
HMAC_SHA256_Buf                                       58       -     -58
HMAC_SHA256_Init                                     159       -    -159
------------------------------------------------------------------------------
(add/remove: 1/3 grow/shrink: 3/1 up/down: 134/-294)         Total: -160 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-07 08:21:44 +02:00
Denys Vlasenko 1a0913d57c libbb: factor out HMAC code from TLS
function                                             old     new   delta
hmac_block                                             -      88     +88
hmac_peek_hash                                         -      61     +61
hmac_end                                               -      50     +50
hmac_begin                                           140     177     +37
hmac_hash_v                                            -      30     +30
.rodata                                           105799  105787     -12
hmac_sha_precomputed                                  54       -     -54
hmac_sha_precomputed_v                                69       -     -69
hmac                                                  83       -     -83
------------------------------------------------------------------------------
(add/remove: 5/3 grow/shrink: 1/1 up/down: 266/-218)           Total: 48 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-07 07:44:01 +02:00
Denys Vlasenko e2091c9842 libbb: add two more forgotten source files
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-07 04:57:16 +02:00
Denys Vlasenko a2a5db41a3 libbb/pw_ascii64.c: add forgotten source file
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-07 00:04:10 +02:00
Denys Vlasenko 53de6e6150 libbb/yescrypt: use common ascii64 encoding routine
function                                             old     new   delta
num2str64_lsb_first                                   33      46     +13
yescrypt_r                                          1235    1133    -102
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 13/-102)           Total: -89 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-06 22:43:28 +02:00
Denys Vlasenko 5e17e3c6f4 libbb: shuffle ascii64 code around, shrink i2a64()
function                                             old     new   delta
num2str64_4chars_msb_first                             -      55     +55
num2str64_lsb_first                                    -      33     +33
i2a64                                                 42      25     -17
to64                                                  33       -     -33
to64_msb_first                                        55       -     -55
------------------------------------------------------------------------------
(add/remove: 2/2 grow/shrink: 0/1 up/down: 88/-105)           Total: -17 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-06 21:59:03 +02:00
Denys Vlasenko f3a1b7be72 libbb/yescrypt: remove one NOINLINE, add copyright headers, merge two source files
function                                             old     new   delta
pw_encrypt                                           945     974     +29
yes_crypt                                             50       -     -50
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/0 up/down: 29/-50)            Total: -21 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-06 20:59:00 +02:00
Denys Vlasenko 0574928c85 libbb/yescrypt: remove unused prefetching code
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-06 20:08:53 +02:00
Denys Vlasenko aebe6f7132 libbb/yescrypt: remove inlines (whcih gcc detects anyway) and dead ifderfs
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-06 19:47:29 +02:00
Denys Vlasenko 447eb6bf71 libbb: in DES crypt, error out on invalid salt chars
function                                             old     new   delta
des_crypt                                           1308    1327     +19

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-06 19:30:58 +02:00
Denys Vlasenko 82bbbd2e53 libbb: code shrink in DES crypt
function                                             old     new   delta
pw_encrypt                                           941     945      +4
bits32                                               128       -    -128
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/0 up/down: 4/-128)           Total: -124 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-06 19:14:09 +02:00
Denys Vlasenko 23b5527f5c libbb/yescrypt: use common ACSII char-to-64 conversion code
function                                             old     new   delta
a2i64                                                  -      46     +46
yescrypt_r                                          1215    1235     +20
decode64_uint32                                      167     177     +10
atoi64                                                25       -     -25
ascii_to_bin                                          53       -     -53
static.atoi64_partial                                 77       -     -77
------------------------------------------------------------------------------
(add/remove: 1/3 grow/shrink: 2/0 up/down: 76/-155)           Total: -79 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-06 19:08:57 +02:00
Denys Vlasenko f5af8aefea libbb/yescrypt: shrink PBKDF2
function                                             old     new   delta
static.PBKDF2_SHA256                                 189     176     -13

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-06 18:35:37 +02:00
Denys Vlasenko b8f7600166 libbb/yescrypt: more efficient byteswapping
function                                             old     new   delta
static.smix1                                         631     604     -27
static.smix2                                         452     420     -32
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-59)             Total: -59 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-06 18:27:16 +02:00
Denys Vlasenko 9c4cd75d12 restore mangled comment
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-06 11:16:43 +02:00
Denys Vlasenko 0893bc3bac libbb/yescrypt: code shrink
static.PBKDF2_SHA256                                   -     189    +189
HMAC_SHA256_Init                                       -     159    +159
HMAC_SHA256_Buf                                        -      58     +58
HMAC_SHA256_Final                                      -      53     +53
i2a64                                                  -      42     +42
yescrypt_r                                          1221    1215      -6
yescrypt_kdf32_body                                 1064    1046     -18
i64c                                                  42       -     -42
libcperciva_HMAC_SHA256_Final                         53       -     -53
libcperciva_HMAC_SHA256_Buf                           58       -     -58
ascii64                                               65       -     -65
libcperciva_HMAC_SHA256_Init                         159       -    -159
PBKDF2_SHA256                                        386       -    -386
------------------------------------------------------------------------------
(add/remove: 5/6 grow/shrink: 0/2 up/down: 501/-787)         Total: -286 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-06 11:12:13 +02:00
Denys Vlasenko b21cd481db libbb/yescrypt: code shrink
function                                             old     new   delta
libcperciva_HMAC_SHA256_Final                         56      53      -3

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-06 11:02:03 +02:00
Denys Vlasenko 62abd47815 Move "sha256-hash a memory array and produce the digest" helper to libbb
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-06 10:50:46 +02:00
Denys Vlasenko 4e5a6b6dbb libbb/yescrypt: remove extra sha256 implementation
function                                             old     new   delta
libcperciva_HMAC_SHA256_Init                           -     159    +159
libcperciva_HMAC_SHA256_Final                          -      56     +56
SHA256_Buf                                             -      40     +40
static.smix                                          753     759      +6
yescrypt_kdf32_body                                 1059    1060      +1
.rodata                                           105803  105799      -4
initial_state                                         32       -     -32
libcperciva_SHA256_Init                               37       -     -37
static.cpu_to_be32_vect                               51       -     -51
_HMAC_SHA256_Final                                    55       -     -55
PAD                                                   64       -     -64
libcperciva_HMAC_SHA256_Buf                          132      58     -74
libcperciva_SHA256_Buf                                86       -     -86
SHA256_Pad_Almost                                    131       -    -131
_SHA256_Final                                        195       -    -195
_SHA256_Update                                       198       -    -198
_HMAC_SHA256_Init                                    213       -    -213
Krnd                                                 256       -    -256
PBKDF2_SHA256                                       1003     386    -617
SHA256_Transform                                    3083       -   -3083
------------------------------------------------------------------------------
(add/remove: 3/12 grow/shrink: 2/3 up/down: 262/-5096)      Total: -4834 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-06 10:35:22 +02:00
Denys Vlasenko ffac25d056 libbb/yescrypt: comment tweaks
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-06 07:43:04 +02:00
Denys Vlasenko 8be6dafe94 libbb/yescrypt: use mmap for allocation, it's large - 16Mbytes
This automatically gives it alignment sufficient for any future SIMD
optimizations.

function                                             old     new   delta
yescrypt_r                                          1217    1221      +4
yescrypt_kdf32_body                                 1077    1059     -18
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 4/-18)             Total: -14 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-06 06:50:18 +02:00
Denys Vlasenko 736589f877 libbb/yescrypt: reduce the number of function parameters
function                                             old     new   delta
yescrypt_kdf32_body                                    -    1077   +1077
static.smix                                          739     753     +14
yescrypt_init_local                                   34       -     -34
yes_crypt                                             87      50     -37
yescrypt_free_local                                   49       -     -49
yescrypt_r                                          1288    1217     -71
static.yescrypt_kdf_body                            1166       -   -1166
------------------------------------------------------------------------------
(add/remove: 1/3 grow/shrink: 1/2 up/down: 1091/-1357)       Total: -266 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-06 06:05:08 +02:00
Denys Vlasenko 85d3c48217 libbb/yescrypt: code shrink in salt decoding
function                                             old     new   delta
yescrypt_r                                          1311    1288     -23

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-06 03:59:59 +02:00
Denys Vlasenko 1c977008e0 libbb/yescrypt: code shrink in parameter decoding
function                                             old     new   delta
decode64_uint32                                      166     167      +1
yescrypt_r                                          1342    1311     -31
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 1/-31)             Total: -30 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-06 03:40:06 +02:00
Denys Vlasenko 1524540613 libbb/yescrypt: remove unused variable
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-06 03:22:46 +02:00
Denys Vlasenko 9b6e03fd09 libbb/yescrypt: remove unused yescrypt_region_t tmp
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-06 03:03:38 +02:00
Denys Vlasenko e189464fa7 libbb/yescrypt: make some functions static
function                                             old     new   delta
static.yescrypt_kdf_body                               -    1166   +1166
yescrypt_r                                           692    1342    +650
atoi64                                                 -      25     +25
decode64_uint32                                      201     166     -35
encode64                                             153       -    -153
decode64                                             174       -    -174
yescrypt_kdf                                         442       -    -442
yescrypt_kdf_body                                   1239       -   -1239
------------------------------------------------------------------------------
(add/remove: 2/4 grow/shrink: 1/1 up/down: 1841/-2043)       Total: -202 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-06 02:39:07 +02:00
Denys Vlasenko 3d9b965b4a libbb/yescrypt: remove unused yescrypt_binary_t
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-06 01:35:23 +02:00
Denys Vlasenko bf8231d11d libbb/yescrypt: remove YESCRYPT_INIT_SHARED flag and code using it
It's only used by libxcrypt-4.4.38/lib/alg-yescrypt-opt.c code
(optimized code version?) which wasn't ported to busybox

function                                             old     new   delta
yescrypt_kdf                                         449     442      -7
static.smix                                          755     739     -16
alloc_region                                          72       -     -72
yescrypt_kdf_body                                   1467    1239    -228
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 0/3 up/down: 0/-323)           Total: -323 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-06 01:29:14 +02:00
Denys Vlasenko 10196929da libbb/yescrypt: remove unreachable support for scrypt hash ("$7$...")
function                                             old     new   delta
decode64                                             136     174     +38
decode64_uint32                                      166     201     +35
atoi64                                                25       -     -25
yescrypt_r                                           879     692    -187
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 2/1 up/down: 73/-212)          Total: -139 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-06 01:23:37 +02:00
Denys Vlasenko be327bed9d libbb/yescrypt: remove unused yescrypt_shared_t
function                                             old     new   delta
static.smix                                            -     755    +755
static.smix1                                           -     631    +631
static.smix2                                           -     452    +452
yescrypt_free_local                                    9      49     +40
yes_crypt                                             90      87      -3
yescrypt_r                                           890     879     -11
yescrypt_kdf                                         479     449     -30
free_region                                           47       -     -47
yescrypt_kdf_body                                   1724    1467    -257
smix2                                                659       -    -659
smix                                                 790       -    -790
smix1                                                960       -    -960
------------------------------------------------------------------------------
(add/remove: 3/4 grow/shrink: 1/4 up/down: 1878/-2757)       Total: -879 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-06 01:03:49 +02:00
Denys Vlasenko 444a91abc9 libbb/yescrypt: remove obviously unused, commented-out parts
No code changes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-06 00:55:08 +02:00
Denys Vlasenko 80e676664e libbb: add yescrypt password hashing support
It seems to work, but not at all optimized for size.
The extra copy of sha256 code need to be removed.

The yescrypt code in libbb/yescrypt/* is adapted from libxcrypt-4.4.38
with minimal edits, hopefully making it easier to track
backports by resetting the tree to this commit,
then comparing changes in upstream libxcrypt to the tree.

function                                             old     new   delta
blockmix_xor_save                                      -    7050   +7050
static.blockmix_xor                                    -    6475   +6475
blockmix                                               -    3390   +3390
SHA256_Transform                                       -    3083   +3083
yescrypt_kdf_body                                      -    1724   +1724
PBKDF2_SHA256                                          -    1003   +1003
smix1                                                  -     960    +960
yescrypt_r                                             -     890    +890
salsa20                                                -     804    +804
smix                                                   -     790    +790
smix2                                                  -     659    +659
blockmix_salsa8_xor                                    -     601    +601
yescrypt_kdf                                           -     479    +479
blockmix_salsa8                                        -     415    +415
Krnd                                                   -     256    +256
_HMAC_SHA256_Init                                      -     213    +213
_SHA256_Update                                         -     198    +198
_SHA256_Final                                          -     195    +195
decode64_uint32                                        -     166    +166
encode64                                               -     153    +153
decode64                                               -     136    +136
libcperciva_HMAC_SHA256_Buf                            -     132    +132
SHA256_Pad_Almost                                      -     131    +131
salsa20_simd_unshuffle                                 -     101    +101
salsa20_simd_shuffle                                   -     101    +101
yes_crypt                                              -      90     +90
libcperciva_SHA256_Buf                                 -      86     +86
crypt_make_rand64encoded                               -      85     +85
static.atoi64_partial                                  -      77     +77
alloc_region                                           -      72     +72
ascii64                                                -      65     +65
PAD                                                    -      64     +64
_HMAC_SHA256_Final                                     -      55     +55
static.cpu_to_be32_vect                                -      51     +51
free_region                                            -      47     +47
libcperciva_SHA256_Init                                -      37     +37
yescrypt_init_local                                    -      34     +34
crypt_make_pw_salt                                    92     125     +33
initial_state                                          -      32     +32
.rodata                                           105771  105803     +32
atoi64                                                 -      25     +25
explicit_bzero                                         -      22     +22
pw_encrypt                                           920     941     +21
yescrypt_free_local                                    -       9      +9
crypt_make_salt                                       85       -     -85
------------------------------------------------------------------------------
(add/remove: 43/1 grow/shrink: 3/0 up/down: 31042/-85)      Total: 30957 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-06 00:49:22 +02:00
Denys Vlasenko 84766710f4 whitespace fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-05 12:59:42 +02:00
Denys Vlasenko 142ac2d796 diff: code shrink
function                                             old     new   delta
diffreg                                             1317    1307     -10

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-04 21:40:51 +02:00
Denys Vlasenko 8d3d078917 shell: empty HISTFILE disables history saving, just as unset one did
The rationale here is that unsetting HISTFILE in /etc/profile
does not "stick": if it's unset, the default one is set later
(after /etc/profile is executed) by the shell.
But setting (and exporting, so it is inherited by all
(grand)child shells) an empty one works.

function                                             old     new   delta
save_history                                         296     316     +20

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-04 12:51:38 +02:00
Denys Vlasenko 9c46a06885 shell: update HISTFILESIZE code to be actually useful
"HISTFILESIZE=0" in profile wasn't working as intended,
"unset HISTFILE" wasn't preventing creation of history files
Now:
HISTSIZE=n      allows to reduce in-memory history buffer
HISTFILESIZE=n  allows to reduce history file size (0: truncate it)
unset HISTFILE  allows to not save history file at all

function                                             old     new   delta
exitshell                                            138     194     +56
hush_exit                                             97     143     +46
save_history                                         266     296     +30
hush_main                                           1170    1186     +16
.rodata                                           105762  105771      +9
load_history                                         246     254      +8
size_from_HISTFILESIZE                                44      41      -3
read_line_input                                     2746    2712     -34
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 6/2 up/down: 165/-37)           Total: 128 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-03 19:10:42 +02:00
Denys Vlasenko 36ac283682 shell: fix race between signal handlers setting bb_got_signal and poll()
function                                             old     new   delta
__ppoll_time64                                         -     211    +211
check_got_signal_and_poll                              -     164    +164
read_key                                             607     601      -6
shell_builtin_read                                  1328    1318     -10
------------------------------------------------------------------------------
(add/remove: 4/0 grow/shrink: 0/2 up/down: 375/-16)           Total: 359 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-02 22:42:47 +02:00
Denys Vlasenko bbaa56f737 use pollfd[1] array for poll() argument
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-02 21:55:42 +02:00
Sertonix 8c835540ef cpio: map -F to --file long option
function                                             old     new   delta
.rodata                                           100437  100444      +7
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 7/0)                 Total: 7 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-02 00:07:18 +02:00
Bin Meng 244f5c4795 libbb: Prevent clang from reading the G pointer before it is assigned
It was observed that getty crashes on RISC-V 64-bit target, with the
busybox binary compiled by clang/LLVM 17 with -O2. Not only getty,
but also some other applets like syslogd/vi are broken too.

Commit 5156b245 ("Make const ptr assign as function call in clang")
introduced XZALLOC_CONST_PTR() to defeat the compiler optimization,
however it only fixed a small number of broken places when compiling
busybox with clang/LLVM. A large number of places remain broken.

This commit treats ASSIGN_CONST_PTR() the same way as XZALLOC_CONST_PTR().

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-01 21:21:16 +02:00
Ron Yorston dcd8df258a shell: improve bash compatibility of read built-in
Make the read built-in more compatible with bash:

- Return an exit code of 142 on timeout.

- When the timeout expires before a newline is detected in the
  input bash captures the partial input.  This behaviour is new
  since bash version 4.4.  BusyBox shells had the pre-4.4 behaviour
  where the input was lost.

Update the tests to suit and fix a couple of compiler errors in
the testsuite.

function                                             old     new   delta
builtin_read                                         154     174     +20
readcmd                                              213     228     +15
shell_builtin_read                                  1364    1370      +6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 41/0)               Total: 41 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-01 20:21:37 +02:00
Denys Vlasenko 4b1f1da358 df: -k overrides block size to 1k even if $POSIXLY_CORRECT
function                                             old     new   delta
df_main                                             1060    1070     +10

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-01 19:26:50 +02:00
Radoslav Kolev e6317e72dd hexdump: add tests for %x, handle little/big endian properly
Signed-off-by: Radoslav Kolev <radoslav.kolev@suse.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-01 13:35:06 +02:00
Radoslav Kolev b8ce2084cd od: make -B test little endian only, add variant for big endian
Signed-off-by: Radoslav Kolev <radoslav.kolev@suse.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-01 13:34:12 +02:00
Radoslav Kolev f5c7cae55f hexdump: fix regression for uint16 on big endian systems
Commit 34751d8bf introduced a bug in the handling of uint16
values on big endian systems not considered safe for unaligned
access when falling back to memcpy.

Signed-off-by: Radoslav Kolev <radoslav.kolev@suse.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-01 13:31:45 +02:00
Michael Glembotzki 73c67d75ef ntpd: Raise MAXDIST to 3s for better tolerance and consistency with chrony
function                                             old     new   delta
select_and_cluster                                  1088    1093      +5

Signed-off-by: Michael Glembotzki <m.glembo@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-01 13:30:40 +02:00
Denys Vlasenko 58adc7b527 ip route: make cache printing a bit more similar to upstream
function                                             old     new   delta
print_route                                         1573    1565      -8

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-01 12:54:00 +02:00
Ahmad Fatoum 952a7b9cec lineedit: fix left-over print to stdout
There's code printing to stderr both before and after the single call to
puts inside put_cur_glyph_and_inc_cursor().

This is likely an oversight as we want everything to go through the
same file descriptor, so switch it over to fputs.

Fixes: fd47f05676 ("lineedit: print prompt and editing operations to stderr")
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-01 12:25:29 +02:00
Ahmad Fatoum 37abfb919d lineedit: fix printing lines during tab completion
Indentation and escape characters are all output to stderr now, but the
matches themself remained on stdout leading to garbled output on Tab
completion.

Print the results to stderr as well to fix this.

Fixes: fd47f05676 ("lineedit: print prompt and editing operations to stderr")
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-01 12:25:29 +02:00
Denys Vlasenko 5f07327251 cpio: error out if the file to be achived is >=4GB
function                                             old     new   delta
.rodata                                           105715  105751     +36
cpio_o                                              1145    1167     +22
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 58/0)               Total: 58 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-04-21 04:42:33 +02:00
Denys Vlasenko f13f68288f rpm2cpio: extract cpio even if compression is not known
This is more useful than failing outright.

function                                             old     new   delta
rpm2cpio_main                                        110     144     +34
.rodata                                           105681  105715     +34
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 68/0)               Total: 68 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-04-20 23:59:38 +02:00
Denys Vlasenko c61fdadf97 libbb/archival: make setup_unzip_on_fd() return bytes read if not compressed
setup_unzip_on_fd() does not return the transformer structure, so the user
does not know how much to seek back (or alternatively what the signature was)
when compressor signature is not detected.

Currently not needed (the only user is tar which dies anyway).
However, rpm2cpio may need this if we extend it to extract the internal .cpio
even if cpio's compressions algo is not known.

function                                             old     new   delta
setup_unzip_on_fd                                     53      59      +6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-04-20 23:49:33 +02:00
J. Neuschäfer 636315ccb9 runit: fix setuidgid help text
Signed-off-by: J. Neuschäfer <j.neuschaefer@gmx.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-04-17 07:06:21 +02:00
Denys Vlasenko 9a8796436b archival: disallow path traversals (CVE-2023-39810)
Create new configure option for archival/libarchive based extractions to
disallow path traversals.
As this is a paranoid option and might introduce backward
incompatibility, default it to no.

Fixes: CVE-2023-39810

Based on the patch by Peter Kaestle <peter.kaestle@nokia.com>

function                                             old     new   delta
data_extract_all                                     921     945     +24
strip_unsafe_prefix                                  101     102      +1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 25/0)               Total: 25 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-04-16 03:03:17 +02:00
Grant Erickson fc466720b5 syslogd: Fix 'OPT_locallog' check regression in 'syslogd_main'
In the recent refactoring of 'syslogd_main', a regression was
introduced in handling the manual bitwise OR of 'OPT_locallog' as
follows:

   if (ENABLE_FEATURE_REMOTE_LOG && !(opts & OPT_remotelog)) // -R
       option_mask32 |= OPT_locallog;

'opts' represents the locally-scoped output of 'getopt32' and
'option_mask32' represents the globally-scoped state of the
same. Consequently, the above performs a bitwise OR to include
'OPT_locallog' of the globally-scoped option state, which 'opts' will
not reflect locally.

Manipulating the global, rather than local, state is correct as
'timestamp_and_log_internal' will later need to check 'OPT_locallog'.

However, when the aforementioned refactor occurred, the following
regressing change was made:

    -       if (!ENABLE_FEATURE_REMOTE_LOG || (option_mask32 & OPT_locallog)) {
    +       if (!ENABLE_FEATURE_REMOTE_LOG || (opts & OPT_locallog)) {

breaking the spatially- and temporally-removed check in
'timestamp_and_log_internal'.

Fixes: 02378ce20c ("syslogd: decrease stack usage, ~50 bytes")

function                                             old     new   delta
syslogd_init                                        1140    1137      -3

Signed-off-by: Grant Erickson <gerickson@nuovations.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-04-08 16:14:34 +02:00
Denys Vlasenko d2d23c848a udhcpd: send DHCPOFFERs as unicast (unless clients specifically asks for bcast)
RFC 2131 says we should do that.
Evidently, since for so many years no one complained, sending them broadcast
works too, but finally we've got someone who wants RFC-compliand behavior.

function                                             old     new   delta
send_packet                                          141     179     +38
.rodata                                           105680  105681      +1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 39/0)               Total: 39 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-04-07 02:46:39 +02:00
Denys Vlasenko a8349b115d Makefile: fix passing of EXTRA_LDLIBS
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-04-06 12:13:16 +02:00
Sébastien Parisot f9274e8d6e init: improve log message when a process exits: show exit code
function                                             old     new   delta
.rodata                                           105649  105680     +31
init_main                                            776     804     +28
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 59/0)               Total: 59 bytes

Signed-off-by: Sébastien Parisot <sparisot@free-mobile.fr>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-04-06 10:44:04 +02:00
Denys Vlasenko 887295686d udhcpc6: fix copy-paste error in "generate a consistent IAID" commit
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-02-09 15:09:15 +01:00
Zhou Siqi 4115439496 udhcpc6: generate a consistent IAID
Currently, udhcpc6 does not meet the requirements for
Identity Association in RFC 3315.
This is a specific explanation in RFC 3315 protocol:
https://datatracker.ietf.org/doc/html/rfc3315#section-10
"The IAID uniquely identifies the IA and must be chosen to be unique
   among the IAIDs on the client.  The IAID is chosen by the client.
   For any given use of an IA by the client, the IAID for that IA MUST
   be consistent across restarts of the DHCP client."
This patch makes the client generate a consistent IAID based on the MAC address.

function                                             old     new   delta
send_d6_discover                                     285     270     -15

Signed-off-by: Zhou Siqi <zhousiqi5@huawei.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-02-09 13:51:33 +01:00
Denys Vlasenko 779cca899f udhcpc6: move block comment, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-02-09 12:54:50 +01:00
Laurent Bercot ef21820dc9 udhcpc6: improvements
Several small improvements to udhcpc6.

- Remove usage text for the nonexistent -B option.
- Fix a segfault when renewing an IA_PD lease without IA_NA (which means
the client hasn't been assigned an ip, so we cannot locally bind to it).
- Fix NAK management: check the option length, and print the status code
and status message
- Add a -m option to always send renew requests as multicast.

 These last two changes are useful to deal with hopelessly broken DHCPv6
servers such as the one from the Orange Livebox (one of the main French
ISPs) which I'm currently having the displeasure to have to talk to,
hence the patch.

function                                             old     new   delta
static.send_d6_renew                                   -     126    +126
.rodata                                           105598  105649     +51
udhcpc6_main                                        2607    2650     +43
packed_usage                                       34933   34953     +20
d6_send_kernel_packet_from_client_data_ifindex       266     282     +16
send_d6_renew                                        174       -    -174
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 4/0 up/down: 256/-174)           Total: 82 bytes

Signed-off-by: Laurent Bercot <ska-dietlibc@skarnet.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-02-09 12:52:02 +01:00
Denys Vlasenko 14f57f5357 cut: code shrink
move "linenum" manipulations to the one place where it is used.

function                                             old     new   delta
cut_main                                            1373    1360     -13

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-21 00:43:45 +01:00
Denys Vlasenko 1ea89fa98a cut: code shrink
This change eliminates one temporary:

-       if (dcount++ < cut_list[cl_pos].startpos)
+       dcount++;
+       if (dcount <= cut_list[cl_pos].startpos)

function                                             old     new   delta
cut_main                                            1402    1373     -29

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-21 00:24:30 +01:00
Denys Vlasenko b03f5162ac cut: fix up -D/-s behavior with -F
function                                             old     new   delta
cut_main                                            1388    1402     +14
packed_usage                                       34934   34933      -1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 14/-1)              Total: 13 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-20 22:12:33 +01:00
Denys Vlasenko dd40b40ee5 cut: remove unnecessary initialization of regmatch_t
function                                             old     new   delta
cut_main                                            1404    1388     -16

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-20 21:46:32 +01:00
Denys Vlasenko e2304d47a9 cut: shorten error messages on bad syntax even more
$ cut -s -b3
cut: -s requires -f or -F
$ cut -d@ -b3
cut: -d DELIM requires -f or -F

function                                             old     new   delta
static.requires_f                                      -      19     +19
static._op_on_field                                   32       -     -32
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 0/0 up/down: 19/-32)            Total: -13 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-16 01:12:17 +01:00
Denys Vlasenko ee8b94acbf cut: shorten error messages on bad syntax
We don't need to mimic GNU cut error messages.

$ cut -d@ -b3
cut: -d DELIM makes sense only with -f or -F
$ cut -s -b3
cut: -s makes sense only with -f or -F

function                                             old     new   delta
static._op_on_field                                   31      32      +1
.rodata                                           105659  105598     -61
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 1/-61)             Total: -60 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-16 00:53:51 +01:00
Denys Vlasenko 0bd84c9472 cut: terminate cut_list[] so that we don't need "size of the array" variable
function                                             old     new   delta
cut_main                                            1410    1404      -6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-16 00:32:57 +01:00
Denys Vlasenko ba9651b803 cut: we can't get empty cut_list[], remove the check for that
function                                             old     new   delta
.rodata                                           105685  105659     -26

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-16 00:19:43 +01:00
Denys Vlasenko e8622f0d85 cut: disallow -f '' and -f '-'
function                                             old     new   delta
cut_main                                            1391    1410     +19

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-15 12:27:33 +01:00
Denys Vlasenko b25ea3f156 cut: fix -F n-m to match toybox
function                                             old     new   delta
cut_main                                            1339    1391     +52

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-14 13:58:49 +01:00
Denys Vlasenko d48400d8fb cut: simplify getopt32 code
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-13 20:35:28 +01:00
Denys Vlasenko 7624077772 cut: "it's legal to pass an empty list" seems to be untrue
function                                             old     new   delta
cut_main                                            1344    1339      -5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-13 20:22:05 +01:00
Denys Vlasenko f4f8dc6864 cut: whitespace fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-13 19:43:53 +01:00
Denys Vlasenko ed6561685c cut: tweak comments
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-13 19:39:34 +01:00
Denys Vlasenko 96a230f17b cut: fix handling of -d ''
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-13 19:31:41 +01:00
Denys Vlasenko 9adafbc118 cut: prevent infinite loop if -F REGEX matches empty delimiter
function                                             old     new   delta
cut_main                                            1339    1348      +9

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-13 19:13:20 +01:00
Denys Vlasenko a4894eaf71 cut: tweak --help
function                                             old     new   delta
packed_usage                                       34901   34934     +33
cut_main                                            1353    1339     -14
.rodata                                           105724  105685     -39
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 33/-53)            Total: -20 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-11 01:10:05 +01:00
Denys Vlasenko 9e364b16d1 cut: fix -d$'\n' --output-delimiter=@@ behavior
function                                             old     new   delta
cut_main                                            1261    1353     +92
packed_usage                                       34925   34901     -24
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 92/-24)             Total: 68 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-10 21:01:52 +01:00
Denys Vlasenko a208fa03de cut: implement --output-delimiter
function                                             old     new   delta
cut_main                                            1204    1261     +57
static.cut_longopts                                    -      20     +20
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/0 up/down: 77/0)               Total: 77 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-10 18:49:10 +01:00
Denys Vlasenko b402b13fab cut: with -F disabled in .config, don't show it in --help
function                                             old     new   delta
packed_usage                                       34897   34849     -48

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-10 18:09:07 +01:00
Denys Vlasenko 38a3c0ad32 cut: comment out code which seems to be not needed
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-10 17:50:29 +01:00
Denys Vlasenko 103139d0e6 cut: fix "echo 1.2 | cut -d. -f1,3" (print "1", not "1.")
function                                             old     new   delta
cut_main                                            1228    1201     -27

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-10 17:21:30 +01:00
Denys Vlasenko 470f009552 cut: with -F, do not regcomp() pattern for every file
function                                             old     new   delta
cut_main                                            1218    1228     +10

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-10 02:55:58 +01:00
Denys Vlasenko 55fc6a18da cut: rename "cut_lists" to "cut_list"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-10 02:29:48 +01:00
Denys Vlasenko 1220b1519d cut: rename some variables to hopefully better names
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-10 02:15:25 +01:00
Denys Vlasenko 808155ebf3 cut: "orig_line" is redundant, remove it
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-10 01:55:25 +01:00
Denys Vlasenko 478ac90f2c cut: allocate "printed" only if OPT_CHAR or OPT_BYTE
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-10 01:50:58 +01:00
Denys Vlasenko ad12ab439b cut: localize 'spos' variable, convert !NUMVAR to NUMVAR == 0
This imporves readability

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-10 01:44:13 +01:00
Denys Vlasenko 73e9d25d75 cut: simplify OPT_ names, eliminate one variable
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-10 01:38:31 +01:00
Ron Yorston f020414413 cut: improve detection of invalid ranges
Commit 0068ce2fa (cut: add toybox-compatible options -O OUTSEP,
-D, -F LIST) added detection of reversed ranges.  Further
improvements are possible.

- The test for reversed ranges compared the start after it had been
  decremented with the end before decrement.  It thus missed ranges
  of the form 2-1.

- Zero isn't a valid start value for a range.  (Nor is it a valid
  end value, but that's caught by the test for a reversed range.)

- The code

        if (!*ltok)
            e = INT_MAX;

  duplicates a check that's already been made.

- Display the actual range in the error message to make it easier
  to find which range was at fault.

function                                             old     new   delta
.rodata                                           100273  100287     +14
cut_main                                            1239    1237      -2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 14/-2)              Total: 12 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-10 01:29:44 +01:00
Colin McAllister 50e2b59370 cut: fix "-s" flag to omit blank lines
Using cut with the delimiter flag ("-d") with the "-s" flag to only
output lines containing the delimiter will print blank lines. This is
deviant behavior from cut provided by GNU Coreutils. Blank lines should
be omitted if "-s" is used with "-d".

This change introduces a somewhat naiive, yet efficient solution, where
line length is checked before looping though bytes. If line length is
zero and the "-s" flag is used, the code will jump to parsing the next
line to avoid printing a newline character.

function                                             old     new   delta
cut_main                                            1196    1185     -11

Signed-off-by: Colin McAllister <colinmca242@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-10 01:27:04 +01:00
Natanael Copa 87e60dcf0f hexdump: fix regression with -n4 -e '"%u"'
Fix bug introduced in busybox 1.37.0 that broke kernel builds.

Fixes commit e2287f99fe (od: for !DESKTOP, match output more closely
to GNU coreutils 9.1, implement -s)

function                                             old     new   delta
rewrite                                              967     976      +9

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-09 11:17:14 +01:00
Ron Yorston 175b8dda19 libbb: tidy argument checks in getopt32()
When getopt32() has complementary options it's possible to specify
the minimum and maximum number of arguments allowed.  Checking
these values was inconsistent:

- '?' correctly checked that it was followed by a digit but set
  the otherwise unused spec_flgs variable on error.

- '=' failed to check that it was followed by a digit.

function                                             old     new   delta
vgetopt32                                           1307    1319     +12

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-09 02:16:44 +01:00
Christian Franke e6f3a3b381 chpst: fix error check of nice(2) call
Check errno instead of return value because -1 is a valid return
value also on success.

Signed-off-by: Christian Franke <christian.franke@t-online.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-09 02:08:52 +01:00
Hajime Tazaki 23db689683 hush: fix G.argv0_for_re_execing to avoid endless loop
When the busybox is used as /sbin/init and the inittab file contains
below:

::respawn:-/bin/sh

/sbin/init spawns hush for the first time with the argv[0] contains '-',
and hush treats it as login shell.  Then it reads /etc/profile and if
the file contains the command execution like below, it invokes hush as
login shell because the argv[0] argument is still '-/bin/sh' and reads
/etc/profile again.  This will last until some failure (e.g., memory
failure) happens.

  [ "$(id -u)" -eq 0 ] && PS1="${PS1}# " || PS1="${PS1}\$ "

This commit fixes this issues by adding an offset (+1) to the
G.argv0_for_re_execing variable.

This issue happens on our out-of-tree UML (use mode linux) with nommu
configuration.

Link: https://lore.kernel.org/all/cover.1731290567.git.thehajime@gmail.com/
Signed-off-by: Hajime Tazaki <thehajime@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-09 01:58:45 +01:00
Denys Vlasenko 75ca8d074b hexdump: accept hex numbers in -n, closes 16195
function                                             old     new   delta
hexdump_main                                         366     383     +17

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-10-08 04:23:29 +02:00
Denys Vlasenko 49d9e06fba libbb: modify find_executable() to not temporarily write to PATH
This allows to simplify "which" applet code

function                                             old     new   delta
find_executable                                       93     111     +18
which_main                                           191     177     -14
builtin_source                                       316     294     -22
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 18/-36)            Total: -18 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-10-08 04:03:17 +02:00
Denys Vlasenko 8c4bccb83e hush: fix "type ./cat" and "command -v ./cat" to not scan PATH
function                                             old     new   delta
find_executable_in_PATH                                -      67     +67
if_command_vV_print_and_exit                         114     116      +2
.rodata                                           105712  105710      -2
builtin_type                                         137     128      -9
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/2 up/down: 69/-11)             Total: 58 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-10-07 22:00:16 +02:00
Denys Vlasenko baa49bdc1b hush: make "test -x" use cached groupinfo
While at it, correct "type" to skip non-executable files in PATH

function                                             old     new   delta
builtin_source                                       211     316    +105
builtin_test                                          10      32     +22
hush_main                                           1150    1170     +20
builtin_type                                         122     137     +15
if_command_vV_print_and_exit                         120     114      -6
find_in_path                                         131       -    -131
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 4/1 up/down: 162/-137)           Total: 25 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-10-07 15:18:45 +02:00
Denys Vlasenko 0929a129fc test: -x can return 0/1 early if all X bits are the same
function                                             old     new   delta
nexpr                                                702     725     +23

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-10-07 07:33:58 +02:00
Denys Vlasenko 96b0607302 ash: cache more of uid/gid syscalls
Testcase:
setuidgid 1:1 strace ash -c 'test -x TODO; test -x TODO; echo $?'
should show that second "test -x" does not query ids again.

function                                             old     new   delta
ash_main                                            1236    1256     +20
get_cached_euid                                        -      19     +19
get_cached_egid                                        -      19     +19
test_main                                             56      72     +16
test_exec                                            119     135     +16
is_in_supplementary_groups                            52      57      +5
nexpr                                                718     702     -16
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 4/1 up/down: 95/-16)             Total: 79 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-10-07 07:28:44 +02:00
Denys Vlasenko d26e958725 ash: make "test -x" use cached groupinfo
function                                             old     new   delta
test_main2                                             -     407    +407
testcmd                                               10      23     +13
test_main                                            418      56    -362
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/1 up/down: 420/-362)           Total: 58 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-10-07 07:14:27 +02:00
Denys Vlasenko 4c1d645c86 libbb: simplify parameter passing in is_in_supplementary_groups()
function                                             old     new   delta
is_in_supplementary_groups                            54      52      -2
nexpr                                                721     718      -3
test_exec                                            125     119      -6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-11)             Total: -11 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-10-07 06:36:00 +02:00
Denys Vlasenko 860b3d066f ash: command -v CMD must skip (go to next path) when CMD exists, but is not executable
Upstream commit:

    Date: Fri, 5 Apr 2024 17:55:46 +0800
    exec: Check executable bit when searching path

    Andrej Shadura <andrew.shadura@collabora.co.uk> wrote:
    ...
    > https://bugs.debian.org/874264
    > -------- Forwarded Message --------
    > Subject: dash: 'command -v' mistakenly returns a shell script whose
    > executable is not set
    > Date: Mon, 04 Sep 2017 10:45:48 -0400
    > From: Norman Ramsey <nr@cs.tufts.edu>
    > To: Debian Bug Tracking System <submit@bugs.debian.org>
    ...
    > I tracked a build bug in s-nail to a problem with dash.  Symptom:
    > building s-nail tries to run /home/nr/bin/clang, a script whose
    > executable bit is not set.  We tracked the problem to the result of
    > running `command -v clang` with /bin/sh:
    ...
    This is inherited from NetBSD.  There is even a commented-out
    block of code that tried to fix this.

    Anyway, we now have faccessat so we can simply use it.

function                                             old     new   delta
test_exec                                              -     125    +125
find_command                                         911     918      +7
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/0 up/down: 132/0)             Total: 132 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-10-07 05:46:31 +02:00
Denys Vlasenko 748b168154 libbb: move is_in_supplementary_groups() from test to libbb
function                                             old     new   delta
is_in_supplementary_groups                             -      54     +54
nexpr                                                766     721     -45
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/1 up/down: 54/-45)              Total: 9 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-10-07 01:20:43 +02:00
Denys Vlasenko bb5525613e test: Invert return value of test_eaccess and rename it to test_st_mode
From dash:

    From: herbert <herbert@gondor.apana.org.au>
    Date: Wed, 2 Mar 2005 22:14:54 +1100
    Invert return value of test_eaccess and rename it to test_st_mode.

function                                             old     new   delta
nexpr                                                800     766     -34

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-10-06 19:25:07 +02:00
Denys Vlasenko 222802e833 test: code shrink
function                                             old     new   delta
nexpr                                                813     800     -13

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-10-06 19:08:10 +02:00
Thomas Devoogdt 8953429a82 networking/libiproute/iplink.c: fix support for older kernels
- The CAN netlink interface has been added in Linux v2.6.31 with only 3 options [1]:

  CAN_CTRLMODE_LOOPBACK    0x1  /* Loopback mode */
  CAN_CTRLMODE_LISTENONLY  0x2  /* Listen-only mode */
  CAN_CTRLMODE_3_SAMPLES   0x4  /* Triple sampling mode */

  So define the other options.

- IFLA_CAN_TERMINATION has been added in Linux 4.11 [2],
  define it for older kernels.

[1] https://github.com/torvalds/linux/blob/v2.6.31/include/linux/can/netlink.h#L80-L82
[2] https://github.com/torvalds/linux/commit/12a6075cabc0d9ffbc0366b44daa22f278606312

Signed-off-by: Thomas Devoogdt <thomas@devoogdt.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-10-06 18:25:01 +02:00
Rudi Heitbaum bf57f732a5 libbb: fix sha1 on !x86 if CONFIG_SHA1_HWACCEL=y
fixes non i386 and x86 builds

libbb/hash_md5_sha.c: In function 'sha1_end':
libbb/hash_md5_sha.c:1316:35: error: 'sha1_process_block64_shaNI' undeclared
 1316 |          || ctx->process_block == sha1_process_block64_shaNI

Signed-off-by: Rudi Heitbaum <rudi@heitbaum.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-10-06 17:56:42 +02:00
Denys Vlasenko dff444bc37 hush: whitespace and comment fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-09-28 03:52:44 +02:00
Ron Yorston 24aa93d538 ash: reject unknown long options
Commit 64f70cc755 (Add --login support) added code in options()
to handle the bash-compatible '--login' option.  In doing so it
committed BusyBox ash to silently accepting all other long
options.

Restore compatibility with other ash variants by rejecting unknown
long options.

function                                             old     new   delta
options                                              589     624     +35

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-09-27 21:29:05 +02:00
Ron Yorston 39c5c08b28 lineedit: use stdout for shell history builtin
Commit fd47f0567 (lineedit: print prompt and editing operations
to stderr) changed various print statements to output to stderr.
The change in show_history() caused the shell history builtin to
send its output to stderr.

Revert that part of the commit.

function                                             old     new   delta
show_history                                          47      42      -5
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-5)               Total: -5 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-09-27 20:16:23 +02:00
Ron Yorston 26895db35d ed: fix line insertion before current line. Closes 15081
When text is inserted by insertLine() the lines following the
insertion are moved down and the insertion point is made the new
current line.  To avoid too much scanning of the linked list of
lines setCurNum() may use the position of the old current line to
determine the location of the new current line.

If the insertion point is before the old current line in the file
the latter will have been moved down, so its line pointer needs to
be adjusted.

function                                             old     new   delta
insertLine                                           162     180     +18
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 18/0)               Total: 18 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-09-27 20:14:04 +02:00
Sam James 480a07bd68 fixdep: add fstat error handling
When `fstat` fails, `st` is left uninitialised. In our case, Ben Kohler
noticed our release media builds were failing in Gentoo on x86 when building
busybox with occasional SIGBUS. This turned out to be EOVERFLOW (from 32-bit
ino_t) which wasn't being reported because nothing was checking the return value
from `fstat`.

Fix that to avoid UB (use of uninit var) and to give a more friendly
error to the user.

This actually turns out to be fixed already in the kernel from back in
2010 [0] and 2016 [1].

[0] https://github.com/torvalds/linux/commit/a3ba81131aca243bfecfa78c42edec0cd69f72d6
[1] https://github.com/torvalds/linux/commit/46fe94ad18aa7ce6b3dad8c035fb538942020f2b

Reported-by: Ben Kohler <bkohler@gentoo.org>
Signed-off-by: Sam James <sam@gentoo.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-09-27 20:03:30 +02:00
Ron Yorston dbd14c4a42 libbb: send usage messages to correct stream
POSIX generally requires normal output to go to stdout and
diagnostic (i.e. error) output to go to stderr.

When usage messages for BusyBox applets are specifically requested
by the user (e.g. 'find --help') they should go to stdout; when
they're emitted due to an error they should go to stderr.

function                                             old     new   delta
bb_show_usage                                        148     146      -2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-2)               Total: -2 bytes

Signed-off-by: Avi Halachmi <avihpit@yahoo.com>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-09-27 19:52:25 +02:00
Ron Yorston 2c232f1e60 libbb: use full_write1_str() to shrink busybox_main()
There are two calls to dup2() in busybox_main().  These were
introduced to coerce full_write2_str() into writing to stdout.

The relevant commits were: 21278dff7 (busybox: do not print help
to fd 2, print it to fd 1) and 5a7c72015 (busybox --list option.
+140 bytes. Rob wanted it.)

Later, in commit 729ecb87b (bbconfig: make it independent from
printf functions), the function full_write1_str() was added.

Using this in busybox_main() allows us to drop the dup2() calls.

function                                             old     new   delta
run_applet_and_exit                                  796     760     -36
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-36)             Total: -36 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-09-27 19:39:28 +02:00
Denys Vlasenko e5b0547ac8 lineedit: make save_history() FAST_FUNC
function                                             old     new   delta
save_history                                         267     266      -1
hush_exit                                             98      97      -1
exitshell                                            140     138      -2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-4)               Total: -4 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-09-27 19:35:50 +02:00
Denys Vlasenko a023f39265 Start 1.38.0 development cycle
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-09-26 23:33:06 +02:00
Denys Vlasenko be7d1b7b17 Bump version to 1.37.0
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-09-26 23:31:15 +02:00
Denys Vlasenko a667a7f020 wget: fix compile warnings when WGET_FTP is not selected
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-09-26 16:27:10 +02:00
Ron Yorston 371fe9f71d ash: move hashvar() calls into findvar()
dash has accepted a patch to remove the first argument of findvar().
It's commit e85e972 (var: move hashvar() calls into findvar()).

Apply the same change to BusyBox ash.

function                                             old     new   delta
findvar                                               35      40      +5
mklocal                                              268     261      -7
exportcmd                                            164     157      -7
setvareq                                             319     310      -9
lookupvar                                            150     141      -9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/4 up/down: 5/-32)             Total: -27 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-07-14 01:12:54 +02:00
Ron Yorston e4b5ccd13b timeout: allow fractional seconds in timeout values
The 'timeout' applet uses parse_duration_str() to obtain its
timeout values.  The default configuration enables float durations.

However, the applet silently ignores fractional seconds.  This
results in unexpected behaviour:

   $ timeout 5.99 sleep 5.1; echo $?
   Terminated
   143

When float durations are enabled ensure that any fractional seconds
are taken into account.

function                                             old     new   delta
timeout_wait                                          44      92     +48
timeout_main                                         383     365     -18
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 48/-18)             Total: 30 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-07-13 21:34:18 +02:00
Denys Vlasenko b20b3790b4 powertop: code shrink
function                                             old     new   delta
print_intel_cstates                                  477     475      -2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-07-13 11:46:15 +02:00
Denys Vlasenko 23da5c4b71 hush: do not exit interactive shell on some redirection errors
$ echo >&99
hush: dup2(99,1): Bad file descriptor
$ echo >&9999
hush: fcntl(1,F_DUPFD,10000): Invalid argument
$ echo 2>/dev/tty 10>&9999
hush: fcntl(10,F_DUPFD,10000): Invalid argument
$ still alive!_

function                                             old     new   delta
static.setup_redirects                               334     394     +60
.rodata                                           105661  105712     +51
dup_CLOEXEC                                           49      79     +30
save_fd_on_redirect                                  263     277     +14
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/0 up/down: 155/0)             Total: 155 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-07-13 02:13:28 +02:00
Denys Vlasenko 14e28c18ca hush: fix "exec 3>FILE" aborting if 3 is exactly the next free fd
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-07-13 00:59:02 +02:00
Denys Vlasenko 6c38d0e9da hush: avoid duplicate fcntl(F_SETFD, FD_CLOEXEC) during init
function                                             old     new   delta
hush_main                                           1149    1150      +1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-07-13 00:14:41 +02:00
Denys Vlasenko 08fb86726b ash: remove limitation on fd# length
"echo text >&0000000000002" works as you would expect,
"echo text >&9999999999" properly fails instead of creating a file
named "9999999999".

function                                             old     new   delta
expredir                                             219     232     +13
readtoken1                                          3045    3053      +8
parsefname                                           204     201      -3
isdigit_str9                                          45       -     -45
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 2/1 up/down: 21/-48)            Total: -27 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-07-12 22:28:25 +02:00
Denys Vlasenko 0829fce079 ash: do not abort interactive mode on >&9999 redirect
With very large fd#, the error code path is different
from one for closed but small fd#.

Make it not abort if we are interactive:

$ echo text >&99    # this wasn't buggy
ash: dup2(9,1): Bad file descriptor
$ echo text >&9999  # this was
ash: fcntl(1,F_DUPFD,10000): Invalid argument

function                                             old     new   delta
.rodata                                           105637  105661     +24
dup2_or_raise                                         35      38      +3
redirect                                            1084    1044     -40
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 27/-40)            Total: -13 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-07-12 22:10:50 +02:00
Denys Vlasenko 1ad2f5cd9f tls: fix CONFIG_FEATURE_TLS_SHA1=y + CONFIG_SHA1_HWACCEL=y
The check for result hash size was buggy for CONFIG_SHA1_HWACCEL=y.

While at it, document CPUID use a bit better.

function                                             old     new   delta
get_shaNI                                              -      28     +28
sha1_end                                              66      79     +13
sha256_begin                                          83      60     -23
sha1_begin                                           111      88     -23
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/2 up/down: 41/-46)             Total: -5 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-07-12 19:30:14 +02:00
Denys Vlasenko 999e290ef6 tls: P256: improve x86_64 multiplication asm code
gcc is being rather silly. Usues suboptimal registers,
and does not realize that i and j are never negative,
thus usese even _more_ registers for temporaries
to sign-extend i/j to 64-bit offsets.

function                                             old     new   delta
sp_256_mont_mul_8                                    155     132     -23

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-07-12 11:10:24 +02:00
Denys Vlasenko d745852f13 tls: P256: fix obscure x86_64 asm misbehavior, closes 15679
gcc does not necessarily clear upper bits in
64-bit regs if you ask it to load a 32-bit constant.

Cast it to unsigned long. Better yet, hand-write loading
of the constant with a smaller instruction.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-07-11 23:53:47 +02:00
Ron Yorston a3c5068306 md5/shaXsum: accept uppercase hex strings
The coreutils versions of md5sum and the like accept uppercase hex
strings from checksum files specified with the '-c' option.

Use a case-insensitive comparison so BusyBox does the same.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-07-11 18:17:31 +02:00
Petja Patjas 05e5d6a381 vi: Ensure that the edit buffer ends in a newline
Currently vi assumes that the edit buffer ends in a newline. This may
not be the case. For example:

  $ printf test > test
  $ vi test
  <press 'o'>

We fix this by inserting a newline to the end during initialization.

Signed-off-by: Petja Patjas <pp01415943@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-07-11 17:52:18 +02:00
Ron Yorston 0af28b84e5 ash: remove defunct control character to save a few bytes
Commit 549deab5a (ash: move parse-time quote flag detection to
run-time) did away with the need to distinguish between backquotes
inside and outside quotes.  This left a gap among the control
characters used in argument strings.  Removing this gap saves a
few bytes.

function                                             old     new   delta
.rodata                                           167346  167338      -8
cmdputs                                              399     388     -11
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-19)             Total: -19 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-07-10 07:35:26 +02:00
Ron Yorston 87c31609f4 Makefile.flags: suppress clang warnings when cross-compiling
Extend the changes introduced by commit b4ef2e3467 (Makefile.flags:
suppress some clang-9 warnings) so they also cover the case where
clang is used as a cross-compiler.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-07-10 07:21:20 +02:00
Ron Yorston ba0f94458b ash: fix parsing of alias expansion + bash features
An alias expansion immediately followed by '<' and a newline is
parsed incorrectly:

   ~ $ alias x='echo yo'
   ~ $ x<
   yo
   ~ $
   sh: syntax error: unexpected newline

The echo is executed and an error is printed on the next command
submission.  In dash the echo isn't executed and the error is
reported immediately:

   $ alias x='echo yo'
   $ x<
   dash: 3: Syntax error: newline unexpected
   $

The difference between BusyBox and dash is that BusyBox supports
bash-style process substitution and output redirection.  These
require checking for '<(', '>(' and '&>' in readtoken1().

In the case above, when the end of the alias is found, the '<' and
the following newline are both read to check for '<('.  Since
there's no match both characters are pushed back.

The next input is obtained by reading the expansion of the alias.
Once this string is exhausted the next call to __pgetc() calls
preadbuffer() which pops the string, reverts to the previous input
and recursively calls __pgetc().  This request is satisified from
the pungetc buffer.  But the first __pgetc() doesn't know this:
it sees the character has come from preadbuffer() so it (incorrectly)
updates the pungetc buffer.

Resolve the issue by moving the code to pop the string and fetch
the next character up from preadbuffer() into __pgetc().

function                                             old     new   delta
pgetc                                                 28     589    +561
__pgetc                                              607       -    -607
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/0 up/down: 561/-607)          Total: -46 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-07-10 07:11:23 +02:00
Denys Vlasenko 0a88a7ae3b awk: mktime() with no arguments is not allowed
It was SEGVing.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-07-10 07:04:28 +02:00
Denys Vlasenko 2eea3494f1 awk: improve comments and constants, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-07-10 06:58:51 +02:00
Denys Vlasenko 45d471d435 qwk: code shrink
function                                             old     new   delta
mk_splitter                                          100      96      -4
as_regex                                             103      99      -4
parse_expr                                           991     986      -5
awk_split                                            544     538      -6
awk_getline                                          559     552      -7
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/5 up/down: 0/-26)             Total: -26 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-07-09 17:50:58 +02:00
Denys Vlasenko 38335df9e9 awk: restore assignment precedence to be lower than ternary ?:
Something is fishy with constrcts like "3==v=3" in gawk,
they should not work, but do. Ignore those for now.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-07-09 15:30:46 +02:00
Denys Vlasenko 49340d93ed awk: do not infinitely recurse getvar_s() if CONVFMT is set to a numeric value
function                                             old     new   delta
fmt_num                                              247     257     +10
evaluate                                            3385    3379      -6
getvar_s                                             111     102      -9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 10/-15)             Total: -5 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-07-09 03:04:26 +02:00
Natanael Copa fb08d43d44 awk: fix use after free (CVE-2023-42363)
function                                             old     new   delta
evaluate                                            3377    3385      +8

Fixes https://bugs.busybox.net/show_bug.cgi?id=15865

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-07-09 02:34:00 +02:00
Denys Vlasenko eba9b33b45 chown: stop accepting deprecated USER.GROUP syntax, only : separator is allowed
function                                             old     new   delta
parse_chown_usergroup_or_die                         115      94     -21

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-07-08 17:53:32 +02:00
Sertonix 9f262698cc wget: ignore header casing
HTTP headers are case insensitive and therefore the check if a default
header has been overwritten needs to be case insensitive.

Without this patch `--header 'user-agent: test'` results in
`User-Agent: Wget` and `user-agent: test` being send.

function                                             old     new   delta
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/0 up/down: 0/0)                 Total: 0 bytes
   text	  data	   bss	   dec	   hex	filename
1040876	 16443	  1840	1059159	102957	busybox_old
1040876	 16443	  1840	1059159	102957	busybox_unstripped

Signed-off-by: Sertonix <sertonix@posteo.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-07-08 15:02:58 +02:00
Denys Vlasenko a6ce017a8a typo fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-06-01 10:51:58 +02:00
Denys Vlasenko 41b47398f5 libbb: fix 64-bit bb_popcnt_long
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-05-31 23:37:28 +02:00
Denys Vlasenko 2075553a1b libbb: add bit counting function, use where appropriate
Although "naive" counting function is not too slow and is smaller,
using it on e.g. each of 1024 words of CPU mask feels wrong.

function                                             old     new   delta
bb_popcnt_32                                           -      52     +52
get_prefix                                           323     321      -2
nproc_main                                           206     199      -7
d4_run_script                                        739     731      -8
ipcalc_main                                          533     507     -26
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 0/4 up/down: 52/-43)              Total: 9 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-05-31 16:03:23 +02:00
Denys Vlasenko 5a68a246e7 nproc: prepare for arbitrarily large CPU masks
function                                             old     new   delta
get_malloc_cpu_affinity                                -      76     +76
nproc_main                                           216     206     -10
process_pid_str                                      250     206     -44
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 0/2 up/down: 76/-54)             Total: 22 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-05-31 11:58:48 +02:00
Denys Vlasenko fd47f05676 lineedit: print prompt and editing operations to stderr
For shells, this is mandated by standards

function                                             old     new   delta
input_backward                                       215     231     +16
read_line_input                                     3015    3028     +13
draw_custom                                           66      78     +12
put_cur_glyph_and_inc_cursor                         149     159     +10
put_prompt_custom                                     47      56      +9
show_history                                          40      46      +6
input_tab                                            927     933      +6
input_delete                                         136     142      +6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 8/0 up/down: 78/0)               Total: 78 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-04-13 18:40:20 +02:00
Yan Zhu 681e4f5d92 docproc: avoid segfault during file closing
In the function find_export_symbols, since the fopen file does not
exit when it fails, there is a dereference problem in fclose(fp),
which will cause a segmentation fault.

Signed-off-by: Yan Zhu <zhuyan2015@foxmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-04-13 17:57:46 +02:00
Ron Yorston e1a6874106 awk: fix segfault when compiled by clang
A 32-bit build of BusyBox using clang segfaulted in the test
"awk assign while assign".  Specifically, on line 7 of the test
input where the adjustment of the L.v pointer when the Fields
array was reallocated

   	L.v += Fields - old_Fields_ptr;

was out by 4 bytes.

Rearrange to code so both gcc and clang generate code that works.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2024-03-02 17:03:37 +01:00
Jones Syue 01f2b5976d crond: log5 fix typo, replace log level '4' with '5'
log5() with crondlog(5, msg, va) seems making logging more consistent.

function                                             old     new   delta
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/0 up/down: 0/0)                 Total: 0 bytes

Signed-off-by: Jones Syue <jonessyue@qnap.com>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2024-03-02 17:03:37 +01:00
Denys Vlasenko c5a1be25ba ash: fix handling of single-quoted strings in pattern substitution
function                                             old     new   delta
subevalvar                                          1576    1588     +12

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-02-26 16:27:53 +01:00
Dario Binacchi f873c63085 ip link: support for the CAN netlink
I developed this application to test the Linux kernel series [1]. As
described in it I could not use the iproute2 package since the
microcontroller is without MMU.

function                                             old     new   delta
do_set_can                                             -     920    +920
packed_usage                                       34645   34908    +263
get_float_1000                                         -     164    +164
.rodata                                           105427  105539    +112
do_iplink                                           1313    1381     +68
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 3/0 up/down: 1527/0)           Total: 1527 bytes

cc: Marc Kleine-Budde <mkl@pengutronix.de>
[1] https://marc.info/?l=linux-netdev&m=167999323611710&w=2
Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-02-26 14:10:10 +01:00
Denys Vlasenko 758b21402a hush: detect when terminating "done"/"fi" is missing
function                                             old     new   delta
parse_stream                                        2271    2292     +21
.rodata                                           105408  105427     +19
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 40/0)               Total: 40 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-02-25 17:53:25 +01:00
Denys Vlasenko 2639f3bc72 hush: set G.ifs sooner (prevents segfault)
function                                             old     new   delta
set_G_ifs                                              -     151    +151
run_list                                            1024    1031      +7
run_pipe                                            1567    1445    -122
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/1 up/down: 158/-122)           Total: 36 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-02-25 15:42:16 +01:00
Denys Vlasenko a97a2f1280 ls: do not truncate username/groupname to 8 chars
function                                             old     new   delta
.rodata                                           105412  105408      -4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-02-25 01:06:30 +01:00
Dominique Martinet 5dc9ece3b9 sed: check errors writing file with sed -i
sed would currently not error if write failed when modifying a file.

This can be reproduced with the following 'script':
$ sudo mount -t tmpfs tmpfs -o size=1M /tmp/m
$ sudo chmod 777 /tmp/m
$ echo foo > /tmp/m/foo
$ dd if=/dev/zero of=/tmp/m/fill bs=4k
dd: error writing '/tmp/m/fill': No space left on device
256+0 records in
255+0 records out
1044480 bytes (1.0 MB, 1020 KiB) copied, 0.00234567 s, 445 MB/s
$ busybox sed -i -e 's/.*/bar/' /tmp/m/foo
$ echo $?
0
$ cat /tmp/m/foo
<empty>

new behaviour:
$ echo foo > /tmp/m/foo
$ ./busybox sed -i -e 's/.*/bar/' /tmp/m/foo
sed: write error
$ echo $?
4
$ cat /tmp/m/foo
foo

function                                             old     new   delta
sed_main                                             754     801     +47
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 47/0)               Total: 47 bytes
   text	   data	    bss	    dec	    hex	filename
  75727	   2510	   1552	  79789	  137ad	busybox_old
  75774	   2510	   1552	  79836	  137dc	busybox_unstripped

Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-01-02 00:58:56 +01:00
Denys Vlasenko 1cac258521 time: implement %% and \escapes in -f FMT
function                                             old     new   delta
time_main                                           1217    1316     +99

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-01-01 22:24:42 +01:00
Natanael Copa 01e80ff9eb time: fix max resident set size unit
The ru_maxrss is already in Kbytes and not pages.

function                                             old     new   delta
ptok                                                  21       -     -21
time_main                                           1261    1217     -44
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 0/1 up/down: 0/-65)             Total: -65 bytes

fixes: https://bugs.busybox.net/show_bug.cgi?id=15751

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-12-31 16:28:53 +01:00
Denys Vlasenko 789ccac7d9 awk: fix handling of empty fields
Patch by M Rubon <rubonmtz@gmail.com>:
Busybox awk handles references to empty (not provided in the input)
fields differently during the first line of input, as compared to
subsequent lines.

$ (echo a ; echo b) | awk '$2 != 0'    #wrong
b

No field $2 value is provided in the input.  When awk references field
$2 for the "a" line, it is seen to have a different behaviour than
when it is referenced for the "b" line.

Problem in BusyBox v1.36.1 embedded in OpenWrt 23.05.0
Same problem also in 21.02 versions of OpenWrt
Same problem in BusyBox v1.37.0.git

I get the correct expected output from Ubuntu gawk and Debian mawk,
and from my fix.
will@dev:~$ (echo a ; echo b) | awk '$2 != 0'  #correct
a
b
will@dev:~/busybox$ (echo a ; echo b ) | ./busybox awk '$2 != 0'  #fixed
a
b

I built and poked into the source code at editors/awk.c  The function
fsrealloc(int size) is core to allocating, initializing, reallocating,
and reinitializing fields, both real input line fields and imaginary
fields that the script references but do not exist in the input.

When fsrealloc() needs more field space than it has previously
allocated, it initializes those new fields differently than how they
are later reinitialized for the next input line.  This works fine for
fields defined in the input, like $1, but does not work the first time
when there is no input for that field (e.g. field $99)

My one-line fix simply makes the initialization and clrvar()
reinitialization use the same value for .type.  I am not sure if there
are regression tests to run, but I have not done those.

I'm not sure if I understand why clrvar() is not setting .type to a
default constant value, but in any case I have left that untouched.

function                                             old     new   delta
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/0 up/down: 0/0)                 Total: 0 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-12-31 15:49:54 +01:00
Peter Korsgaard 5e0e54827f util-linux/lsusb.c: print manufacturer/product strings if available
Just listing the vendor/product IDs is not always very helpful, so add logic
to print the manufacturer and product strings similar to the "big" usbutils
versions.

Not all devices provide sensible strings though.  The usbutils version works
around this by falling back to looking up the vendor/product IDs in the hwdb
and using those strings instead, which is not an option here - Instead
simply trim() the strings for readability.

lsusb | sort
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 0bda:5539 Realtek Semiconductor Corp. Integrated_Webcam_HD
Bus 001 Device 003: ID 0a5c:5842 Broadcom Corp. 58200
Bus 001 Device 030: ID 8087:0aaa Intel Corp. Bluetooth 9460/9560 Jefferson Peak (JfP)
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 006 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 006 Device 002: ID 0bda:5487 Realtek Semiconductor Corp. Dell dock
Bus 006 Device 003: ID 0bda:5413 Realtek Semiconductor Corp. Dell dock
Bus 006 Device 004: ID 413c:b06e Dell Computer Corp. Dell dock
Bus 006 Device 005: ID 0451:8142 Texas Instruments, Inc. TUSB8041 4-Port Hub
Bus 006 Device 006: ID 0bda:402e Realtek Semiconductor Corp. USB Audio
Bus 006 Device 007: ID 413c:1010 Dell Computer Corp. USB 2.0 Hub [MTT]
Bus 006 Device 008: ID 413c:b06f Dell Computer Corp. Dell dock
Bus 006 Device 009: ID 046d:c016 Logitech, Inc. Optical Wheel Mouse
Bus 006 Device 010: ID 413c:2110 Dell Computer Corp. Dell Wired Multimedia Keyboard
Bus 006 Device 011: ID 0451:8142 Texas Instruments, Inc. TUSB8041 4-Port Hub
Bus 006 Device 012: ID 0451:3410 Texas Instruments, Inc. TUSB3410 Microcontroller
Bus 007 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 007 Device 002: ID 0bda:0487 Realtek Semiconductor Corp. Dell dock
Bus 007 Device 003: ID 0bda:0413 Realtek Semiconductor Corp. Dell dock
Bus 007 Device 004: ID 0bda:8153 Realtek Semiconductor Corp. RTL8153 Gigabit Ethernet Adapter

./busybox lsusb | sort
Bus 001 Device 001: ID 1d6b:0002 Linux 6.1.0-13-amd64 xhci-hcd xHCI Host Controller
Bus 001 Device 002: ID 0bda:5539 CNFHH53Q0324300ACA10 Integrated_Webcam_HD
Bus 001 Device 003: ID 0a5c:5842 Broadcom Corp 58200
Bus 001 Device 030: ID 8087:0aaa
Bus 002 Device 001: ID 1d6b:0003 Linux 6.1.0-13-amd64 xhci-hcd xHCI Host Controller
Bus 003 Device 001: ID 1d6b:0002 Linux 6.1.0-13-amd64 xhci-hcd xHCI Host Controller
Bus 004 Device 001: ID 1d6b:0003 Linux 6.1.0-13-amd64 xhci-hcd xHCI Host Controller
Bus 005 Device 001: ID 1d6b:0002 Linux 6.1.0-13-amd64 dummy_hcd Dummy host controller
Bus 006 Device 001: ID 1d6b:0002 Linux 6.1.0-13-amd64 xhci-hcd xHCI Host Controller
Bus 006 Device 002: ID 0bda:5487 Dell Inc. Dell dock
Bus 006 Device 003: ID 0bda:5413 Dell Inc. Dell dock
Bus 006 Device 004: ID 413c:b06e Dell dock
Bus 006 Device 005: ID 0451:8142
Bus 006 Device 006: ID 0bda:402e Generic USB Audio
Bus 006 Device 007: ID 413c:1010 USB 2.0 Hub [MTT]
Bus 006 Device 008: ID 413c:b06f Dell dock
Bus 006 Device 009: ID 046d:c016 Logitech Optical USB Mouse
Bus 006 Device 010: ID 413c:2110 Dell Dell Wired Multimedia Keyboard
Bus 006 Device 011: ID 0451:8142
Bus 006 Device 012: ID 0451:3410 Texas Instruments TUSB3410 Boot Device
Bus 007 Device 001: ID 1d6b:0003 Linux 6.1.0-13-amd64 xhci-hcd xHCI Host Controller
Bus 007 Device 002: ID 0bda:0487 Dell Inc. Dell dock
Bus 007 Device 003: ID 0bda:0413 Dell Inc. Dell dock
Bus 007 Device 004: ID 0bda:8153 Realtek USB 10/100/1000 LAN

./scripts/bloat-o-meter busybox_unstripped{_orig,}
function                                             old     new   delta
trim                                                   -     101    +101
fileAction                                           338     431     +93
add_sysfs_prop                                         -      70     +70
open_read_close                                        -      54     +54
read_close                                             -      35     +35
.rodata                                             3268    3294     +26
------------------------------------------------------------------------------
(add/remove: 5/0 grow/shrink: 2/0 up/down: 379/0)             Total: 379 bytes

Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
2023-12-13 15:59:47 +01:00
Denys Vlasenko 28f4126093 top: improve large PID display in memory ('s') mode
Display VSZ[RW] fields in more compact form if PID is wider.

function                                             old     new   delta
display_topmem_process_list                          564     614     +50
ulltoa5_and_space                                      -      14     +14
ulltoa6_and_space                                     14       -     -14
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 1/0 up/down: 64/-14)             Total: 50 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-11-23 01:18:02 +01:00
Christian Franke a63b60bdd6 Cygwin: regenerate defconfig
Signed-off-by: Christian Franke <christian.franke@t-online.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-11-13 11:32:35 +01:00
Denys Vlasenko 59cf2c23ae start-stop-daemon: make --output not depend on FANCY
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-11-08 14:42:00 +01:00
Denys Vlasenko 58ca629fd2 start-stop-daemon: do not lose error messages with -b
function                                             old     new   delta
start_stop_daemon_main                              1186    1206     +20
bb_daemonize_or_rexec                                196     212     +16
bb_banner                                             47      46      -1
packed_usage                                       34656   34645     -11
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/2 up/down: 36/-12)             Total: 24 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-11-08 14:07:20 +01:00
Denys Vlasenko 2de67a62e8 start-stop-daemon: typo fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-11-08 12:36:11 +01:00
Louai Al-Khanji 389c0458da start-stop-daemon: implement option -O|--output
If specified redirect command stdout and stderr to given pathname.

function                                             old     new   delta
start_stop_daemon_main                              1130    1186     +56
start_stop_daemon_longopts                           164     173      +9
packed_usage                                       34653   34656      +3
.rodata                                           105384  105386      +2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/0 up/down: 70/0)               Total: 70 bytes

Signed-off-by: Louai Al-Khanji <louai@astranis.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-11-07 21:44:07 +01:00
Petr Vorel d17c0a348f sleep: Update doc
4c20d9f2b removed FEATURE_FLOAT_SLEEP option, thus since then there are
only two variants.

Fixes: 4c20d9f2b ("extend fractional duration support to "top -d N.N" and "timeout"")
Signed-off-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-11-07 16:59:09 +01:00
Denys Vlasenko da8d1d84fd start-stop-daemon: update comment, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-11-07 15:59:11 +01:00
ejaaskel 73f28134fc start-stop-daemon: add -d DIR chdir option
Add option to change the running directory before starting the process.
This can be done using -d or --chdir options. Add also test cases to
start-stop-daemon to test out the directory change option.

function                                             old     new   delta
packed_usage                                       34602   34648     +46
start_stop_daemon_main                              1107    1130     +23
start_stop_daemon_longopts                           156     164      +8
.rodata                                           105382  105384      +2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/0 up/down: 79/0)               Total: 79 bytes

Signed-off-by: ejaaskel <esa.jaaskela@suomi24.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-11-07 07:12:40 +01:00
Denys Vlasenko 0c71497e65 start-stop-daemon: fix --help: -K or -S is required
function                                             old     new   delta
.rodata                                           105381  105382      +1
packed_usage                                       34638   34602     -36
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 1/-36)             Total: -35 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-11-07 06:55:35 +01:00
Russ Dill e265c8d4c0 udhcp: Avoid leaking uninitialized/stale data
I noticed a commit in connman:

"gdhcp: Avoid leaking stack data via unitiialized variable" [1]

Since gdhcp is just BusyBox udhcp with the serial numbers filed off, I
checked if BusyBox udhcp has a related issue.

The issue is that the get_option logic assumes any data within the
memory area of the buffer is "valid". This reduces the complexity of the
function at the cost of reading past the end of the actually received
data in the case of specially crafted packets. This is not a problem
for the udhcp_recv_kernel_packet data path as the entire memory
area is zeroed. However, d4/d6_recv_raw_packet does not zero the
memory.

Note that a related commit [2] is not required as we are zeroing
any data that can be read by the get_option function.

[1] https://git.kernel.org/pub/scm/network/connman/connman.git/commit/?id=a74524b3e3fad81b0fd1084ffdf9f2ea469cd9b1
[2] https://git.kernel.org/pub/scm/network/connman/connman.git/commit/?id=58d397ba74873384aee449690a9070bacd5676fa

function                                             old     new   delta
d4_recv_raw_packet                                   484     497     +13
d6_recv_raw_packet                                   216     228     +12
.rodata                                           105390  105381      -9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 25/-9)              Total: 16 bytes

Signed-off-by: Russ Dill <russ.dill@gmail.com>
Cc: Colin Wee <cwee@tesla.com>
Cc: Denys Vlasenko <vda.linux@googlemail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-10-04 16:46:35 +02:00
Denys Vlasenko 5fa39d48d5 syslogd: fix breakage caused by "daemonize _after_ init" change
function                                             old     new   delta
syslogd_init                                        1007    1140    +133
create_socket                                        143       -    -143
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/0 up/down: 133/-143)          Total: -10 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-10-03 19:16:10 +02:00
Denys Vlasenko 92ab29fcf0 awk: implement -E; do not reorder -f and -e
function                                             old     new   delta
awk_main                                             843     891     +48
next_input_file                                      243     261     +18
packed_usage                                       34631   34638      +7
.rodata                                           105391  105390      -1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/1 up/down: 73/-1)              Total: 72 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-10-02 15:24:06 +02:00
Nero 6d22c9abc2 install: Fix chown resetting suid/sgid bits from chmod
Since Linux 2.2.13, chown(2) resets the suid/gid bits for all users.
This patch changes the ordering so that chmod gets called after chown.

This behavior follows GNU coreutils.

Signed-off-by: Nero <nero@w1r3.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-10-02 14:26:27 +02:00
Denys Vlasenko 791b222dd5 sleep: fix "sleep -- ARGS"
function                                             old     new   delta
sleep_main                                           116     119      +3
printf_main                                          860     837     -23
single_argv                                           50      25     -25
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 3/-48)             Total: -45 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-10-02 13:56:32 +02:00
Ron Yorston 2cc9d436e8 tsort: avoid use-after-free
When the input data contained a cycle it was possible for tsort to
attempt to access freed nodes.  This sometimes resulted in the
test case 'echo a b b a | tsort' crashing.

Don't free nodes when they're removed from the graph.

function                                             old     new   delta
tsort_main                                           621     596     -25
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-25)             Total: -25 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-08-31 09:41:53 +02:00
zhuyan ed4a24dfd1 ash: initialize basepf.buf in ash
When I planned to print the command in read_line_input, I found that after
the system started, the command printed for the first time was always
garbled.

After analysis, it is found that in the init() function of ash, the
variable basepf.buf is not initialized after applying for memory, resulting
in garbled initial data. Then assign it to the global variable
g_parsefile->buf in ash.c, and then pass g_parsefile->buf to the parameter
command of the function read_line_input in the function preadfd(), and
finally cause it to be garbled when the command is printed by
read_line_input.

The call stack is as follows:
 #0  read_line_input (st=0xb6fff220, prompt=0xb6ffc910 "\\[\\033[32m\\]\\h \\w\\[\\033[m\\] \\$ ", command=command@entry=0xb6ffc230 "P\325\377\266P\325\377\266", maxsize=maxsize@entry=1024) at libbb/lineedit.c:2461
 #1  0x0043ef8c in preadfd () at shell/ash.c:10812
 #2  preadbuffer () at shell/ash.c:10914
 #3  pgetc () at shell/ash.c:10997
 #4  0x00440c20 in pgetc_eatbnl () at shell/ash.c:11039
 #5  0x00440cbc in xxreadtoken () at shell/ash.c:13157
 #6  0x00440f40 in readtoken () at shell/ash.c:13268
 #7  0x00441234 in list (nlflag=nlflag@entry=1) at shell/ash.c:11782
 #8  0x004420e8 in parsecmd (interact=<optimized out>) at shell/ash.c:13344
 #9  0x00442c34 in cmdloop (top=top@entry=1) at shell/ash.c:13549
 #10 0x00444e4c in ash_main (argc=<optimized out>, argv=0x444e4c <ash_main+1328>) at shell/ash.c:14747
 #11 0x00407954 in run_applet_no_and_exit (applet_no=9, name=<optimized out>, argv=0xbefffd34) at libbb/appletlib.c:1024
 #12 0x00407b68 in run_applet_and_exit (name=0xbefffe56 "ash", argv=0x9) at libbb/appletlib.c:1047
 #13 0x00407f88 in main (argc=<optimized out>, argv=0xbefffd34) at libbb/appletlib.c:1181

Fixes: 82dd14a510 ("ash: use CONFIG_FEATURE_EDITING_MAX_LEN")

Signed-off-by: zhuyan <zhuyan34@huawei.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-08-31 02:20:19 +02:00
Denys Vlasenko 8f0845cad7 libbb: rename source files, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-18 16:41:12 +02:00
Denys Vlasenko c484846c44 introduce and use exitcode_t
function                                             old     new   delta
strings_main                                         422     420      -2
setfattr_main                                        175     173      -2
brctl_main                                          1548    1546      -2
makedevs_main                                        979     975      -4
rev_main                                             337     332      -5
getfattr_main                                        307     302      -5
cut_main                                            1201    1196      -5
cksum_main                                           398     393      -5
umount_main                                          573     565      -8
ln_main                                              516     508      -8
expand_main                                          660     652      -8
df_main                                             1068    1060      -8
renice_main                                          346     332     -14
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/13 up/down: 0/-76)            Total: -76 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-17 17:29:36 +02:00
Denys Vlasenko a6a102ec4c getfattr: fix "getfattr NOTEXIST" - now prints error msg
function                                             old     new   delta
getfattr_main                                        309     307      -2
.rodata                                           105395  105391      -4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-6)               Total: -6 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-17 09:36:17 +02:00
YU Jincheng cf809e2f2d getfattr: new applet
function                                             old     new   delta
getfattr_main                                          -     309    +309
print_attr                                             -     115    +115
packed_usage                                       34576   34631     +55
.rodata                                           105349  105395     +46
lgetxattr                                              -      41     +41
getxattr                                               -      41     +41
llistxattr                                             -      35     +35
listxattr                                              -      35     +35
applet_names                                        2806    2815      +9
applet_main                                         1620    1624      +4
------------------------------------------------------------------------------
(add/remove: 7/0 grow/shrink: 4/0 up/down: 690/0)             Total: 690 bytes

Signed-off-by: YU Jincheng <shana@zju.edu.cn>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-16 14:40:44 +02:00
Denys Vlasenko ab755f4925 hwclock: force LONG_OPTS, stop accepting non-compatible -t
function                                             old     new   delta
hwclock_main                                         576     579      +3
.rodata                                           105404  105349     -55
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 3/-55)             Total: -52 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-14 16:37:24 +02:00
Andrej Picej d70256a5c7 hwclock: add get/set parameters option
In kernel 5.16 special ioctls were introduced to get/set RTC parameters.
Add option to get/set parameters into busybox version of hwclock.
Implementation is similar to the one already used in linux-utils hwclock
tool.

Example of parameter get use:
$ hwclock -g 2
The RTC parameter 0x2 is set to 0x2.
$ hwclock --param-get bsm
The RTC parameter 0x2 is set to 0x2.

Example of parameter set use:
$ hwclock -p 2=1
The RTC parameter 0x2 will be set to 0x1.
$ hwclock -p bsm=2
The RTC parameter 0x2 will be set to 0x2.

function                                             old     new   delta
hwclock_main                                         298     576    +278
.rodata                                           105231  105400    +169
packed_usage                                       34541   34576     +35
static.hwclock_longopts                               60      84     +24
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/0 up/down: 506/0)             Total: 506 bytes

Signed-off-by: Andrej Picej <andrej.picej@norik.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-12 16:27:49 +02:00
Denys Vlasenko 9fc5933b10 ntpd: fix a warning on 32-bit arch build
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-10 17:29:38 +02:00
Denys Vlasenko 69d33db445 i2ctransfer: fix build warning
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-10 17:27:26 +02:00
Denys Vlasenko 5353df91cb Update applet size estimates
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-10 17:25:21 +02:00
Denys Vlasenko a9047e0980 ash: tweak comments, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-10 12:02:34 +02:00
Denys Vlasenko ae351311da ash: remove "volatile" specifier from suppress_int
function                                             old     new   delta
aliascmd                                             274     278      +4
signal_handler                                        81      80      -1
static.redirectsafe                                  144     141      -3
unwindlocalvars                                      219     215      -4
trapcmd                                              333     329      -4
setvar                                               164     160      -4
setpwd                                               167     163      -4
setinputfile                                         216     212      -4
setcmd                                                76      72      -4
readcmd                                              221     217      -4
raise_exception                                       26      22      -4
out2str                                               37      33      -4
out1str                                               32      28      -4
freejob                                               89      85      -4
forkchild                                            616     612      -4
fg_bgcmd                                             298     294      -4
expandarg                                            949     945      -4
evaltree                                             753     749      -4
evalsubshell                                         173     169      -4
evalpipe                                             346     342      -4
evalfun                                              408     404      -4
cdcmd                                                699     695      -4
ash_main                                            1240    1236      -4
__pgetc                                              589     585      -4
unaliascmd                                           152     147      -5
unalias                                               51      46      -5
umaskcmd                                             253     248      -5
stalloc                                               97      92      -5
shiftcmd                                             144     139      -5
setinputstring                                        73      68      -5
redirect                                            1068    1063      -5
recordregion                                          81      76      -5
pushstring                                           160     155      -5
popstring                                            120     115      -5
popstackmark                                          69      64      -5
popredir                                             123     118      -5
popfile                                              110     105      -5
out1fmt                                               45      40      -5
newline_and_flush                                     39      34      -5
ifsfree                                               66      61      -5
growstackblock                                       146     141      -5
freestrings                                           95      90      -5
fmtstr                                                59      54      -5
flush_stdout_stderr                                   23      18      -5
dowait                                               577     572      -5
delete_cmd_entry                                      52      47      -5
clearcmdentry                                         98      93      -5
ash_arith                                             79      74      -5
argstr                                              1404    1399      -5
evalcommand                                         1523    1515      -8
removerecordregions                                  219     209     -10
mklocal                                              284     274     -10
find_command                                         893     883     -10
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/52 up/down: 4/-251)          Total: -247 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-10 11:13:51 +02:00
Denys Vlasenko 5e0411a7fb ash: disable sleep as builtin, closes 15619
Has a few annoying problems:
* sleepcmd() -> sleep_main(), the parsing of bad arguments exits the shell.
* sleep_for_duration() in sleep_main() has to be interruptible for
  ^C traps to work, which may be a problem for other users
  of sleep_for_duration().
* BUT, if sleep_for_duration() is interruptible, then SIGCHLD interrupts it
  as well (try "/bin/sleep 1 & sleep 10").
* sleep_main() must not allocate anything as ^C in ash longjmp's.
  (currently, allocations are only on error paths, in message printing).

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-10 10:53:23 +02:00
Yousong Zhou 6ce1dc2e91 libiproute: fix filtering ip6 route by table id
Otherwise

 - "ip -6 route show" shows routes from all tables
 - "ip -6 route show table 200" shows nothing

function                                             old     new   delta
print_route                                         1962    1941     -21
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-21)             Total: -21 bytes

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-09 20:26:23 +02:00
Denys Vlasenko e41e481fd5 hush: fix a compile failure
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-08 17:57:42 +02:00
Denys Vlasenko 07a95cfcab ash: disable check for "good" function name, bash does not check this
function                                             old     new   delta
.rodata                                           105304  105261     -43
parse_command                                       1696    1633     -63
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-106)           Total: -106 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-04 14:38:25 +02:00
Denys Vlasenko e5692e2342 hush: quote values in "readonly" output
function                                             old     new   delta
builtin_readonly                                      61     107     +46
builtin_export                                       140     145      +5
.rodata                                           105321  105304     -17
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 51/-17)             Total: 34 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-03 14:30:59 +02:00
Denys Vlasenko cc9543fed1 shell/math: avoid $((3**999999999999999999)) to take years
function                                             old     new   delta
arith_apply                                          991    1030     +39

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-02 19:32:12 +02:00
Denys Vlasenko 045924ed7d shell/math: do not accept $((36#@))
function                                             old     new   delta
parse_with_base                                      170     174      +4
arith_apply                                          996     991      -5
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 4/-5)               Total: -1 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-02 17:58:20 +02:00
Denys Vlasenko 38f769ab4e shell/math: code shrink
function                                             old     new   delta
arith_apply                                          999     996      -3
evaluate_string                                     1295    1291      -4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-7)               Total: -7 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-30 19:16:41 +02:00
Denys Vlasenko 6a0ba67382 shell/math: code shrink
function                                             old     new   delta
arith_apply                                         1023     996     -27

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-29 11:01:50 +02:00
Denys Vlasenko 800207b90a shell/math: code shrink
function                                             old     new   delta
arith_apply                                         1015    1023      +8
evaluate_string                                     1309    1295     -14
.rodata                                           105344  105321     -23
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 8/-37)             Total: -29 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-28 14:18:35 +02:00
Denys Vlasenko e619a25a55 shell/math: improve comments
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-26 11:08:40 +02:00
Denys Vlasenko 5d8f8570c0 shell/math: rename TOK_NUM to TOK_VALUE, improve comments
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-26 10:02:54 +02:00
Denys Vlasenko c1c267fd36 shell/math: bash-compatible handling of too large numbers
function                                             old     new   delta
parse_with_base                                        -     170    +170
evaluate_string                                     1477    1309    -168
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/1 up/down: 170/-168)            Total: 2 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-25 17:42:05 +02:00
Denys Vlasenko 019dd31150 shell/math: disable debug again
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-19 10:23:58 +02:00
Denys Vlasenko db0e886735 shell/math: $((1?)) has one-too-small opstack, fix this
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-19 10:22:15 +02:00
Denys Vlasenko a165098922 shell/math: fix comments about jammed-together num+num corner cases
function                                             old     new   delta
evaluate_string                                     1478    1470      -8

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-19 09:44:04 +02:00
Denys Vlasenko 79b90cbece shell/math: add note on ERANGE
function                                             old     new   delta
evaluate_string                                     1488    1478     -10

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-18 20:15:35 +02:00
Denys Vlasenko 10cce8ae35 shell/math: explain why we use separate &end
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-18 19:30:22 +02:00
Denys Vlasenko 7701b526a7 shell/math: code shrink
function                                             old     new   delta
evaluate_string                                     1498    1491      -7

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-18 19:20:10 +02:00
Denys Vlasenko 8309c9159f shell/math: eliminate redundant endofname()
function                                             old     new   delta
evaluate_string                                     1486    1498     +12

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-18 19:03:05 +02:00
Denys Vlasenko b61fd8ec5a shell: typo fix in tests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-18 18:49:00 +02:00
Denys Vlasenko 2d06c83b87 shell/math: code shrink
function                                             old     new   delta
evaluate_string                                     1489    1486      -3

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-18 18:31:55 +02:00
Denys Vlasenko c72c5552ed shell/math: decrease stack usage by not allocating copies of variable names
We risk exhaust stack with alloca() with old code.

function                                             old     new   delta
arith_apply                                          990    1023     +33
evaluate_string                                     1467    1494     +27
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 60/0)               Total: 60 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-18 18:12:14 +02:00
Denys Vlasenko 182e5a4d00 shell/math: decrease stack usage
function                                             old     new   delta
evaluate_string                                     1412    1467     +55

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-18 18:12:04 +02:00
Denys Vlasenko 96769486e2 shell: move varcmp() to shell_common.h and use it in hush
function                                             old     new   delta
unset_local_var                                        -     112    +112
findvar                                               31      35      +4
set_vars_and_save_old                                144     141      -3
helper_export_local                                  235     230      -5
set_local_var                                        425     416      -9
handle_changed_special_names                          38      27     -11
builtin_unset                                        154     141     -13
builtin_getopts                                      404     391     -13
get_local_var_value                                  281     260     -21
get_ptr_to_local_var                                  71      45     -26
unset_local_var_len                                  139       -    -139
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 1/8 up/down: 116/-240)         Total: -124 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-17 21:13:13 +02:00
Denys Vlasenko d0441222db ash: code shrink
function                                             old     new   delta
setvar                                               166     164      -2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-17 20:45:02 +02:00
Denys Vlasenko 2ca9c45953 shell/read: do not allow empty variable name
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-17 19:52:20 +02:00
Denys Vlasenko 822590f5e2 shell/math: eliminate some redundant stores on return code path
function                                             old     new   delta
evaluate_string                                     1432    1412     -20

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-17 19:21:28 +02:00
Denys Vlasenko 19a74a54de shell/math: change ?: nesting code to not have 63 level nesting limitation
function                                             old     new   delta
evaluate_string                                     1406    1432     +26
arith                                                 36      29      -7
arith_apply                                          998     990      -8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 26/-15)             Total: 11 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-17 11:03:02 +02:00
Denys Vlasenko 6221832bc1 shell/math.h: update comments, rearrange struct members for smaller code
function                                             old     new   delta
arith_apply                                         1000     998      -2
evaluate_string                                     1414    1406      -8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-10)             Total: -10 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-17 10:40:29 +02:00
Denys Vlasenko d6f98f214b shell/math: code shrink
function                                             old     new   delta
evaluate_string                                     1432    1414     -18

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-17 00:28:49 +02:00
Denys Vlasenko 550696d492 shell/math: tweka comments
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-16 20:47:43 +02:00
Denys Vlasenko e127985839 shell/math: fix ?: to not evaluate not-taken branches
This fixes ash-arith-arith-ternary1/2.tests

function                                             old     new   delta
evaluate_string                                     1271    1432    +161
arith_apply                                          968    1000     +32
arith                                                 22      36     +14
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 207/0)             Total: 207 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-16 19:51:01 +02:00
Denys Vlasenko f8263528cd shell/math: simplify handling of unary plus
function                                             old     new   delta
evaluate_string                                     1257    1271     +14
arith_apply                                          977     968      -9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 14/-9)               Total: 5 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-15 17:16:46 +02:00
Denys Vlasenko 38f423cc9c shell/math: explain the logic, small tweak to make code smaller
function                                             old     new   delta
evaluate_string                                     1258    1257      -1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-15 16:46:31 +02:00
Denys Vlasenko ea6dcbe283 shell/math: fix order of expansion of variables to numbers
This fixes arith-assign-in-varexp1.tests

function                                             old     new   delta
evaluate_string                                     1132    1258    +126
arith_lookup_val                                     143       -    -143
arith_apply                                         1132     977    -155
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/1 up/down: 126/-298)         Total: -172 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-15 13:56:12 +02:00
Denys Vlasenko 22cb0d573a shell: document another arithmetic discrepancy with bash
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-15 12:44:43 +02:00
Denys Vlasenko 648f506949 libbb: code shrink: introduce and use [_]exit_FAILURE()
function                                             old     new   delta
exit_FAILURE                                           -       7      +7
_exit_FAILURE                                          -       7      +7
run                                                  198     199      +1
restore_state_and_exit                               114     115      +1
xbsd_write_bootstrap                                 399     397      -2
vfork_compressor                                     209     207      -2
sig_handler                                           12      10      -2
serial_ctl                                           154     152      -2
parse_args                                          1169    1167      -2
onintr                                                21      19      -2
make_new_session                                     493     491      -2
login_main                                           988     986      -2
gotsig                                                35      33      -2
do_iplink                                           1315    1313      -2
addgroup_main                                        397     395      -2
inetd_main                                          1911    1908      -3
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 2/12 up/down: 16/-25)            Total: -9 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-15 11:55:56 +02:00
Denys Vlasenko 61a4959251 shell/math: remove special code to handle a?b?c:d:e, it works without it now
The "hack" to virtually parenthesize ? EXPR : made this unnecessary.
The expression is effectively a?(b?(c):d):e and thus b?c:d is evaluated
before continuing with the second :

function                                             old     new   delta
evaluate_string                                     1148    1132     -16

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-15 11:22:13 +02:00
Denys Vlasenko 5f56a03882 shell/math: fix parsing of ?: and explain why it's parsed that way
This fixes arith-precedence1.tests.

This breaks arith-ternary2.tests again (we now evaluate variables
on not-taken branches). We need a better logic here anyway:
not only bare variables should not evaluate when not-taken:
	1 ? eval_me : do_not_eval
but any (arbitrarily complex) expressions shouldn't
evaluate as well!
	1 ? var_is_set=1 : ((var_is_not_set=2,var2*=4))

function                                             old     new   delta
evaluate_string                                     1097    1148     +51

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-15 10:14:43 +02:00
Denys Vlasenko 3829d8b675 shell/math: simpler insertion of "fake" last RPAREN
Skip one pass through token table, since we know the result.

function                                             old     new   delta
evaluate_string                                     1095    1097      +2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-15 09:19:48 +02:00
Denys Vlasenko 2ff01bb699 shell: sync ash/hush test scripts
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-14 15:19:02 +02:00
Denys Vlasenko 66139330fc shell/math: trivial code shrink
function                                             old     new   delta
arith_apply                                         1143    1132     -11

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-14 13:59:11 +02:00
Denys Vlasenko 3df885abe3 shell/math: fix the order of variable resolution in binops
function                                             old     new   delta
arith_apply                                         1134    1143      +9

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-14 11:33:59 +02:00
Denys Vlasenko 5febdb1223 shell/math: remove now-unused second_val
function                                             old     new   delta
arith_apply                                         1137    1134      -3
evaluate_string                                     1101    1095      -6
arith_lookup_val                                     150     143      -7
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-16)             Total: -16 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-14 11:10:45 +02:00
Denys Vlasenko 46dccd2ec0 shell/math: fix nested ?: and do not parse variables in not-taken branch
Fixes arith-ternary1.tests and arith-ternary_nested.tests

function                                             old     new   delta
evaluate_string                                     1043    1101     +58
arith_apply                                         1087    1137     +50
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 108/0)             Total: 108 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-14 11:07:30 +02:00
Denys Vlasenko a02450ff0b shell/math: remove a redundant check
function                                             old     new   delta
arith_apply                                         1134    1087     -47

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-14 01:05:40 +02:00
Denys Vlasenko 8acbf31708 shell/math: document ternary ?: op's weirdness, add code comments
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-14 00:41:18 +02:00
Denys Vlasenko 373f64eef3 syslogd: daemonize _after_ init (so that init errors are visible, if they occur)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-13 16:25:13 +02:00
Denys Vlasenko 02378ce20c syslogd: decrease stack usage, ~50 bytes
function                                             old     new   delta
syslogd_init                                           -    1007   +1007
syslogd_main                                        1619     636    -983
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/1 up/down: 1007/-983)          Total: 24 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-13 16:24:56 +02:00
Denys Vlasenko c1d7507a4d shell/math: fix one name check, other minor cleanups
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-13 16:15:18 +02:00
Denys Vlasenko 8ccb3f7b13 shell: add a few yet-failing arithmentic tests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-13 15:21:22 +02:00
Denys Vlasenko a4f30f3c70 shell/math: reduce stack usage
function                                             old     new   delta
arith_apply                                         1123    1134     +11
arith_lookup_val                                     140     145      +5
evaluate_string                                     1053    1047      -6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 16/-6)              Total: 10 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-13 13:55:13 +02:00
Denys Vlasenko d417193cf3 shell: avoid segfault on ${0::0/0~09J}. Closes 15216
function                                             old     new   delta
evaluate_string                                     1011    1053     +42

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-12 17:48:47 +02:00
Denys Vlasenko bab8828b0d hush: fix expansion of space in "a=${a:+$a }c" construct
function                                             old     new   delta
encode_then_append_var_plusminus                     554     552      -2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-12 16:39:32 +02:00
Denys Vlasenko 8f0e4c42c6 udhcpd: optional BOOTP support
from Adam Goldman <adamg@pobox.com>

This patch makes udhcpd respond correctly to queries from BOOTP clients.

It contains the following changes:

The end field, or DHCP_END option, is required in DHCP requests but
optional in BOOTP requests. However, we still send an end
field in all replies, because some BOOTP clients expect one in replies
even if they didn't send one in the request.

Requests without a DHCP_MESSAGE_TYPE are recognized as BOOTP requests
and handled appropriately, instead of being discarded. We still require
an RFC 1048 options field, but we allow it to be empty.

Since a BOOTP client will keep using the assigned IP forever, we only
send a BOOTP reply if a static lease exists for that client.

BOOTP replies shouldn't contain DHCP_* options, so we omit them if there
was no DHCP_MESSAGE_TYPE in the request. Options other than DHCP_*
options are still sent.

The options field of a BOOTP reply must be exactly 64 bytes. If we
construct a reply with more than 64 bytes of options, we give up and log
an error instead of sending it. udhcp_send_raw_packet already pads the
options field to 64 bytes if it is too short.

This implementation has been tested against an HP PA-RISC client.

function                                             old     new   delta
.rodata                                           105247  105321     +74
udhcpd_main                                         1520    1591     +71
send_offer                                           419     470     +51
init_packet                                           81      97     +16
udhcp_init_header                                     75      88     +13
udhcp_scan_options                                   192     203     +11
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 6/0 up/down: 236/0)             Total: 236 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-12 13:22:47 +02:00
Denys Vlasenko 4bd70463c7 libbb: pass "" rather than NULL as format string in _nomsg functions
function                                             old     new   delta
bb_perror_nomsg_and_die                                9      10      +1
bb_perror_nomsg                                        9      10      +1
bb_verror_msg                                        480     469     -11
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 2/-11)              Total: -9 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-12 10:19:29 +02:00
Denys Vlasenko 2ca39ffd44 awk: fix subst code to handle "start of word" pattern correctly (needs REG_STARTEND)
function                                             old     new   delta
awk_sub                                              637     714     +77

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-08 10:42:39 +02:00
Denys Vlasenko 113685fbcd awk: fix SEGV on read error in -f PROGFILE
function                                             old     new   delta
awk_main                                             829     843     +14

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-07 10:54:34 +02:00
Denys Vlasenko f4789164e0 awk: code shrink
function                                             old     new   delta
awk_sub                                              544     548      +4
exec_builtin                                        1136    1130      -6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 4/-6)               Total: -2 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-06 12:48:11 +02:00
Denys Vlasenko 5f84c56336 awk: fix backslash handling in sub() builtins
function                                             old     new   delta
awk_sub                                              559     544     -15

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-03 00:42:10 +02:00
Denys Vlasenko 0256e00a9d awk: fix precedence of = relative to ==
Discovered while adding code to disallow assignments to non-lvalues

function                                             old     new   delta
parse_expr                                           936     991     +55
.rodata                                           105243  105247      +4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 59/0)               Total: 59 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-30 16:44:04 +02:00
Denys Vlasenko fe0b798548 tunctl: code shrink
function                                             old     new   delta
.rodata                                           105246  105243      -3
tunctl_main                                          349     344      -5
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-8)               Total: -8 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-29 14:47:10 +02:00
Denys Vlasenko 721bf6eaf4 awk: printf(INVALID_FMT) prints it verbatim
function                                             old     new   delta
awk_printf                                           628     640     +12

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-29 10:55:40 +02:00
Denys Vlasenko 4d7339204f awk: shrink - use setvar_sn() to set variables from non-NUL terminated strings
function                                             old     new   delta
setvar_sn                                              -      39     +39
exec_builtin                                        1145    1136      -9
awk_getline                                          591     559     -32
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/2 up/down: 39/-41)             Total: -2 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-28 18:08:06 +02:00
Denys Vlasenko 05e60007d4 awk: code shrink
function                                             old     new   delta
awk_getline                                          620     591     -29

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-28 17:51:59 +02:00
Denys Vlasenko b76b420b5d awk: fix closing of non-opened file
function                                             old     new   delta
setvar_ERRNO                                           -      53     +53
.rodata                                           105252  105246      -6
awk_getline                                          639     620     -19
evaluate                                            3402    3377     -25
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/3 up/down: 53/-50)              Total: 3 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-28 17:25:56 +02:00
Denys Vlasenko 9790eb73c8 libbb/dump: code shrink
function                                             old     new   delta
.rodata                                           105252  105246      -6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-28 13:32:07 +02:00
Denys Vlasenko 21dce1c3c3 awk: do not read ARGIND, only set it (gawk compat)
function                                             old     new   delta
next_input_file                                      216     243     +27
evaluate                                            3396    3402      +6
awk_main                                             826     829      +3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 36/0)               Total: 36 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-27 19:11:28 +02:00
Denys Vlasenko 5c8a9dfd97 awk: remove a local variable "caching" a struct member
Since we take its address, the variable lives on stack (not a GPR).
Thus, nothing is improved by caching it.

function                                             old     new   delta
awk_getline                                          642     639      -3

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-27 18:21:38 +02:00
Denys Vlasenko 528808bcd2 awk: get rid of one indirection level for iF (input file structure)
function                                             old     new   delta
try_to_assign                                          -      91     +91
next_input_file                                      214     216      +2
awk_main                                             827     826      -1
evaluate                                            3403    3396      -7
is_assignment                                         91       -     -91
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 1/2 up/down: 93/-99)             Total: -6 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-27 18:05:42 +02:00
Denys Vlasenko 84ff1825dd awk: fix splitting with default FS
function                                             old     new   delta
awk_split                                            543     544      +1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-27 16:17:38 +02:00
Denys Vlasenko 9225f9684f libbb/dump: make xxd_displayoff member conditional on xxd
With xxd not selected:

function                                             old     new   delta
display                                             1459    1444     -15

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-27 14:52:17 +02:00
Denys Vlasenko 6d9427420b od: -l,I,L indeed depend on sizeof(long), fix this
function                                             old     new   delta
.rodata                                           105255  105252      -3
od_main                                             1917    1901     -16
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-19)             Total: -19 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-26 20:17:04 +02:00
Denys Vlasenko 5dcc443dba awk: fix use-after-realloc (CVE-2021-42380), closes 15601
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-26 19:36:58 +02:00
Denys Vlasenko d7814f5727 hexdump: code shrink
function                                             old     new   delta
add_format                                             -      50     +50
add_first                                             10       -     -10
hexdump_main                                         401     366     -35
.rodata                                           105306  105255     -51
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 0/2 up/down: 50/-96)            Total: -46 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-26 16:43:40 +02:00
Denys Vlasenko 283cba78f2 hexdump, xxd: shrink strings
function                                             old     new   delta
add_first                                             12      10      -2
.rodata                                           105321  105306     -15
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-17)             Total: -17 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-26 14:46:29 +02:00
Denys Vlasenko 34751d8bf9 libbb/dump: correct handling of 1-byte signed int format
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-26 14:10:38 +02:00
Denys Vlasenko 8fab211141 libbb/dump: use fputs_stdout where appropriate
function                                             old     new   delta
display                                             1485    1483      -2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-26 13:39:33 +02:00
Denys Vlasenko de851bc9b2 od, hexdump: byte 0x11 is "dc1" not "dcl"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-26 13:33:08 +02:00
Denys Vlasenko 25a10ffe1f od: actually remove -IL from --help, as comment says
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-26 13:01:41 +02:00
Denys Vlasenko 60d4d55b87 od: support -DOHXIL
function                                             old     new   delta
od_main                                             1866    1917     +51
.rodata                                           105306  105321     +15
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 66/0)               Total: 66 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-26 12:56:17 +02:00
Denys Vlasenko 3c6f6382ee libbb/dump: conditionalize code used only by xxd and od
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-26 12:34:11 +02:00
Denys Vlasenko aa4d303a31 od: fix default format, shrink
function                                             old     new   delta
od_main                                              556     568     +12
.rodata                                           104613  104555     -58
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 12/-58)            Total: -46 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-26 04:27:43 +02:00
Denys Vlasenko 0c3270f7e5 od: stop printing extra trailing spaces
function                                             old     new   delta
.rodata                                           104598  104613     +15
display                                             1475    1485     +10
od_main                                              549     556      +7
rewrite                                              971     967      -4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/1 up/down: 32/-4)              Total: 28 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-25 23:48:13 +02:00
Denys Vlasenko 6882a933cf od: implement -B
function                                             old     new   delta
.rodata                                           105305  105306      +1
od_main                                             1880    1866     -14
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 1/-14)             Total: -13 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-25 22:17:18 +02:00
Denys Vlasenko ce4cfc33ca od: correct -i, enable tests which pass for DESKTOP too
function                                             old     new   delta
.rodata                                           105302  105305      +3

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-25 19:51:37 +02:00
Denys Vlasenko e2287f99fe od: for !DESKTOP, match output more closely to GNU coreutils 9.1, implement -s
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-25 17:40:20 +02:00
David Leonard 64bdd7566c od: add tests
* Added tests for od (non-DESKTOP little-endian)
* Allow 'optional' to invert meaning of a config option with '!'

Signed-off-by: David Leonard <d+busybox@adaptive-enterprises.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-25 15:32:03 +02:00
David Leonard 2bda790fd1 od: fix -O
od with option -O (4-byte octal) was incorrectly displaying 2-byte
decimal when built without CONFIG_DESKTOP

Signed-off-by: David Leonard <d+busybox@adaptive-enterprises.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-25 15:32:03 +02:00
Denys Vlasenko b5be8da350 hush: make "false" built-in
function                                             old     new   delta
bltins1                                              384     396     +12
builtin_false                                          -       6      +6
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/0 up/down: 18/0)               Total: 18 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-25 15:24:56 +02:00
Denys Vlasenko 6824298ab4 hush: fix ELIF cmd1;cmd2 THEN ... not executing cmd2, closes 15571
function                                             old     new   delta
run_list                                            1012    1024     +12

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-25 14:22:10 +02:00
Karsten Sperling 3e83699ce2 ash: use-after-free in bash pattern substitution
Commit daa66ed6 fixed a number of use-after-free bugs in bash pattern
substitution, however one "unguarded" STPUTC remained, which is fixed here.

function                                             old     new   delta
subevalvar                                          1564    1576     +12

Signed-off-by: Karsten Sperling <ksperling@apple.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-18 16:49:54 +02:00
Denys Vlasenko c5682813ab examples/var_service/README: fix an error
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-18 13:30:10 +02:00
Denys Vlasenko 2f663a6f7d cpio: tweak --help
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-09 20:35:16 +02:00
Denys Vlasenko dc84002a82 nslookup: code shrink
function                                             old     new   delta
send_queries                                         725     723      -2
nslookup_main                                        822     820      -2
add_query                                             89      86      -3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-7)               Total: -7 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-09 19:32:29 +02:00
Denys Vlasenko 62775ec4b3 nslookup: ensure unique transaction IDs for the DNS queries
Based on patch by Uwe Kleine-König.

It makes sense to actually see the nitty-gritty details of DNS
querying, so bringing in (commented-out) musl's DNS request code.

function                                             old     new   delta
nslookup_main                                        760     822     +62

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-09 19:21:45 +02:00
Denys Vlasenko 3a7f00eadc hush: add comment about abort on syntax error %{^}
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-09 14:02:06 +02:00
Denys Vlasenko 465f05a420 build system: fix "Config.in:117 error: Overlong line"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-08 12:31:34 +02:00
Denys Vlasenko 3c8e540eb7 hush: fix an interactive abort on error
function                                             old     new   delta
parse_and_run_stream                                 140     155     +15

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-08 12:27:50 +02:00
Uwe Kleine-König 40fa8eb998 build system: Make it possible to build with 64bit time_t
On most 32bit architectures time_t (and a few other time related types)
are a signed 32bit wide integer type.
As a consequence they can only represent dates between

	Fri Dec 13 08:45:52 PM UTC 1901

(-0x80000000 seconds before Jan 1 1970) and

	Tue Jan 19 03:14:07 AM UTC 2038

(0x7fffffff seconds after Jan 1 1970). Given that some machines that are
built today have an expected lifetime of >15 years, this needs to be
extended. To to that, define the cpp symbol _TIME_BITS to 64 which
results in some magic in glibc to make time_t (and the few other time
related types) 64 bit wide.

This new switch CONFIG_TIME64 is in the spirit of CONFIG_LFS and only
expected to have the expected effect with glibc. On musl for examples
time_t already defaults to 64bit wide types.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-07 18:57:06 +02:00
Denys Vlasenko 07f8b6feac readlink: code shrink
function                                             old     new   delta
readlink_main                                        111     103      -8

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-07 18:44:03 +02:00
Denys Vlasenko c6058d221a nmeter: improve %T fractionals display
function                                             old     new   delta
nmeter_main                                          751     786     +35

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-07 18:35:22 +02:00
Denys Vlasenko 382e163497 factor: we can pack 21, not 20, 3-bit elements into packed wheel words
function                                             old     new   delta
packed_wheel                                         192     184      -8
factor_main                                          171     163      -8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-16)             Total: -16 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-23 14:02:20 +02:00
Denys Vlasenko 7ddd233c80 ip: code shrink
function                                             old     new   delta
ipaddr_list_or_flush                                1089    1079     -10

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-23 12:37:46 +02:00
Eric Blake d2b81b3dc2 readlink: support --, -n always
POSIX will be standardizing readlink (just the -n option) and realpath
(just -E and -e options):
https://www.austingroupbugs.net/view.php?id=1457

Change things for readlink so that the POSIX-mandated -n and -- work
even when disabling the non-standard (and partially non-working) -f
when FEATURE_READLINK_FOLLOW is clear.

POSIX also wants readlink to be verbose by default (if the argument is
not a symlink, readlink must output a diagnostic); I did NOT address
that one, because I'm waiting to see what the GNU Coreutils folks do:
https://lists.gnu.org/archive/html/bug-coreutils/2023-03/msg00035.html

Partial fix for https://bugs.busybox.net/show_bug.cgi?id=15466

function                                             old     new   delta
packed_usage                                       34538   34557     +19

Signed-off-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-16 18:01:44 +02:00
Ron Yorston 2ffd8986e2 tr: display usage for incorrect arguments
tr must have one or two non-option arguments.  Display the usage
message if any other number is present.

function                                             old     new   delta
.rodata                                           108389  108392      +3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 3/0)                 Total: 3 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-16 17:54:00 +02:00
Ron Yorston acae889dd9 ash,hush: tab completion of functions and aliases
Since commit 9e2a5668f (ash,hush: allow builtins to be tab-completed,
closes 7532) ash and hush have supported tab completion of builtins.

Other shells, bash and ksh for example, also support tab completion
of functions and aliases.

Add such support to ash and hush.

function                                             old     new   delta
ash_command_name                                       -      92     +92
hush_command_name                                      -      63     +63
ash_builtin_name                                      17       -     -17
hush_builtin_name                                     38       -     -38
------------------------------------------------------------------------------
(add/remove: 2/2 grow/shrink: 0/0 up/down: 169/-55)           Total: 100 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Avi Halachmi <avihpit@yahoo.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-16 17:15:05 +02:00
Denys Vlasenko 90b607d79a hush: quote variable values printed by "set" (match ash behavior)
function                                             old     new   delta
builtin_set                                          258     301     +43

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-13 09:20:24 +02:00
Denys Vlasenko 8b72877bab shuf: another tweak to COMMON_PREFIX_HACK code
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-13 03:02:11 +02:00
Tomas Paukrt 7c1f975cdd build system: clean more files on make clean
Signed-off-by: Tomas Paukrt <tomaspaukrt@email.cz>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2023-04-12 20:31:44 +02:00
Denys Vlasenko f7065aa9ae shuf: fix pfx_len calculation
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-12 14:56:05 +02:00
Denys Vlasenko 8696f5d380 shuf: remove redundant code
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-12 14:51:11 +02:00
Denys Vlasenko 238dab322a shuf: add (disabled) code to support very long numbers in -i LO-HI
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-12 14:47:24 +02:00
Akos Somfai 853cfe927f lineedit: fix crash when icanon set with -echo
When icanon is set with -echo (e.g. ssh from an emacs shell) then
S.state will remain null but later it will be deferenced causing ash to
crash. Fix: additional check on state.

Signed-off-by: Akos Somfai <akos.somfai@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-12 13:49:14 +02:00
Denys Vlasenko 550e6d8fbd sleep: fix error exit when called as "sh" builtin
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-12 12:23:36 +02:00
Denys Vlasenko 478b5ac2bc seq: fix yet another case of negative parameters not working
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-11 20:29:59 +02:00
Thomas Devoogdt cb57abb46f seedrng: fix for glibc <= 2.24 not providing random header
- dropped the wrong define (not sure why it was there)
 - <sys/random.h> not available if glibc <= 2.24
 - GRND_NONBLOCK not defined if <sys/random.h> not included
 - ret < 0 && errno == ENOSYS has to be true to get creditable set

Signed-off-by: Thomas Devoogdt <thomas@devoogdt.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-11 13:56:12 +02:00
Denys Vlasenko 200a9669fb seedrng: fix for glibc <= 2.24 not providing getrandom()
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-10 17:26:04 +02:00
Tomas Paukrt 85e4805ae9 appletlib: fix "warning: unused variable applet_no"
Signed-off-by: Tomas Paukrt <tomaspaukrt@email.cz>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-10 16:56:55 +02:00
Denys Vlasenko 7362d29794 ash: fix sleep built-in not running INT trap immediately on ^C
function                                             old     new   delta
sleep_for_duration                                   169     149     -20

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-10 16:30:27 +02:00
Denys Vlasenko 611729eff3 mkfs_vfat: do not generate same volume_id when run in rapid succession
function                                             old     new   delta
mkfs_vfat_main                                      1502    1523     +21

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-10 14:47:38 +02:00
Denys Vlasenko 9bc2b6e884 seq: accept negative parameters
function                                             old     new   delta
seq_main                                             429     476     +47
packed_usage                                       34557   34538     -19
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 47/-19)             Total: 28 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-10 14:33:20 +02:00
Denys Vlasenko a26711a2d1 libbb: consolidate NOMMU fix of restoring high bit in argv[0][0]
function                                             old     new   delta
fork_or_rexec                                         46      56     +10
bootchartd_main                                     1087    1079      -8
cpio_main                                            674     661     -13
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 10/-21)            Total: -11 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-06 21:20:28 +02:00
Denys Vlasenko 05f2bedaeb ash: sleep builtin with no arguments should not exit
function                                             old     new   delta
sleep_main                                           116     143     +27
.rodata                                           105245  105268     +23
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 50/0)               Total: 50 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-03 19:54:42 +02:00
Denys Vlasenko ff8fde111e hush: printf builtin with no arguments should not exit
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-03 19:29:57 +02:00
Denys Vlasenko 46e92e1e56 ash: code shrink: do not take address of prefix(), allowing it to inline
function                                             old     new   delta
getjob                                               281     285      +4
prefix                                                13       -     -13
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/0 up/down: 4/-13)              Total: -9 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-03 17:30:03 +02:00
Denys Vlasenko a33d19eba8 ash: code shrink - reuse is_prefixed_with() from libbb
function                                             old     new   delta
changepath                                            67      68      +1
legal_pathopt                                         70      66      -4
prefix                                                34      13     -21
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 1/-25)             Total: -24 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-03 15:19:13 +02:00
Denys Vlasenko 94780e3e8e ash: get rid of separate mail_var_path_changed flag variable
We can just clear mailtime_hash to zero and have the same effect.

function                                             old     new   delta
changemail                                             8      11      +3
mail_var_path_changed                                  1       -      -1
cmdloop                                              398     382     -16
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/1 up/down: 3/-17)             Total: -14 bytes
   text	   data	    bss	    dec	    hex	filename
1054786	    559	   5020	1060365	 102e0d	busybox_old
1054773	    559	   5020	1060352	 102e00	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-03 15:01:00 +02:00
Denys Vlasenko 7ababc3e3c ash: fix still-broken new mail detection
padvance() exit condition is return value < 0, not == 0.
After MAIL changing twice, the logic erroneously
concluded that "you have new mail".

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-03 14:41:01 +02:00
Denys Vlasenko 2860b2530e ash: fix broken new mail detection
Mea culpa, in "Do not allocate stack string in padvance" commit
(I left an extraneous "break" statement).

function                                             old     new   delta
cmdloop                                              329     398     +69

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-03 14:01:36 +02:00
Denys Vlasenko 6748e6494c hush (NOMMU): fix LINENO in execed children
function                                             old     new   delta
hush_main                                           1815    1851     +36
re_execute_shell                                     601     635     +34
.rodata                                           102721  102726      +5
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 75/0)               Total: 75 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-01 23:17:53 +02:00
Denys Vlasenko fd5fb2d2b5 hush: speed up "big heredoc" code
function                                             old     new   delta
hush_main                                           1810    1815      +5
.rodata                                           102723  102721      -2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 5/-2)                Total: 3 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-01 22:52:08 +02:00
Denys Vlasenko 1409432d07 hush: add TODO comment
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-01 22:16:32 +02:00
Denys Vlasenko 00fc136843 ash: code shrink
function                                             old     new   delta
describe_command                                     323     320      -3
dotcmd                                               324     309     -15
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-18)             Total: -18 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-01 11:11:20 +02:00
Denys Vlasenko 262a845477 ash: exec: Stricter pathopt parsing - lost chunk
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-03-31 21:35:50 +02:00
Ron Yorston 098cd7ece4 ash: improve trap and jobs builtins in child shells
The trap and jobs builtins can be used to report information about
traps and jobs.  This works when they're called from the current
shell but in a child shell the required information is usually
cleared.  Special hacks allow:

- trap to work with command substitution;
- jobs to work with command substitution or in a pipeline.

Neither works with process substitution.

- Relax the test for the trap hack so it also supports pipelines.

- Pass the command to be evaluated to forkshell() in evalbackcmd()
  so trap and jobs both work with process substitution.

function                                             old     new   delta
forkchild                                            629     640     +11
argstr                                              1502    1496      -6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 11/-6)               Total: 5 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-03-31 14:22:56 +02:00
Denys Vlasenko af5277f883 modprobe: call finit_module with MODULE_INIT_COMPRESSED_FILE if module name doesn't end with .ko
IOW: if name doesn't end with .ko, assume it's .gz/.xz or similar,
and ask kernel to uncompress it.

If finit_module(MODULE_INIT_COMPRESSED_FILE) fails, retry with
finit_module(0).

function                                             old     new   delta
bb_init_module                                       151     197     +46

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-03-31 13:15:58 +02:00
Ron Yorston 470fa7b364 ash: make EPOCH variables work if RANDOM is disabled
Commit 1d37186fe2 (ash: add bash-compatible EPOCH variables) added
support for the EPOCHSECONDS and EPOCHREALTIME variables.

These variables are dynamic and therefore require the VDYNAMIC flag
to be non-zero.  However, this is only the case if support for the
RANDOM variable is enabled.

Give VDYNAMIC a non-zero value if either EPOCH variables or RANDOM
are enabled.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-03-29 16:45:13 +02:00
Ron Yorston f2e659415a lineedit: fix matching of directories when searching PATH
Commit 8baa643a3 (lineedit: match local directories when searching
PATH) included subdirectories of the current directory in the search
when tab-completing commands.

Unfortunately a short time later commit 1d180cd74 (lineedit: use
strncmp instead of is_prefixed_with (we know the length)) broke
this feature by returning an incorrect length for the array of paths.

Fix the length and reinstate matching of subdirectories.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-03-29 16:45:13 +02:00
Denys Vlasenko a59e5a7d08 libbb/sha: do not read shaNI variable twice, and factor out its setting
My gcc inlines both calls, so instead of "-20 bytes" I get only this:

function                                             old     new   delta
sha256_begin                                          84      83      -1
sha1_begin                                           114     111      -3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-4)               Total: -4 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-03-29 15:46:32 +02:00
Denys Vlasenko bd76b75f72 libbb/sha: fix sha-NI instruction detection
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-03-29 15:17:00 +02:00
Denys Vlasenko 3253d7fe00 httpd: do not mangle cgi-bin/SCRIPT/params URLs
If cgi-bin/ prefix is seen, do not test the rest for existence,
whether it's a dir, and such.

function                                             old     new   delta
handle_incoming_and_exit                            2200    2212     +12

Reported here:
https://lists.zx2c4.com/pipermail/cgit/2023-March/004825.html

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-03-28 18:56:08 +02:00
David Leonard d8a3360380 find: implement -ok
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/find.html

  -ok  utility_name  [argument ...] ;
    The -ok primary shall be equivalent to -exec, except that the use
    of a <plus-sign> to punctuate the end of the primary expression
    need not be supported, and find shall request affirmation of the
    invocation of utility_name using the current file as an argument
    by writing to standard error as described in the STDERR section. If
    the response on standard input is affirmative, the utility shall be
    invoked. Otherwise, the command shall not be invoked and the value
    of the -ok operand shall be false.

function                                             old     new   delta
do_exec                                              438     517     +79
parse_params                                        1833    1845     +12
static.params                                        288     292      +4
.rodata                                           100771  100775      +4
packed_usage                                       34543   34541      -2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/1 up/down: 99/-2)              Total: 97 bytes

Signed-off-by: David Leonard <d+busybox@adaptive-enterprises.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-03-28 18:08:02 +02:00
Arsen Arsenović 2d4a3d9e6c fixdep: avoid underflow when end of entry doesn't coincide with EOF
Bug: https://bugs.gentoo.org/893776
Closes: https://bugs.busybox.net/show_bug.cgi?id=15326
Signed-off-by: Arsen Arsenović <arsen@gentoo.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-02-27 13:09:44 +01:00
Denys Vlasenko 029740a3e4 unzip: document some options we might support
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-02-23 12:00:36 +01:00
Denys Vlasenko 75197998c2 unzip: clear SUID/GID bits, implement -K to not clear them
function                                             old     new   delta
unzip_main                                          2656    2715     +59
packed_usage                                       34517   34552     +35
.rodata                                           105250  105251      +1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 95/0)               Total: 95 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-02-22 10:50:14 +01:00
Denys Vlasenko 669c40ed8e top: stop using div() from libc, compilers now do it better
function                                             old     new   delta
div                                                   23       -     -23
display_process_list                                1237    1178     -59
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 0/1 up/down: 0/-82)             Total: -82 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-02-13 15:05:19 +01:00
Denys Vlasenko 93ae7464e6 hush: restore SIGHUP handling, this time explain why we do what we do
function                                             old     new   delta
check_and_run_traps                                  229     278     +49

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-30 18:48:36 +01:00
Denys Vlasenko 1fdb33bd07 hush: restore tty pgrp on SIGHUP
Found one case where SIGHUP does need some handling.

ash does not restore tty pgrp when killed by SIGHUP, and
this means process which started ash needs to restore it,
or it would get backgrounded when trying to use tty.

function                                             old     new   delta
check_and_run_traps                                  214     229     +15

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-30 16:49:48 +01:00
Denys Vlasenko 6101b6d3ea hush: remove special handling of SIGHUP
Kernel should do the right thing.
(ash and dash do not have special SIGHUP handling.)

function                                             old     new   delta
check_and_run_traps                                  278     214     -64

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-30 15:57:04 +01:00
Denys Vlasenko 93e0898c66 shell: fix SIGWINCH and SIGCHLD (in hush) interrupting line input, closes 15256
function                                             old     new   delta
record_pending_signo                                  32      63     +31
lineedit_read_key                                    231     224      -7
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 31/-7)              Total: 24 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-26 12:56:33 +01:00
Denys Vlasenko c2739e11de nmeter: increase maximum /proc file size (needed for large machines)
function                                             old     new   delta
get_file                                             185     201     +16

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-24 12:47:32 +01:00
Denys Vlasenko 1040f78176 ntpd: correct comment: 2^-20 is ~1 microsecond (confused with 10^-20)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-18 18:04:22 +01:00
Denys Vlasenko 479bd7af0d ntpd: fold d_to_tv() into its only caller
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-18 17:42:17 +01:00
Denys Vlasenko c344ca6c7f ntpd: correct fixed->float conversions of fractions
Need to divide by (1<<32), not by (1<<32)-1.
Fraction of 0xffffffff is not 1 whole second.

function                                             old     new   delta
.rodata                                           105264  105268      +4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-17 17:01:05 +01:00
Miroslav Lichvar 85acf71d25 ntpd: make NTP client and server Y2036/2038-ready
The 32-bit integer part of the NTP timestamp overflows in year 2036,
which starts the second NTP era.

Modify the timestamp conversion to shift values between 1900-1970 (in
the first era) to the second era to enable the client to measure its
offset correctly until year 2106 (assuming 64-bit time_t).

Also update the conversion from double used when stepping the clock to
work with 64-bit time_t after reaching the maximum 32-bit value in 2038
and the server conversion to work correctly in the next NTP era.

function                                             old     new   delta
lfp_to_d                                              51      64     +13
step_time                                            326     332      +6
.rodata                                           105260  105264      +4
d_to_lfp                                             100      86     -14
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/1 up/down: 23/-14)              Total: 9 bytes

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-17 16:48:54 +01:00
Sören Tempel ca96022d6e ed: don't use memcpy with overlapping memory regions
The memcpy invocations in the subCommand function, modified by this
commit, previously used memcpy with overlapping memory regions. This is
undefined behavior. On Alpine Linux, it causes BusyBox ed to crash since
we compile BusyBox with -D_FORTIFY_SOURCE=2 and our fortify-headers
implementation catches this source of undefined behavior [0]. The issue
can only be triggered if the replacement string is the same size or
shorter than the old string.

Looking at the code, it seems to me that a memmove(3) is what was
actually intended here, this commit modifies the code accordingly.

[0]: https://gitlab.alpinelinux.org/alpine/aports/-/issues/13504

Signed-off-by: Sören Tempel <soeren+git@soeren-tempel.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-05 16:21:48 +01:00
Denys Vlasenko b1884deb51 Start 1.37.0 development cycle
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-03 15:32:00 +01:00
Denys Vlasenko 70f77e4617 Bump version to 1.36.0
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-03 15:15:41 +01:00
Denys Vlasenko 969e008168 hush: code shrink
function                                             old     new   delta
run_list                                            1032    1012     -20

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-03 14:08:18 +01:00
Denys Vlasenko d488a5218b ash: trivial code shrink
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-03 13:39:14 +01:00
Denys Vlasenko bcb90b9c41 xxd: use bb_simple_perror_msg... where appropriate
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-03 08:30:12 +01:00
Denys Vlasenko 27be0e8cfe shell: fix compile failures in some configs
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-03 08:28:16 +01:00
Denys Vlasenko 8ed57db65b Makefile.flags: add resolv to LDLIBS for linux compilers too (not only gnu ones)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-02 17:10:04 +01:00
Denys Vlasenko 9b2d766e0e sed: fix double-free in FEATURE_CLEAN_UP=y configs
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-02 17:05:55 +01:00
Denys Vlasenko cadf57b3af mv: fix error in !VERBOSE configs
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-02 17:04:44 +01:00
Denys Vlasenko e7977df2ca libbb/loop: fix compile failure (name collision)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-02 17:03:44 +01:00
Denys Vlasenko fb0c000567 testsuite/sha1sum.tests: fix false positive failure
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-02 17:02:17 +01:00
Denys Vlasenko dc068abad5 testsuite/tree.tests: fix false positive failure
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-02 17:01:14 +01:00
Denys Vlasenko adb1c7dcfe xxd: fix use of non-initialized data
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-02 16:59:40 +01:00
Denys Vlasenko c4d296aa7c xargs: implement -o, closes 15146
function                                             old     new   delta
.rodata                                           105225  105259     +34
d6_listen_socket                                     150     180     +30
packed_usage                                       34512   34532     +20
d6_read_interface                                    595     581     -14
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/1 up/down: 84/-14)             Total: 70 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-12-22 10:38:08 +01:00
Denys Vlasenko 02ca565646 udhcpc6: fix binding to network aliases
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-12-15 23:57:27 +01:00
Denys Vlasenko 6c2ddf808e udhcp: add a few comments, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-12-15 13:34:52 +01:00
Denys Vlasenko 242d056230 udhcpc6: use a different default config script
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-12-15 11:51:16 +01:00
Denys Vlasenko 301ef96892 udhcpc6: align FF02__1_2[]
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-12-15 11:49:00 +01:00
Natanael Copa 3636d52cbe more: accept and ignore -e
Accept and ignore -e which is specified in POSIX.
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/more.html

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-12-14 16:05:43 +01:00
Denys Vlasenko e977853e70 udhcpc6: add some comments
RFCs for DHCPv6 are written rather badly...

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-12-14 00:36:59 +01:00
Denys Vlasenko 9898db4c94 udhcpc6: remove stray comment
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-12-13 23:21:59 +01:00
Denys Vlasenko 7710250e4a libbb: shrink del_loop()
function                                             old     new   delta
del_loop                                              52      49      -3

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-12-13 16:00:00 +01:00
Denys Vlasenko a55bd1c484 loop: restore the correct return vaule of set_loop()
It is only used by mount's error path, though...

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-12-13 15:52:52 +01:00
Denys Vlasenko 45734a2351 loop: optionally use ioctl(LOOP_CONFIGURE) to set up loopdevs
LOOP_CONFIGURE is added to Linux 5.8

function                                             old     new   delta
NO_LOOP_CONFIGURE (old code):
set_loop                                             784     782      -2
LOOP_CONFIGURE:
set_loop                                             784     653    -131
TRY_LOOP_CONFIGURE:
set_loop                                             784     811     +27

Based on a patch by Xiaoming Ni <nixiaoming@huawei.com>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-12-13 15:21:28 +01:00
Denys Vlasenko 9df54deead testsuite/mount.tests: accomodate umount failure seen on 5.18.0
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-12-13 15:12:31 +01:00
Xiaoming Ni a1856934ba loop: refactor: extract subfunction set_loopdev_params()
Extract subfunction set_loop_info() from set_loop()

function                                             old     new   delta
set_loop                                             760     784     +24

Signed-off-by: Xiaoming Ni <nixiaoming@huawei.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-12-13 14:26:20 +01:00
Xiaoming Ni 7dc76c9f21 loop: simplify code of LOOP_SET_FD failure
function                                             old     new   delta
set_loop                                             790     760     -30

Signed-off-by: Xiaoming Ni <nixiaoming@huawei.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-12-12 19:03:06 +01:00
Xiaoming Ni ddccf6cd2f loop: refactor: extract subfunction get_next_free_loop()
Extract subfunction get_next_free_loop() from set_loop()

Also fix miss free(try) when stat(try) and mknod fail

function                                             old     new   delta
set_loop                                             807     790     -17

Fixes: 3448914e8cc5 ("mount,losetup: use /dev/loop-control is it exists")
Signed-off-by: Xiaoming Ni <nixiaoming@huawei.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-12-12 18:57:09 +01:00
Brandon Maier 90456a6aa3 xxd: fix typo in trivial usage
Signed-off-by: Brandon Maier <brandon.maier@collins.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-12-08 17:13:11 +01:00
Peter Kaestle 7ade421b1a unzip -l: add missed big-endian conversions date and time
When calling unzip -l the date and time output was missing big-endian
conversions.

Signed-off-by: Peter Kaestle <peter.kaestle@nokia.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-11-29 14:44:39 +01:00
Denys Vlasenko 99476502f9 Remove "select PLATFORM_LINUX"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-11-29 14:14:06 +01:00
Samuel Thibault 77216c368f Fix non-Linux builds
Various tools are Linuxish and should thus only attempted to build on
Linux only. Some features are also Linux-only.

Also, libresolv is used on all GNU platforms, notably GNU/Hurd and
GNU/kfreeBSD.

Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-11-29 14:10:22 +01:00
Dario Binacchi 75fbff1326 fbset: support setting pixel clock rate
Only in case the FEATURE_FBSET_FANCY configuration is enabled.

function                                             old     new   delta
fbset_main                                           733     766     +33

Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-11-16 13:40:34 +01:00
Dario Binacchi e8dfa0c1be fbset: abort on not handled options
Not all options are actually implemented. In this case, return a message
and an error code to make it clear that the requested command has not
been executed.

function                                             old     new   delta
.rodata                                           105200  105224     +24
fbset_main                                           747     733     -14
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 24/-14)             Total: 10 bytes

Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-11-16 13:39:35 +01:00
Xiaoming Ni cb8d2ea8c9 loop: fix a race when a free loop device is snatched
When /dev/loop-control exists and *device is empty,
the mount may fail if a concurrent mount is running.

function                                             old     new   delta
set_loop                                             809     807      -2

Signed-off-by: Xiaoming Ni <nixiaoming@huawei.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-11-15 14:54:05 +01:00
Louis Sautier 707a7ef4c7 pkill: add -e to display the name and PID of the process being killed
This mimics the behaviour of pkill -e / --echo from procps.

function                                             old     new   delta
.rodata                                           105179  105200     +21
packed_usage                                       34523   34516      -7
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 21/-7)              Total: 14 bytes

Signed-off-by: Louis Sautier <sautier.louis@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-10-14 14:33:34 +02:00
Denys Vlasenko c8c1fcdba1 tls: move definitions around, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-09-08 16:56:54 +02:00
Denys Vlasenko 9bab580cd4 tls: include signature_algorithms extension in client hello message
function                                             old     new   delta
tls_xread_record                                     629     645     +16
.rodata                                           105167  105179     +12
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 28/0)               Total: 28 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-09-08 16:31:44 +02:00
Ludwig Nussel 526625bc83 libbb: mark stack in assembly files read-only
Signed-off-by: Ludwig Nussel <ludwig.nussel@suse.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-08-30 17:21:53 +02:00
Denys Vlasenko dd79e1d4d3 fix [ --help ] and [[ --help ]]
function                                             old     new   delta
show_usage_if_dash_dash_help                          72      79      +7

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-08-30 17:12:34 +02:00
Denys Vlasenko fe73c8d557 *: style fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-08-30 16:41:17 +02:00
Shawn Landden 58598eb709 ash: optional sleep builtin
function                                             old     new   delta
sleepcmd                                               -      10     +10
builtintab                                           352     360      +8
.rodata                                           105264  105271      +7
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 2/0 up/down: 25/0)               Total: 25 bytes

Signed-off-by: Shawn Landden <shawnlandden@tutanota.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-08-27 19:56:21 +02:00
Aaro Koskinen d432049f28 devmem: add 128-bit width
Add 128-bit width if the compiler provides the needed type.

function                                             old     new   delta
devmem_main                                          405     464     +59
.rodata                                           109025  109043     +18
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 77/0)               Total: 77 bytes

Signed-off-by: Aaro Koskinen <aaro.koskinen@nokia.com>
Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-08-26 17:09:47 +02:00
Denys Vlasenko 1a1220a5b0 tree: unicode tweak (use normal space char, 0x20)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-08-26 14:54:45 +02:00
Denys Vlasenko b30d345cfd tree: make it unicode-aware
function                                             old     new   delta
tree_print                                           396     420     +24
.rodata                                           105251  105266     +15
tree_main                                             86      91      +5
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 44/0)               Total: 44 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-08-26 14:41:42 +02:00
Denys Vlasenko 5eceafb1f8 xxd -r: handle offsets
function                                             old     new   delta
xxd_main                                            1076    1439    +363
.rodata                                           105239  105251     +12
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 375/0)             Total: 375 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-08-22 17:28:43 +02:00
Denys Vlasenko 0011a6bc20 xxd: add two more testcases
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-08-22 15:57:57 +02:00
Denys Vlasenko f318adaaab xxd -r: without -p, stop at more than one whitespace, closes 14786
function                                             old     new   delta
xxd_main                                             888    1076    +188

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-08-22 15:40:47 +02:00
Ron Yorston 5a9d2b6e02 libbb: make '--help' handling more consistent
Running an applet with '--help' as its only argument is treated
as a special case.  If additional arguments follow '--help' the
behaviour is inconsistent:

- applets which call single_argv() print help and do nothing else;

- applets which call getopt() report "unrecognized option '--help'"
  and print help anyway;

- expr says "expr: syntax error" and doesn't print help;

- printenv silently ignores '--help', prints any other variables
  and doesn't print help;

- realpath says "--help: No such file or directory", prints the path
  of any other files and doesn't print help.

If the first argument is '--help' ignore any other arguments and print
help.  This is more consistent and most likely what the user wanted.

See also commit 6bdfbc4cb (libbb: fix '--help' handling in
FEATURE_SH_NOFORK=y).

function                                             old     new   delta
show_usage_if_dash_dash_help                          75      69      -6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-6)               Total: -6 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-08-22 14:05:01 +02:00
Denys Vlasenko 41d5f800a1 bc: hopefully fix bug 14956 (use-after-free)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-08-18 16:23:55 +02:00
Sören Tempel 7c2a3bdde0 ash: fix use-after-free in bash pattern substitution
function                                             old     new   delta
subevalvar                                          1566    1564      -2

Signed-off-by: Sören Tempel <soeren@soeren-tempel.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-08-02 18:27:41 +02:00
Denys Vlasenko 84b89b4c22 udhcpc6: downgrade "opening listen socket" log level to 2
This matches udhcpc for IPv4.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-08-02 18:04:51 +02:00
Denys Vlasenko 75aaa8b311 udhcpc6: fix sending of renew messages
function                                             old     new   delta
d6_listen_socket                                       -     150    +150

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-08-02 15:33:51 +02:00
Grob Grobmann 3147552a23 vi: add 'ZQ' quitting command
Busybox vi provides the 'ZZ' command to save and close
the similar 'ZQ' command just exits without saving.

function                                             old     new   delta
do_cmd                                              4222    4244     +22

Signed-off-by: Grob Grobmann <grobgrobmann@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-08-02 15:05:12 +02:00
Henrique Rodrigues 9eddf164bf ping: fix typo in --help text
Signed-off-by: Henrique Rodrigues <henrique.rodrigues@ist.utl.pt>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-08-02 14:34:38 +02:00
Denys Vlasenko daa66ed62c ash: fix use-after-free in pattern substituon code
Patch by soeren@soeren-tempel.net

The idx variable points to a value in the stack string (as managed
by STPUTC). STPUTC may resize this stack string via realloc(3). If
this happens, the idx pointer needs to be updated. Otherwise,
dereferencing idx may result in a use-after free.

function                                             old     new   delta
subevalvar                                          1562    1566      +4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-08-02 12:41:18 +02:00
Denys Vlasenko 1c54552842 ash: fix ifs cleanup on error paths
Patch by Alex Gorinson <algore3698@gmail.com>

function                                             old     new   delta
evalvar                                              477     495     +18
varvalue                                             603     618     +15
subevalvar                                          1557    1572     +15
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 48/0)               Total: 48 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-08-02 11:18:11 +02:00
Denys Vlasenko 5479c435fd sort: fix sort -s -u, closes 14871
function                                             old     new   delta
sort_main                                            851     856      +5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-07-29 16:40:00 +02:00
Denys Vlasenko 00f2a35b83 sort: fix -k2M (wasn't skipping leading whitespace)
function                                             old     new   delta
compare_keys                                         848     862     +14

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-07-29 16:05:50 +02:00
Denys Vlasenko 9b6eb2a8ef udhcpc6: add missed big-endian conversions
function                                             old     new   delta
option_to_env                                        686     694      +8

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-07-13 16:15:04 +02:00
Denys Vlasenko 7b969bb2ad tls: P256: remove NOP macro sp_256_norm_8()
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-07-13 16:11:17 +02:00
Natanael Copa e63d7cdfda awk: fix use after free (CVE-2022-30065)
fixes https://bugs.busybox.net/show_bug.cgi?id=14781

function                                             old     new   delta
evaluate                                            3343    3357     +14

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-07-11 17:18:07 +02:00
Denys Vlasenko 3ad3aa6441 shaNNNsum: accept one-space "HASH FILENAME" format for -c, closes 14866
function                                             old     new   delta
md5_sha1_sum_main                                    496     501      +5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-07-11 14:36:39 +02:00
Ron Yorston 298ac9507b lineedit: get PWD from ash
The line editing code and ash disagree when the current directory
is changed to a symbolic link:

   ~ $ mkdir real
   ~ $ ln -s real link
   ~ $ cd link
   ~/real $ pwd
   /home/rmyf36/link

Note the prompt says we're in ~/real.  Bash does:

   [rmy@random ~]$ cd link
   [rmy@random link]$ pwd
   /home/rmyf36/link

Ash uses the name supplied by the user while the line editing code
calls getcwd(3).  The discrepancy can be avoided by fetching the
value of PWD from ash.

Hush calls getcwd(3) when the directory is changed
so there's no disagreement with the line editing code.

There is no standard how shells should handle cd'ing into
symlinks.

function                                             old     new   delta
parse_and_put_prompt                                 838     869     +31

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-07-03 21:41:38 +02:00
Roger Knecht 20a4f70eca tree: new applet
Adds the tree program to list directories and files in a tree structure.

function                                             old     new   delta
tree_print                                             -     343    +343
scandir64                                              -     330    +330
scandir                                                -     330    +330
tree_main                                              -      86     +86
.rodata                                           105150  105228     +78
packed_usage                                       34511   34557     +46
alphasort64                                            -      31     +31
alphasort                                              -      31     +31
strcoll                                                -       5      +5
applet_names                                        2801    2806      +5
applet_main                                         1616    1620      +4
applet_suid                                          101     102      +1
applet_install_loc                                   202     203      +1
------------------------------------------------------------------------------
(add/remove: 11/0 grow/shrink: 6/0 up/down: 1291/0)          Total: 1291 bytes

Signed-off-by: Roger Knecht <rknecht@pm.me>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-06-30 17:18:12 +02:00
Ron Yorston 2617a5e4c6 vi: handle autoindent in 'cc' command
When the 'cc' command is invoked with autoindent enabled it
should use the indent of the first line being changed.

The size of the indent has to be established before char_insert()
is called as the lines being changed are deleted.  Introduce a
new global variable, newindent, to handle this.  The indentcol
global is now effectively a static variable in char_insert().

function                                             old     new   delta
do_cmd                                              4247    4308     +61
vi_main                                              416     422      +6
char_insert                                          891     875     -16
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 67/-16)             Total: 51 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-06-26 19:38:31 +02:00
Ron Yorston af3b585815 vi: fix regression in autoindent handling
Suppose autoindent is enabled and we have a line with an initial
tab where we want to split the words onto separate lines:

	split the words

One way to do this is with the sequence 'f r<CR>;r<CR>', but in
BusyBox vi the result is:

	split

	he
words

This is a regression introduced by commit 9659a8db1 (vi: remove
autoindent from otherwise empty lines).  The amount of indentation
is being recorded when the 'r' command inserts a newline but
isn't subsequently reset.  A fix is to only record the indent
when in insert or replace mode.  Proper handling of the 'o' and
'O' commands then requires them to switch to insert mode before
calling char_insert() to insert a newline.

function                                             old     new   delta
char_insert                                          884     891      +7
do_cmd                                              4243    4247      +4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 11/0)               Total: 11 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-06-26 19:38:28 +02:00
Ron Yorston 7d1c7d8337 ash,hush: use HOME for tab completion and prompts
ash and hush correctly use the value of HOME for tilde expansion.
However the line editing code in libbb obtains the user's home
directory by calling getpwuid().  Thus tildes in tab completion
and prompts may be interpreted differently than in tilde expansion.

When the line editing code is invoked from a shell make it use the
shell's interpretation of tilde.  This is similar to how GNU readline
and bash collaborate.

function                                             old     new   delta
get_homedir_or_NULL                                   29      72     +43
optschanged                                          119     126      +7
hush_main                                           1204    1211      +7
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 57/0)               Total: 57 bytes

v2: Always check for HOME before trying the password database:  this
    is what GNU readline does.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-06-26 18:05:50 +02:00
Ron Yorston 95fec31be6 libbb: restore special handling of nomsg errors
The functions bb_perror_nomsg() and bb_perror_nomsg_and_die() are
used to print error messages where no specific information is
available.  For example:

   $ busybox mktemp -p /
   mktemp: (null): Permission denied

mktemp(3) doesn't tell us the name of the file it tried to create.

However, printing '(null)' is a regression introduced by commit
6937487be (libbb: reduce the overhead of single parameter bb_error_msg()
calls).  Restore the previous behaviour by reverting the changes to
the two functions mentioned:

   $ busybox mktemp -p /
   mktemp: Permission denied

function                                             old     new   delta
bb_perror_nomsg_and_die                                7      14      +7
bb_perror_nomsg                                        7      14      +7
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 14/0)               Total: 14 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-06-26 17:17:02 +02:00
Denys Vlasenko 8d67007a4d top: improve large PID display in memory ('s') mode
function                                             old     new   delta
display_topmem_process_list                          530     564     +34

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-05-12 11:44:47 +02:00
Denys Vlasenko b9c2108b26 examples/var_service/dhcp_if: make helper scripts more talkative
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-05-12 11:07:12 +02:00
Denys Vlasenko 1099a27696 top: code shrink
function                                             old     new   delta
display_process_list                                1186    1168     -18

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-05-10 14:04:34 +02:00
Denys Vlasenko 69f82e305b top: code shrink
function                                             old     new   delta
display_process_list                                1191    1186      -5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-05-10 13:51:09 +02:00
Denys Vlasenko 294881d2e9 top: fix display of large PID/PPID
function                                             old     new   delta
display_process_list                                1077    1191    +114
.rodata                                           104803  104807      +4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 118/0)             Total: 118 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-05-10 12:56:28 +02:00
Denys Vlasenko 67fd6be0bb seedrng: do not hash in a constant string, it's not adding entropy
function                                             old     new   delta
seedrng_main                                         906     880     -26
.rodata                                           104899  104873     -26
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-52)             Total: -52 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-05-03 12:48:50 +02:00
Denys Vlasenko 3bfbcb5807 seedrng: restore error check on fsync
Or else security people will never stop nagging us.

function                                             old     new   delta
seedrng_main                                         884     906     +22

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-05-02 15:03:32 +02:00
Denys Vlasenko 5ba56e8b95 seedrng: it's not a part of util-linux, move to miscutils
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-05-02 14:53:14 +02:00
Denys Vlasenko 1a290f889c init: do not set HOME
function                                             old     new   delta
.rodata                                           104906  104899      -7
init_main                                            786     776     -10
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-17)             Total: -17 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-05-02 14:47:53 +02:00
David Leonard 4642cf5b38 tsort: new applet
function                                             old     new   delta
tsort_main                                             -     578    +578
.rodata                                           104884  104906     +22
applet_names                                        2759    2765      +6
applet_main                                         1596    1600      +4
packed_usage                                       34290   34288      -2
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 3/1 up/down: 610/-2)            Total: 608 bytes

Signed-off-by: David Leonard <d+busybox@adaptive-enterprises.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-05-02 14:25:36 +02:00
Paul Fox 52a7bf6fa6 crond: implement support for setting PATH in crontab files
It's very inconvenient for a cron user not to be able to set a
"personal" PATH for their cron jobs, as is possible with other crons

function                                             old     new   delta
load_crontab                                         868     942     +74
.rodata                                           104878  104884      +6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 80/0)               Total: 80 bytes

Signed-off-by: Paul Fox <pgf@foxharp.boston.ma.us>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-05-02 12:28:48 +02:00
Denys Vlasenko 9b6f44e040 style fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-05-01 17:06:00 +02:00
Bernhard Reutner-Fischer a157c4c978 seedrng: manually inline seed_rng
We can now remove a separate buffer

function                                             old     new   delta
seedrng_main                                         930     884     -46

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-05-01 17:02:20 +02:00
Denys Vlasenko 54867fec12 seedrng: shorten --help, assorted small cleanups
function                                             old     new   delta
packed_usage                                       34295   34290      -5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-05-01 16:51:06 +02:00
Denys Vlasenko b5624be6df seedrng: reduce MAX_SEED_LEN from 512 to 256
As proposed by Jason.
getrandom() is more likely to block on reads larger than this.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-05-01 16:37:39 +02:00
Denys Vlasenko 7471658038 seedrng: do not hash lengths, they are very predictable
function                                             old     new   delta
seedrng_main                                         982     930     -52

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-05-01 02:06:20 +02:00
Denys Vlasenko fb4546c7af seedrng: code shrink
function                                             old     new   delta
seedrng_main                                         994     982     -12

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-05-01 01:58:57 +02:00
Denys Vlasenko d5bd2e57a7 seedrng: explain why we need locking and fsync'ing
Also, do not test for locking errors: on Linux, they do not happen.

function                                             old     new   delta
.rodata                                           104900  104878     -22
seedrng_main                                        1022     994     -28

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-05-01 01:50:44 +02:00
Denys Vlasenko 0bca489b24 seedrng: remove redundant assignment
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-04-30 23:53:28 +02:00
Denys Vlasenko 4648754119 seedrng: re-add fsync after unlink, and explain its purpose
function                                             old     new   delta
seedrng_main                                        1003    1022     +19

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-04-30 23:17:58 +02:00
Denys Vlasenko 267178c628 seedrng: include fiel/dir names in error messages
function                                             old     new   delta
.rodata                                           104898  104900      +2
seedrng_main                                        1011    1003      -8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 2/-8)               Total: -6 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-04-30 15:50:45 +02:00
Denys Vlasenko d49da38aa3 seedrng: use more xfuncs where appropriate
function                                             old     new   delta
.rodata                                           104929  104898     -31
seedrng_main                                        1050    1011     -39

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-04-30 15:45:53 +02:00
Denys Vlasenko 2cbfd01c15 seedrng: code shrink
Struct initializers do this double init:
># util-linux/seedrng.c:88:              struct pollfd random_fd = {
        movl    $0, 132(%esp)   #, random_fd
        movl    $0, 136(%esp)   #, random_fd
...
># util-linux/seedrng.c:88:              struct pollfd random_fd = {
        movl    %eax, 140(%esp) # _110, random_fd.fd
        movw    $1, 144(%esp)   #, random_fd.events

and close(random_fd.fd) needs to pull the item from the stack:
        pushl   132(%esp)       # random_fd.fd
        call    close   #

function                                             old     new   delta
seedrng_main                                        1076    1050     -26

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-04-30 15:38:44 +02:00
Denys Vlasenko 52f3cf7e5f seedrng: simplify read_new_seed() to not have error return
gcc in fact detects this and does this transformation
when generating code - no object code changes.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-04-30 15:33:28 +02:00
Denys Vlasenko 282b61a649 seedrng: prepare read_new_seed() to not need a "success" retval
We do not expect /dev/[u]random to be not openable/readable.
If they are, just bail out (something is obviously very wrong).

function                                             old     new   delta
seedrng_main                                        1077    1076      -1
.rodata                                           104939  104929     -10

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-04-30 15:25:55 +02:00
Denys Vlasenko 0fa16fc7a2 seedrng: do not try to continue on unexpected errors (just exit)
function                                             old     new   delta
.rodata                                           104946  104938      -8
seedrng_main                                        1225    1077    -148
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-156)           Total: -156 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-04-30 15:17:32 +02:00
Denys Vlasenko 002d6ee46d ifplugd: split -a into -a and -A, latter disables upping in iface creation
-a meant both "don't up iface before each link detection" and "don't up iface
when it newly appears". But they are not the same.

I have a dock station where eth1 appears when I attach the notebook to it
(looks like it's hanging off a USB bus). IOW: appearance of this interface
is functionally equivalent to attaching ethernet cable.
ifplugd meant to be able to *automatically* handle this case.
Currently, with -a, it couldn't: newly appearing iface stayed down,
user had to manually up it.

function                                             old     new   delta
packed_usage                                       34253   34296     +43
.rodata                                           104876  104877      +1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 44/0)               Total: 44 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-04-30 14:33:14 +02:00
Denys Vlasenko 8456c21c09 seedrng: chdir to the SEED_DIRECTORY - avoid concat_path_file's
function                                             old     new   delta
seedrng_main                                        1273    1225     -48

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-04-27 17:53:12 +02:00
Denys Vlasenko c82a0cd2b0 seedrng: shorten strings
function                                             old     new   delta
.rodata                                           104894  104876     -18

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-04-27 17:33:15 +02:00
Denys Vlasenko 401356511c seedrng: remove unnecessary zero-filling of local variables
function                                             old     new   delta
seedrng_main                                        1292    1273     -19

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-04-27 17:20:43 +02:00
Denys Vlasenko 6da9947358 seedrng: remove unnecessary zero-filling of local variables
function                                             old     new   delta
seedrng_main                                        1323    1292     -31

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-04-27 17:09:38 +02:00
Denys Vlasenko 137b205722 seedrng: shrink --help text
function                                             old     new   delta
packed_usage                                       34280   34253     -27

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-04-27 16:54:18 +02:00
Denys Vlasenko 0cdd6f5792 libbb: fix fallout from nth_string() robustification, closes 14726
function                                             old     new   delta
parse_common                                         187     228     +41

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-04-27 15:33:55 +02:00
Bernhard Reutner-Fischer 7fbfb2050f kbuild: Prefer -Oz over -Os
-Oz Optimize aggressively for size rather than speed.

with gcc-12 so far (i think only https://gcc.gnu.org/PR32803 and 103773 )
"shorter load imm on x86_64":
(add/remove: 0/0 grow/shrink: 4/1670 up/down: 6/-13196)    Total: -13190 bytes
   text	   data	    bss	    dec	    hex	filename
 975753	   4227	   1816	 981796	  efb24	busybox_old
 962442	   4227	   1816	 968485	  ec725	busybox_unstripped

with clang-15:
(add/remove: 394/34 grow/shrink: 161/1856 up/down: 18644/-98946)Total: -80302 bytes
   text	   data	    bss	    dec	    hex	filename
1120994	  16066	   1696	1138756	 116044	busybox_old
1040689	  16026	   1696	1058411	 10266b	busybox_unstripped

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2022-04-24 19:18:57 +02:00
Jason A. Donenfeld 05c366a560 seedrng: prune header includes
Remove redundant includes.
We have platform specific handling in libbb.h and platform.h so we can
handle quirks in a central place.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2022-04-24 10:03:59 +02:00
Jason A. Donenfeld f9ea8ba5ed seedrng: code-golf even smaller
Since we're passing 0 as the timeout, we don't need safe_poll. Remove
cleanup at end of program, since OS does that, which lets us simplify
control flow. Factor repeated function calls into ternary loop.

function                                             old     new   delta
seedrng_main                                        1061    1459    +398
seed_from_file_if_exists                             468       -    -468
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/0 up/down: 398/-468)          Total: -70 bytes
   text    data     bss     dec     hex filename
1052781   16515    1816 1071112  105808 busybox_old
1052711   16515    1816 1071042  1057c2 busybox_unstripped

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2022-04-24 10:01:07 +02:00
Bernhard Reutner-Fischer 831c754c91 kbuild: fix building sha256
Pass down the correct EXTRA_CFLAGS to the compiler driver when building
assembler source.
Otherwise building busybox for a multilib other than the default failed
to link since hash_md5_sha256_x86-64_shaNI.o and
hash_md5_sha_x86-64_shaNI.o were built for the default arch which might
not what we requested in the EXTRA_CFLAGS.

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2022-04-21 13:37:10 +02:00
Ron Yorston c93eb1a95b vi: fix backspace over tab in commands
Colon and search commands are entered on the status line.  Since
the cursor position wasn't being tracked backspacing over a tab
resulted in a mismatch between the actual and apparent content
of the command.

function                                             old     new   delta
get_input_line                                       178     180      +2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 2/0)                 Total: 2 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2022-04-20 16:06:04 +02:00
Jason A. Donenfeld 57fea029cc seedrng: compress format strings with %s arguments
- Avoid an xstrdup call with seed_dir.
- Compress format strings with %s arguments.
- Open /dev/urandom for add entropy ioctl rather than /dev/random, so that
  /dev/random is only used for the already-sightly-flawed poll() check for
  creditability.

function                                             old     new   delta
seedrng_main                                         948     958     +10
seed_from_file_if_exists                             410     417      +7
.rodata                                           108338  108206    -132
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 17/-132)          Total: -115 bytes
   text	   data	    bss	    dec	    hex	filename
 975829	   4227	   1816	 981872	  efb70	busybox_old
 975714	   4227	   1816	 981757	  efafd	busybox_unstripped

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2022-04-20 15:43:04 +02:00
Jason A. Donenfeld 3cb40f89de seedrng: avoid needless runtime strlen() call
- Avoid needless runtime strlen() call, bloating binary.
- Replace failed seed string with series of nulls.

function                                             old     new   delta
.rodata                                           108350  108338     -12
static.seedrng_prefix                                 26       -     -26
seedrng_main                                        1000     948     -52
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 0/2 up/down: 0/-90)             Total: -90 bytes
   text	   data	    bss	    dec	    hex	filename
 975919	   4227	   1816	 981962	  efbca	busybox_old
 975829	   4227	   1816	 981872	  efb70	busybox_unstripped

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2022-04-20 15:43:00 +02:00
Jason A. Donenfeld ce9a345632 seedrng: use predefined strings where possible
- Use predefined strings where possible.
- Open /dev/random with O_RDONLY for ioctl().

function                                             old     new   delta
seed_from_file_if_exists                             413     410      -3
.rodata                                           108407  108350     -57
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-60)             Total: -60 bytes
   text	   data	    bss	    dec	    hex	filename
 975979	   4227	   1816	 982022	  efc06	busybox_old
 975919	   4227	   1816	 981962	  efbca	busybox_unstripped

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2022-04-20 15:43:00 +02:00
Jason A. Donenfeld 398bb3861a seedrng: further reduce size
- Remove all games with errno to further reduce code size.
- Combine error messages that don't benefit from being separated.
- Lock directory fd instead of separate file.

function                                             old     new   delta
static.longopts                                       38      26     -12
seed_from_file_if_exists                             426     413     -13
packed_usage                                       34519   34480     -39
.rodata                                           108484  108407     -77
seedrng_main                                        1088    1000     -88
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/5 up/down: 0/-229)           Total: -229 bytes
   text	   data	    bss	    dec	    hex	filename
 976208	   4227	   1816	 982251	  efceb	busybox_old
 975979	   4227	   1816	 982022	  efc06	busybox_unstripped

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2022-04-20 15:43:00 +02:00
Jason A. Donenfeld 3c60711f83 seedrng: remove some global variables
- Remove global variables and pass dfd by value, opened once instead of
  twice, which shaves off some more bytes.

function                                             old     new   delta
seedrng_main                                        1086    1088      +2
seed_dir                                               8       -      -8
non_creditable_seed                                    8       -      -8
lock_file                                              8       -      -8
creditable_seed                                        8       -      -8
seed_from_file_if_exists                             456     426     -30
------------------------------------------------------------------------------
(add/remove: 0/4 grow/shrink: 1/1 up/down: 2/-62)             Total: -60 bytes
   text	   data	    bss	    dec	    hex	filename
 976236	   4227	   1848	 982311	  efd27	busybox_old
 976208	   4227	   1816	 982251	  efceb	busybox_unstripped

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2022-04-20 15:43:00 +02:00
Jason A. Donenfeld 31ec481baf seedrng: hoist bb_strtoul out of min/max
- Hoist bb_strtoul out of min/max to prevent quadruple evaluation.
- Don't use separate variables for boottime/realtime.
- Make use of ENABLE_FEATURE_CLEAN_UP where appropriate.
- Order hash initialization after lock taking per Bernhard's taste.
- Add comment description of theory of operation.

function                                             old     new   delta
seed_from_file_if_exists                             533     456     -77
seedrng_main                                        1218    1086    -132
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-209)           Total: -209 bytes
   text	   data	    bss	    dec	    hex	filename
 976445	   4227	   1848	 982520	  efdf8	busybox_old
 976236	   4227	   1848	 982311	  efd27	busybox_unstripped

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2022-04-20 15:42:53 +02:00
Jason A. Donenfeld 4538578996 seedrng: use libbb functions
- Make extensive use of libbb.h functions, which simplify a lot of code
  and reduce binary size considerably.
- Use the already existing PID_FILE_PATH variable.

function                                             old     new   delta
seed_from_file_if_exists                             697     533    -164
.rodata                                           108665  108484    -181
seedrng_main                                        1463    1218    -245
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-590)           Total: -590 bytes
   text	   data	    bss	    dec	    hex	filename
 977035	   4227	   1848	 983110	  f0046	busybox_old
 976445	   4227	   1848	 982520	  efdf8	busybox_unstripped

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2022-04-20 15:22:55 +02:00
Jason A. Donenfeld 4b407bacd4 seedrng: import SeedRNG utility for kernel RNG seed files
The RNG can't actually be seeded from a shell script, due to the
reliance on ioctls and the fact that entropy written into the
unprivileged /dev/urandom device is not immediately mixed in, making
subsequent seed reads dangerous. For this reason, the seedrng project
provides a basic "C script" meant to be copy and pasted into projects
like Busybox and tweaked as needed: <https://git.zx2c4.com/seedrng/about/>.

The SeedRNG construction has been part of systemd's seeder since
January, and recently was added to Android, OpenRC, and Void's Runit,
with more integrations on their way depending on context. Virtually
every single Busybox-based distro I have seen seeds things in wrong,
incomplete, or otherwise dangerous way. For example, fixing this issue
in Buildroot requires first for Busybox to have this fix.

This commit imports it into Busybox and wires up the basic config. The
utility itself is tiny, and unlike the example code from the SeedRNG
project, we can re-use libbb's existing hash functions, rather than
having to ship a standalone BLAKE2s, which makes this even smaller.

function                                             old     new   delta
seedrng_main                                           -    1463   +1463
.rodata                                           107858  108665    +807
seed_from_file_if_exists                               -     697    +697
packed_usage                                       34414   34519    +105
static.longopts                                        -      38     +38
static.seedrng_prefix                                  -      26     +26
seed_dir                                               -       8      +8
non_creditable_seed                                    -       8      +8
lock_file                                              -       8      +8
creditable_seed                                        -       8      +8
applet_names                                        2747    2755      +8
applet_main                                         3192    3200      +8
------------------------------------------------------------------------------
(add/remove: 9/0 grow/shrink: 4/0 up/down: 3184/0)           Total: 3184 bytes
   text	   data	    bss	    dec	    hex	filename
 973776	   4219	   1816	 979811	  ef363	busybox_old
 977035	   4227	   1848	 983110	  f0046	busybox_unstripped

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2022-04-20 15:20:29 +02:00
Ron Yorston fc7868602e vi: improved handling of backspace in replace mode
In replace mode ('R' command) the backspace character should get
special treatment:

- backspace only goes back to the start of the replacement;
- backspacing over replaced characters restores the original text.

Prior to this commit BusyBox vi deleted the characters both before
and after the cursor in replace mode.

function                                             old     new   delta
undo_pop                                               -     235    +235
char_insert                                          858     884     +26
indicate_error                                        81      84      +3
find_range                                           654     657      +3
static.text_yank                                      77      79      +2
do_cmd                                              4486    4243    -243
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 4/1 up/down: 269/-243)           Total: 26 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-03-04 22:57:05 +01:00
Denys Vlasenko 55f969a006 taskset: fix printf format mismatch in !FEATURE_TASKSET_FANCY config. closes 14616
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-03-01 10:49:17 +01:00
Denys Vlasenko 5fe20cf321 ash: do not truncate failed tilde expansion on unknown user names
Do not skip over "*p = c;" statement.

Testcase: echo ~~nouser/qwe

function                                             old     new   delta
argstr                                              1396    1406     +10

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-03-01 10:10:22 +01:00
Denys Vlasenko 7750b5a25a ash: fix unsafe use of mempcpy
function                                             old     new   delta
subevalvar                                          1549    1557      +8

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-03-01 09:56:54 +01:00
Sören Tempel fa52ac9781 ash: don't read past end of var in subvareval for bash substitutions
Without this patch, BusyBox handles bash pattern substitutions without
a terminating '/' character incorrectly.

Consider the following shell script:

	_bootstrapver=5.0.211-r0
	_referencesdir="/usr/${_bootstrapver/-*}/Sources"
	echo $_referencesdir

This should output `/usr/5.0.211/Sources`. However, without this patch
it instead outputs `/usr/5.0.211Sources`. This is due to the fact that
BusyBox expects the bash pattern substitutions to always be terminated
with a '/' (at least in this part of subvareval) and thus reads passed
the substitution itself and consumes the '/' character which is part of
the literal string. If there is no '/' after the substitution then
BusyBox might perform an out-of-bounds read under certain circumstances.

When replacing the bash pattern substitution with `${_bootstrapver/-*/}`,
or with this patch applied, ash outputs the correct value.

Signed-off-by: Sören Tempel <soeren@soeren-tempel.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-03-01 08:47:43 +01:00
Denys Vlasenko 1891fdda59 libbb/sha1: update config help text with new performance numbers
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-02-18 17:09:51 +01:00
Denys Vlasenko c2e7780e52 libbb/sha256: explicitly use sha256rnds2's %xmm0 (MSG) argument
Else, the code seemingly does not use MSG.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-02-12 00:52:12 +01:00
Denys Vlasenko 1f272c06d0 whitespace fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-02-11 23:03:27 +01:00
Denys Vlasenko dda77e8376 libbb/sha1: revert last commit: pshufb is a SSSE3 insn, can't use it
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-02-11 14:53:26 +01:00
Denys Vlasenko 8154146be4 libbb/sha1: shrink unrolled x86-64 code
function                                             old     new   delta
sha1_process_block64                                3481    3384     -97

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-02-11 06:08:27 +01:00
Denys Vlasenko 6f56fa1713 libbb/sha: improve comments
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-02-10 15:38:10 +01:00
Denys Vlasenko 6a6c1c0ea9 whitespace fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-02-09 11:29:23 +01:00
Denys Vlasenko caa9c4f707 libbb/sha256: code shrink in x86 assembly
function                                             old     new   delta
sha256_process_block64_shaNI 32-bit                  676     673      -3
sha256_process_block64_shaNI 64-bit                  680     677      -3

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-02-09 01:50:22 +01:00
Denys Vlasenko 11bcea7ac0 libbb/sha256: code shrink in 64-bit x86
function                                             old     new   delta
sha256_process_block64_shaNI                         701     680     -21

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-02-09 01:42:49 +01:00
Denys Vlasenko 461a994b09 libbb/sha256: code shrink in 32-bit x86
function                                             old     new   delta
sha256_process_block64_shaNI                         697     676     -21

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-02-09 01:30:23 +01:00
Denys Vlasenko c0ff0d4528 libbb/sha256: code shrink in 32-bit x86
function                                             old     new   delta
sha256_process_block64_shaNI                         713     697     -16

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-02-09 00:33:39 +01:00
Denys Vlasenko eb8d5f3b8f libbb/sha1: shrink x86 hardware accelerated hashing (32-bit)
function                                             old     new   delta
sha1_process_block64_shaNI                           511     507      -4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-02-08 15:34:02 +01:00
Denys Vlasenko eb52e7fa52 libbb/sha1: shrink x86 hardware accelerated hashing (32-bit)
function                                             old     new   delta
sha1_process_block64_shaNI                           517     511      -6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-02-08 15:23:26 +01:00
Denys Vlasenko 71a1cccaad libbb/sha1: shrink x86 hardware accelerated hashing
function                                             old     new   delta
sha1_process_block64_shaNI 32-bit                    524     517      -7
sha1_process_block64_shaNI 64-bit                    510     508      -2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-02-08 08:22:17 +01:00
Denys Vlasenko 4923f74e58 libbb/sha1: shrink unrolled x86-64 code
function                                             old     new   delta
sha1_process_block64                                3482    3481      -1
.rodata                                           108460  108412     -48
------------------------------------------------------------------------------
(add/remove: 1/4 grow/shrink: 0/2 up/down: 0/-49)             Total: -49 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-02-08 03:29:16 +01:00
Denys Vlasenko c193cbd6df libbb/sha1: shrink and speed up unrolled x86-64 code
function                                             old     new   delta
sha1_process_block64                                3514    3482     -32

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-02-07 02:34:04 +01:00
Denys Vlasenko 987be932ed *: slap on a few ALIGN_PTR where appropriate
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-02-06 20:07:12 +01:00
Denys Vlasenko ca466f385a *: slap on a few ALIGN* where appropriate
The result of looking at "grep -F -B2 '*fill*' busybox_unstripped.map"

function                                             old     new   delta
.rodata                                           108586  108460    -126
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-126)           Total: -126 bytes
   text	   data	    bss	    dec	    hex	filename
 970412	   4219	   1848	 976479	  ee65f	busybox_old
 970286	   4219	   1848	 976353	  ee5e1	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-02-06 19:53:10 +01:00
Denys Vlasenko 4f40735c87 libbb/sha256: code shrink in 32-bit x86
function                                             old     new   delta
sha256_process_block64_shaNI                         722     713      -9

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-02-06 00:56:13 +01:00
Denys Vlasenko 31c1c31077 libbb/sha256: code shrink in 64-bit x86
function                                             old     new   delta
sha256_process_block64_shaNI                         706     701      -5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-02-06 00:33:42 +01:00
Denys Vlasenko a1429fbb8c libbb/sha256: code shrink in 64-bit x86
function                                             old     new   delta
sha256_process_block64_shaNI                         730     706     -24

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-02-03 15:17:42 +01:00
Denys Vlasenko de6cb4bed8 libbb/sha256: code shrink in 32-bit x86
function                                             old     new   delta
sha256_process_block64_shaNI                         747     722     -25

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-02-03 15:11:23 +01:00
Denys Vlasenko 6472ac9428 libbb/sha256: optional x86 hardware accelerated hashing
64 bit:
function                                             old     new   delta
sha256_process_block64_shaNI                           -     730    +730
.rodata                                           108314  108586    +272
sha256_begin                                          31      83     +52
------------------------------------------------------------------------------
(add/remove: 5/1 grow/shrink: 2/0 up/down: 1055/-1)          Total: 1054 bytes

32 bit:
function                                             old     new   delta
sha256_process_block64_shaNI                           -     747    +747
.rodata                                           104318  104590    +272
sha256_begin                                          29      84     +55
------------------------------------------------------------------------------
(add/remove: 5/1 grow/shrink: 2/0 up/down: 1075/-1)          Total: 1074 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-02-03 14:58:02 +01:00
Denys Vlasenko 205042c07a libbb/sha1: in unrolled x86-64 code, pass initial W[] in registers, not on stack
This can be faster on some CPUs.
On Skylake, evidently load latency from L1 (or store-to-load
forwarding in LSU) is fast enough to completely hide
memory reference latencies here.

function                                             old     new   delta
sha1_process_block64                                3495    3514     +19

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-25 17:21:45 +01:00
Denys Vlasenko 99e22d230d cut: build fix for FEATURE_CUT_REGEX
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-24 07:07:17 +01:00
Khem Raj 117a8c9b7a apply const trick to ptr_to_globals
This was missing in the previous attempt to fix it via [1]

This helps fix segfaults when compiling with clang ( seen on riscv64 )

[  452.428349] less[270]: unhandled signal 11 code 0x1 at 0x000000000000000c in busybox.nosuid[2ab7491000+ba000]
[  452.430246] CPU: 3 PID: 270 Comm: less Not tainted 5.15.13-yocto-standard #1
[  452.431323] Hardware name: riscv-virtio,qemu (DT)
[  452.431925] epc : 0000002ab74a19ee ra : 0000002ab74a19dc sp : 0000003fec6ec980
[  452.432725]  gp : 0000002ab754dcb0 tp : 0000003f88783800 t0 : 0000003f8878d4a0
[  452.433744]  t1 : 0000002ab749b00c t2 : 0000000000000000 s0 : 0000003fec6ecc38
[  452.434732]  s1 : 000000000000004c a0 : 00000000ffffffff a1 : 0000002ab754dde0
[  452.435861]  a2 : 0000000000000000 a3 : 0000000000000100 a4 : 0000002ab754f3a0
[  452.436787]  a5 : 0000002ab754f3a0 a6 : 0000000000000000 a7 : 0000002ab754f2a0
[  452.437974]  s2 : 0000000000000002 s3 : 0000002ab754b6c8 s4 : 0000002ab749b60e
[  452.438781]  s5 : 0000000000000000 s6 : 0000002ab754b6c8 s7 : 0000003f88943060
[  452.439723]  s8 : 0000003f88944050 s9 : 0000002ad8502e88 s10: 0000002ad8502de8
[  452.440538]  s11: 0000000000000014 t3 : 0000003f887fceb6 t4 : 0000003f8893af0c
[  452.441438]  t5 : 0000000000000000 t6 : 0000003f88923000

[1] https://git.busybox.net/busybox/commit/?id=1f925038a

Signed-off-by: Khem Raj <raj.khem@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-23 23:13:44 +01:00
Timo Teräs 78fdf4d22d mkfs.vfat: fix volume label to be padded with space
The specification requires volume label to be space padded.

Latest fsck.vfat will remove the zero padded volume label
as invalid. See also:
https://github.com/dosfstools/dosfstools/issues/172

Make the default label also "NO NAME" which has the special meaning
that label is not set.

function                                             old     new   delta
mkfs_vfat_main                                      1470    1502     +32
static.NO_NAME_11                                      -      12     +12
.rodata                                           104309  104318      +9
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 2/0 up/down: 53/0)               Total: 53 bytes

Signed-off-by: Timo Teräs <timo.teras@iki.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-23 23:07:07 +01:00
Walter Lozano 6dd6a6c42d Add support for long options to cmp
In order to improve compatibility with GNU cmp add support for long
options to busybox cmp.

function                                             old     new   delta
static.cmp_longopts                                    -      36     +36
cmp_main                                             589     594      +5
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/0 up/down: 41/0)               Total: 41 bytes

Signed-off-by: Walter Lozano <walter.lozano@collabora.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-23 20:24:32 +01:00
Denys Vlasenko f12fb1e409 sed: fix handling of escaped delimiters in s/// replacement
function                                             old     new   delta
parse_regex_delim                                    111     140     +29

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-23 19:04:27 +01:00
Denys Vlasenko e998c7c032 sed: fix handling of escaped delimiters in s/// search pattern, closes 14541
function                                             old     new   delta
copy_parsing_escapes                                  67      96     +29
parse_regex_delim                                    109     111      +2
get_address                                          213     215      +2
add_cmd                                             1176    1178      +2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/0 up/down: 35/0)               Total: 35 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-23 18:48:49 +01:00
Denys Vlasenko 33a9f34df5 add busybox_ldscript.README.txt
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-23 15:46:05 +01:00
Denys Vlasenko 39369ff460 libbb/sha1: use SSE2 in unrolled x86-64 code. ~10% faster
function                                             old     new   delta
.rodata                                           108241  108305     +64
sha1_process_block64                                3502    3495      -7
------------------------------------------------------------------------------
(add/remove: 5/0 grow/shrink: 1/1 up/down: 64/-7)              Total: 57 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-23 12:57:27 +01:00
Denys Vlasenko 1e825acf8d libbb: shrink lineedit_read_key()
function                                             old     new   delta
lineedit_read_key                                    237     231      -6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-18 00:36:42 +01:00
Denys Vlasenko 8ad2acf352 fix "defined but not used" warnings
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-17 23:59:46 +01:00
Denys Vlasenko 12566e7f9b ash,hush: fix handling of SIGINT while waiting for interactive input
function                                             old     new   delta
lineedit_read_key                                    160     237     +77
__pgetc                                              522     589     +67
fgetc_interactive                                    244     309     +65
safe_read_key                                          -      39     +39
read_key                                             588     607     +19
record_pending_signo                                  23      32      +9
signal_handler                                        75      81      +6
.rodata                                           104312  104309      -3
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 6/1 up/down: 282/-3)            Total: 279 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-17 11:46:23 +01:00
Denys Vlasenko a277506a64 shell: add comments about SIGINT-related problems
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-16 23:54:46 +01:00
Denys Vlasenko c2788f88f4 libbb: introduce and use chdir_or_warn()
function                                             old     new   delta
chdir_or_warn                                          -      37     +37
send_cgi_and_exit                                    720     711      -9
xchdir                                                27      15     -12
setup_environment                                    233     217     -16
fork_job                                             449     433     -16
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/4 up/down: 37/-53)            Total: -16 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-13 12:56:10 +01:00
Denys Vlasenko 931c55f9e2 libbb: invert the meaning of SETUP_ENV_NO_CHDIR -> SETUP_ENV_CHDIR
Double negatives are hard to grok.

function                                             old     new   delta
login_main                                           986     988      +2
su_main                                              474     470      -4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 2/-4)               Total: -2 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-13 12:50:48 +01:00
Denys Vlasenko b3eec1651f sulogin: util-linux does not say "normal startup" on Ctrl-D
function                                             old     new   delta
sulogin_main                                         341     331     -10
.rodata                                           104327  104312     -15
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-25)             Total: -25 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-13 01:43:11 +01:00
Denys Vlasenko 96771ec5f5 sulogin: start _login_ shell only with -p
Also, shorten/eliminate messages to be closer to util-linux.

function                                             old     new   delta
packed_usage                                       34233   34238      +5
sulogin_main                                         340     341      +1
.rodata                                           104380  104327     -53
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 6/-53)             Total: -47 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-13 01:38:47 +01:00
Denys Vlasenko 68b402ee51 ash: ^C with SIG_INGed SIGINT should not exit the shell
function                                             old     new   delta
__pgetc                                              501     522     +21

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-13 01:15:10 +01:00
Denys Vlasenko d162a7b978 sulogin: increase util-linux compatibility
Change to root's HOME. Set some envvars. Steal ctty if necessary and possible.

function                                             old     new   delta
sulogin_main                                         240     340    +100
setup_environment                                    225     233      +8
su_main                                              479     474      -5
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 108/-5)            Total: 103 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-12 23:19:11 +01:00
Denys Vlasenko 004cefa918 reset: better --help text
function                                             old     new   delta
packed_usage                                       34175   34233     +58

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-12 17:21:14 +01:00
Denys Vlasenko 524fecf7c3 nmeter: %[md] %[mw] - dirty file-backed pages, writeback pages
function                                             old     new   delta
collect_mem                                          333     387     +54
.rodata                                           104369  104380     +11
packed_usage                                       34184   34175      -9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 65/-9)              Total: 56 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-11 19:32:16 +01:00
Denys Vlasenko ff8fda8482 ls: implement ls -sh (human-readable allocated blocks)
function                                             old     new   delta
display_single                                       979    1018     +39

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-08 22:59:49 +01:00
Denys Vlasenko 143356876b libbb/sha1: add a comment
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-08 22:43:24 +01:00
Denys Vlasenko e2952dfaff awk: input numbers are never octal or hex (only program consts can be)
function                                             old     new   delta
next_token                                           825     930    +105
getvar_i                                             114     129     +15
nextchar                                              49      53      +4
my_strtod                                            138       -    -138
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 3/0 up/down: 124/-138)          Total: -14 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-08 22:42:35 +01:00
Emanuele Giacomelli 84a1305888 XXXsum: handle binary sums with " " in the path
If a line specifies a binary checksum whose path contains two adjacent
spaces, when checking digests with -c the two spaces will be used as the
separator between the digest and the pathname instead of " *", as shown:

$ echo foo > "/tmp/two  spaces"
$ md5sum -b "/tmp/two  spaces"   # This is GNU md5sum
d3b07384d113edec49eaa6238ad5ff00 */tmp/two  spaces
$ md5sum -b "/tmp/two  spaces" | ./busybox md5sum -c
md5sum: can't open 'spaces': No such file or directory
spaces: FAILED
md5sum: WARNING: 1 of 1 computed checksums did NOT match

function                                             old     new   delta
md5_sha1_sum_main                                    503     496      -7

Signed-off-by: Emanuele Giacomelli <emanuele.giacomelli@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-08 17:16:00 +01:00
Denys Vlasenko e7ff29402d libbb/sha1: simplify cpuid code
function                                             old     new   delta
sha1_begin                                           107     106      -1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-08 01:25:23 +01:00
Denys Vlasenko 805ececa61 whitespace fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-08 00:41:09 +01:00
Denys Vlasenko 0bab5da37e libbb/sha1: tweak comments
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-07 14:55:31 +01:00
Denys Vlasenko 89092c61bc powertop: fix cpuid asm: ebx saving/restoring is properly done by gcc
function                                             old     new   delta
print_intel_cstates                                  481     477      -4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-07 01:33:46 +01:00
Denys Vlasenko a96ccbefe4 libbb/sha1: optional i686 hardware accelerates hashing
function                                             old     new   delta
sha1_process_block64_shaNI                             -     524    +524
sha1_begin                                            57     114     +57
.rodata                                           104353  104369     +16
static.shaNI                                           -       1      +1
------------------------------------------------------------------------------
(add/remove: 4/0 grow/shrink: 2/0 up/down: 598/0)             Total: 598 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-07 01:32:13 +01:00
Denys Vlasenko 711e20ecb8 libbb/sha1: optional x86-64 hardware accelerates hashing
function                                             old     new   delta
sha1_process_block64_shaNI                             -     510    +510
sha1_begin                                            52     107     +55
.rodata                                           108285  108301     +16
static.shaNI                                           -       1      +1
------------------------------------------------------------------------------
(add/remove: 4/0 grow/shrink: 2/0 up/down: 582/0)             Total: 582 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-07 00:43:59 +01:00
Vincent Stehlé a93668cc42 fdisk: recognize EBBR protective partitions
The MBR partition type 0xF8 is used by the Arm EBBR specification[1] for
protective partitions over fixed-location firmware images.

[1]: https://github.com/ARM-software/ebbr

Signed-off-by: Vincent Stehlé <vincent.stehle@arm.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-06 10:55:53 +01:00
Denys Vlasenko 6062c0d19b libbb: change xstrndup, xmemdup to take size_t as size parameter
Also, remove entirely usually-disabled paranoia check (was also using
wrong config option to enable itself).

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-05 23:03:54 +01:00
Denys Vlasenko db5546ca10 libbb: code shrink: introduce and use [_]exit_SUCCESS()
function                                             old     new   delta
exit_SUCCESS                                           -       7      +7
_exit_SUCCESS                                          -       7      +7
run_pipe                                            1562    1567      +5
pseudo_exec_argv                                     399     400      +1
finish                                                86      87      +1
start_stop_daemon_main                              1109    1107      -2
shutdown_on_signal                                    38      36      -2
runsv_main                                          1662    1660      -2
redirect                                            1070    1068      -2
read_line                                             79      77      -2
pause_and_low_level_reboot                            54      52      -2
list_i2c_busses_and_exit                             483     481      -2
less_exit                                             12      10      -2
identify                                            4123    4121      -2
grep_file                                           1161    1159      -2
getty_main                                          1519    1517      -2
fsck_minix_main                                     2681    2679      -2
free_session                                         132     130      -2
fdisk_main                                          4739    4737      -2
clean_up_and_exit                                     53      51      -2
bsd_select                                          1566    1564      -2
bb_daemonize_or_rexec                                198     196      -2
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 3/17 up/down: 21/-34)           Total: -13 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-05 22:16:06 +01:00
Denys Vlasenko 076f5e064f less: code shrink
function                                             old     new   delta
restore_tty                                            -      29     +29
less_main                                           2107    2105      -2
getch_nowait                                         253     251      -2
buffer_print                                         614     612      -2
less_exit                                             51      12     -39
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/4 up/down: 29/-45)            Total: -16 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-05 22:04:21 +01:00
Denys Vlasenko 34e0bb3931 sort: support -h
function                                             old     new   delta
static.scale_suffix                                    -      62     +62
.rodata                                           104304  104336     +32
compare_keys                                         820     848     +28
packed_usage                                       34159   34184     +25
static.suffix                                          -       9      +9
sort_opt_str                                          37      38      +1
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 4/0 up/down: 157/0)             Total: 157 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-05 12:05:55 +01:00
Denys Vlasenko cc7d2e2178 sort: fix -s -r interaction: 'stable' order is not affected by -r
function                                             old     new   delta
compare_keys                                         818     820      +2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-04 23:53:21 +01:00
Denys Vlasenko dfd8aafcf5 libbb: fflush_stdout_and_exit(0) still exits with _error_ (not 0!) if fflush fails
function                                             old     new   delta
fflush_stdout_and_exit                                36      40      +4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-04 23:36:16 +01:00
Denys Vlasenko 31f45c1b36 libbb: factor out fflush_stdout_and_exit(EXIT_SUCCESS)
function                                             old     new   delta
fflush_stdout_and_exit_SUCCESS                         -       7      +7
xxd_main                                             890     888      -2
vlock_main                                           353     351      -2
uuencode_main                                        318     316      -2
uniq_main                                            427     425      -2
uname_main                                           250     248      -2
sort_main                                            853     851      -2
shuf_main                                            500     498      -2
route_main                                           238     236      -2
readlink_main                                        113     111      -2
nice_main                                            156     154      -2
last_main                                            957     955      -2
ipcs_main                                            960     958      -2
env_main                                             209     207      -2
chrt_main                                            464     462      -2
cal_main                                             921     919      -2
baseNUM_main                                         650     648      -2
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/16 up/down: 7/-32)            Total: -25 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-04 23:31:58 +01:00
Denys Vlasenko 286b33721d sed: correctly handle 'w FILE' commands writing to the same file
function                                             old     new   delta
sed_xfopen_w                                           -      84     +84

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-04 19:42:36 +01:00
Denys Vlasenko ed2af2e82d build system: detect if build host has no bzip2
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-04 14:32:41 +01:00
Denys Vlasenko c3cfcc9242 libbb/sha1: x86_64 version: reorder prologue/epilogue insns
Not clear exactly why, but this increases hashing speed
on Skylake from 454 MB/s to 464 MB/s.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-04 01:45:52 +01:00
Denys Vlasenko 1fc520ed28 md5/shaXsum: use FEATURE_COPYBUF_KB to size the buffer instead of fixed 4k
function                                             old     new   delta
md5_sha1_sum_main                                    536     565     +29
hash_file                                            419     401     -18
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 29/-18)             Total: 11 bytes

In my test, for unrolled sha1, COPYBUF_KB=64 increases throughput
from 367 MB/s to 457 MB/s.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-04 00:51:04 +01:00
Denys Vlasenko 7abb2bb96e libbb/sha1: x86_64 version: tidying up, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-03 17:02:48 +01:00
Denys Vlasenko 4387077f8e typo fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-03 13:14:09 +01:00
Denys Vlasenko 947bef0dea libbb/sha1: x86_64 version: generate from a script, optimize a bit
function                                             old     new   delta
sha1_process_block64                                3569    3502     -67

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-03 13:10:30 +01:00
Denys Vlasenko 05fd13ebec libbb/sha1: x86_64 version: move to a separate .S file, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-03 12:57:36 +01:00
Denys Vlasenko 5c0c558231 libbb/sha1: code shrink in medium-speed version
function                                             old     new   delta
sha1_process_block64                                 654     641     -13

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-02 01:56:35 +01:00
Denys Vlasenko 4d4f1f2096 libbb/sha1: x86_64 version: bswap in 64-bit chunks
function                                             old     new   delta
sha1_process_block64                                3562    3570      +8

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-01 15:42:15 +01:00
Denys Vlasenko d643010fee libbb/sha1: shrink x86_64 version - use r8..15 for W[8..15]
function                                             old     new   delta
sha1_process_block64                                3683    3562    -121

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-01 15:01:53 +01:00
Denys Vlasenko 5f68170204 libbb/sha1: assembly versions for x86
32 bits:
function                                             old     new   delta
sha1_process_block64                                3950    3657    -293
64 bits:
sha1_process_block64                                4167    3683    -484

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-01 13:57:34 +01:00
Denys Vlasenko f09d088fdf libbb/sha1: shrink and speed up fully unrolled version
function                                             old     new   delta
sha1_process_block64                                4149    3950    -199

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-12-31 17:07:47 +01:00
Denys Vlasenko 0b62a08777 libbb/sha1: add config-selectable partially unrolled version
function                                             old     new   delta
sha1_process_block64                                 364     732    +368
static.rconsts                                        16       -     -16
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/0 up/down: 368/-16)           Total: 352 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-12-30 18:54:02 +01:00
Denys Vlasenko 25aadc893d libbb/sha1: add config-selectable fully unrolled version, closes 14391
function                                             old     new   delta
sha1_process_block64                                 364    4167   +3803
static.rconsts                                        16       -     -16
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/0 up/down: 3803/-16)         Total: 3787 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-12-30 13:17:16 +01:00
Sören Tempel 9173c9cce4 ed: add support for -s command-line option as mandated by POSIX
Apart from the -p option, POSIX also mandates an -s option which
suppresses the output of byte counts for the e, E, r, and w command.
From these commands, Busybox ed presently only implements the r and w
commands. This commit ensures that these two command do not output any
bytes counts when the -s option is passed. The shell escape command,
also effected by the -s option, is not implemented by Busybox at the
moment.

function                                             old     new   delta
packed_usage                                       34096   34115     +19
doCommands                                          1887    1900     +13
readLines                                            388     397      +9
.rodata                                           104196  104200      +4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/0 up/down: 45/0)               Total: 45 bytes

Signed-off-by: Sören Tempel <soeren+git@soeren-tempel.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-12-29 19:01:32 +01:00
Denys Vlasenko 0e2cb6d1e2 echo: add FIXME comment
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-12-29 07:26:23 +01:00
Denys Vlasenko 0fcc7f5f73 scripts/echo.c: fix NUL handling in "abc\0 def"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-12-28 21:05:59 +01:00
Denys Vlasenko f1d06462e8 libbb: cose shrink in sha1
function                                             old     new   delta
sha1_process_block64                                 356     342     -14

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-12-28 09:05:12 +01:00
Denys Vlasenko 44075929a8 Start 1.36.0 development cycle
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-12-26 18:40:55 +01:00
805 changed files with 36468 additions and 14299 deletions

No files matched your search

+3
View File
@@ -181,3 +181,6 @@ Jie Zhang <jie.zhang@analog.com>
Maxime Coste <mawww@kakoune.org>
paste implementation
Roger Knecht <rknecht@pm.me>
tree
+18
View File
@@ -108,6 +108,17 @@ config LFS
programs that can benefit from large file support include dd, gzip,
cp, mount, tar.
config TIME64
bool "Support 64bit wide time types"
default y
depends on LFS
help
Make times later than 2038 representable for several libc syscalls
(stat, clk_gettime etc.). Note this switch is specific to glibc
and has no effect on platforms that already use 64bit wide time types
(i.e. all 64bit archs and some selected 32bit archs (currently riscv
and x32)).
config PAM
bool "Support PAM (Pluggable Authentication Modules)"
default n
@@ -193,6 +204,13 @@ config FEATURE_INSTALLER
busybox at runtime to create hard links or symlinks for all the
applets that are compiled into busybox.
config FEATURE_VERSION
bool "Support --version"
default y
depends on BUSYBOX
help
Enable 'busybox --version' support.
config INSTALL_NO_USR
bool "Don't use /usr"
default n
+9 -11
View File
@@ -1,7 +1,7 @@
VERSION = 1
PATCHLEVEL = 35
PATCHLEVEL = 39
SUBLEVEL = 0
EXTRAVERSION =
EXTRAVERSION = .git
NAME = Unnamed
# *DOCUMENTATION*
@@ -476,6 +476,7 @@ libs-y := \
findutils/ \
init/ \
libbb/ \
libbb/yescrypt/ \
libpwdgrp/ \
loginutils/ \
mailutils/ \
@@ -612,8 +613,12 @@ quiet_cmd_busybox__ ?= LINK $@
"$(core-y)" \
"$(libs-y)" \
"$(LDLIBS)" \
"$(CONFIG_EXTRA_LDLIBS)" \
$(CONFIG_EXTRA_LDLIBS) \
&& $(srctree)/scripts/generate_BUFSIZ.sh --post include/common_bufsiz.h
# ^^^ note: CONFIG_xyz strings already have double quotes: their value
# is '"LIB LIB2"', therefore $(CONFIG_EXTRA_LDLIBS) above must NOT be written
# as "$(CONFIG_EXTRA_LDLIBS)", it would be passed as ""LIB LIB2"",
# and LIB2 would end up in $9, not $8 (and lost or misinterpreted).
# Generate System.map
quiet_cmd_sysmap = SYSMAP
@@ -967,6 +972,7 @@ endif # CONFIG_MODULES
# Directories & files removed with 'make clean'
CLEAN_DIRS += $(MODVERDIR) _install 0_lib
CLEAN_FILES += busybox busybox_unstripped* busybox.links \
busybox*.suid busybox*.nosuid \
System.map .kernelrelease \
.tmp_kallsyms* .tmp_version .tmp_busybox* .tmp_System.map
@@ -1301,14 +1307,6 @@ quiet_cmd_rmdirs = $(if $(wildcard $(rm-dirs)),CLEAN $(wildcard $(rm-dirs)))
quiet_cmd_rmfiles = $(if $(wildcard $(rm-files)),CLEAN $(wildcard $(rm-files)))
cmd_rmfiles = rm -f $(rm-files)
a_flags = -Wp,-MD,$(depfile) $(AFLAGS) $(AFLAGS_KERNEL) \
$(NOSTDINC_FLAGS) $(CPPFLAGS) \
$(modkern_aflags) $(EXTRA_AFLAGS) $(AFLAGS_$(*F).o)
quiet_cmd_as_o_S = AS $@
cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $<
# read all saved command lines
targets := $(wildcard $(sort $(targets)))
+2 -2
View File
@@ -156,12 +156,12 @@ docs/busybox.pod: $(srctree)/docs/busybox_header.pod \
docs/BusyBox.txt: docs/busybox.pod
$(disp_doc)
$(Q)-mkdir -p docs
$(Q)-pod2text $< > $@
$(Q)-pod2text --quotes=none $< > $@
docs/busybox.1: docs/busybox.pod
$(disp_doc)
$(Q)-mkdir -p docs
$(Q)-pod2man --center=busybox --release="version $(KERNELVERSION)" $< > $@
$(Q)-pod2man --quotes=none --center=busybox --release="version $(KERNELVERSION)" $< > $@
docs/BusyBox.html: docs/busybox.net/BusyBox.html
$(disp_doc)
+11 -5
View File
@@ -15,6 +15,7 @@ CPPFLAGS += \
-include include/autoconf.h \
-D_GNU_SOURCE -DNDEBUG \
$(if $(CONFIG_LFS),-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64) \
$(if $(CONFIG_TIME64),-D_TIME_BITS=64) \
-DBB_VER=$(squote)$(quote)$(BB_VER)$(quote)$(squote)
CFLAGS += $(call cc-option,-Wall,)
@@ -26,6 +27,8 @@ CFLAGS += $(call cc-option,-Wunused -Wunused-parameter,)
CFLAGS += $(call cc-option,-Wunused-function -Wunused-value,)
CFLAGS += $(call cc-option,-Wmissing-prototypes -Wmissing-declarations,)
CFLAGS += $(call cc-option,-Wno-format-security,)
# we use "" format in ioctl_or_perror_and_die(a, b, c, "")
CFLAGS += $(call cc-option,-Wno-format-zero-length,)
# warn about C99 declaration after statement
CFLAGS += $(call cc-option,-Wdeclaration-after-statement,)
# If you want to add more -Wsomething above, make sure that it is
@@ -47,7 +50,7 @@ endif
# gcc 3.x emits bogus "old style proto" warning on find.c:alloc_action()
CFLAGS += $(call cc-ifversion, -ge, 0400, -Wold-style-definition)
ifneq ($(CC),clang)
ifneq ($(lastword $(subst -, ,$(CC))),clang)
# "clang-9: warning: optimization flag '-finline-limit=0' is not supported
CFLAGS += $(call cc-option,-finline-limit=0,)
endif
@@ -65,7 +68,7 @@ CFLAGS += $(call cc-option,-static-libgcc,)
endif
CFLAGS += $(call cc-option,-falign-functions=1,)
ifneq ($(CC),clang)
ifneq ($(lastword $(subst -, ,$(CC))),clang)
# "clang-9: warning: optimization flag '-falign-jumps=1' is not supported" (and same for other two)
CFLAGS += $(call cc-option,-falign-jumps=1 -falign-labels=1 -falign-loops=1,)
endif
@@ -78,7 +81,7 @@ CFLAGS += $(call cc-option,-fno-asynchronous-unwind-tables,)
CFLAGS += $(call cc-option,-fno-builtin-printf,)
# clang-9 does not like "str" + N and "if (CONFIG_ITEM && cond)" constructs
ifeq ($(CC),clang)
ifeq ($(lastword $(subst -, ,$(CC))),clang)
CFLAGS += $(call cc-option,-Wno-string-plus-int -Wno-constant-logical-operand)
endif
@@ -87,14 +90,14 @@ endif
#CFLAGS += $(call cc-option,-Wconversion,)
ifneq ($(CONFIG_DEBUG),y)
CFLAGS += $(call cc-option,-Os,$(call cc-option,-O2,))
CFLAGS += $(call cc-option,-Oz,$(call cc-option,-Os,$(call cc-option,-O2,)))
else
CFLAGS += $(call cc-option,-g,)
#CFLAGS += "-D_FORTIFY_SOURCE=2"
ifeq ($(CONFIG_DEBUG_PESSIMIZE),y)
CFLAGS += $(call cc-option,-O0,)
else
CFLAGS += $(call cc-option,-Os,$(call cc-option,-O2,))
CFLAGS += $(call cc-option,-Oz,$(call cc-option,-Os,$(call cc-option,-O2,)))
endif
endif
ifeq ($(CONFIG_DEBUG_SANITIZE),y)
@@ -187,6 +190,9 @@ ifeq ($(CONFIG_FEATURE_NSLOOKUP_BIG),y)
ifneq (,$(findstring linux,$(shell $(CC) $(CFLAGS) -dumpmachine)))
LDLIBS += resolv
endif
ifneq (,$(findstring gnu,$(shell $(CC) $(CFLAGS) -dumpmachine)))
LDLIBS += resolv
endif
endif
ifeq ($(CONFIG_EFENCE),y)
+1
View File
@@ -336,6 +336,7 @@ setuidgid - noexec. spawner
sha1sum - noexec. runner
sha256sum - noexec. runner
sha3sum - noexec. runner
sha384sum - noexec. runner
sha512sum - noexec. runner
showkey - interactive, longterm
shred - runner
-2
View File
@@ -222,8 +222,6 @@ Minor stuff:
---
unify progress_meter. wget, flash_eraseall, pipe_progress, fbsplash, setfiles.
---
support start-stop-daemon -d <chdir-path>
---
(TODO list after discussion 11.05.2009)
+1 -1
View File
@@ -20,5 +20,5 @@ int main(int argc, char **argv)
void bb_show_usage(void)
{
fputs_stdout(APPLET_full_usage "\n");
exit(EXIT_FAILURE);
exit_FAILURE();
}
+12 -5
View File
@@ -67,30 +67,37 @@ int main(void)
}
if (col == 0) {
col = 6;
printf("\t");
} else {
printf(", ");
}
printf("%s", usage_array[i].aname);
if (usage_array[i].usage[0] != NOUSAGE_STR[0]) {
/*
* If the applet usage string will be included in the final document
* optimistically link to its header (which is just the applet name).
*/
printf("L<C<%1$s>|/\"%1$s\">", usage_array[i].aname);
} else {
/* Without a usage string, just output the applet name with no link. */
printf("C<%s>", usage_array[i].aname);
}
col += len2;
}
printf("\n\n");
printf("=head1 COMMAND DESCRIPTIONS\n\n");
printf("=over 4\n\n");
for (i = 0; i < num_messages; i++) {
if (usage_array[i].aname[0] >= 'a' && usage_array[i].aname[0] <= 'z'
&& usage_array[i].usage[0] != NOUSAGE_STR[0]
) {
printf("=item B<%s>\n\n", usage_array[i].aname);
/* This is the heading that will be linked from the command list. */
printf("=head2 %s\n\n", usage_array[i].aname);
if (usage_array[i].usage[0])
printf("%s %s\n\n", usage_array[i].aname, usage_array[i].usage);
else
printf("%s\n\n", usage_array[i].aname);
}
}
printf("=back\n\n");
return 0;
}
+11
View File
@@ -35,4 +35,15 @@ config FEATURE_LZMA_FAST
This option reduces decompression time by about 25% at the cost of
a 1K bigger binary.
config FEATURE_PATH_TRAVERSAL_PROTECTION
bool "Prevent extraction of filenames with /../ path component"
default n
help
busybox tar and unzip remove "PREFIX/../" (if it exists)
from extracted names.
This option enables this behavior for all other unpacking applets,
such as cpio, ar, rpm.
GNU cpio 2.15 has NO such sanity check.
# try other archivers and document their behavior?
endmenu
+6 -5
View File
@@ -151,15 +151,15 @@ static int write_ar_header(archive_handle_t *handle)
static int write_ar_archive(archive_handle_t *handle)
{
struct stat st;
off_t st_size;
archive_handle_t *out_handle;
xfstat(handle->src_fd, &st, handle->ar__name);
st_size = xfstat_size(handle->src_fd, handle->ar__name);
/* if archive exists, create a new handle for output.
* we create it in place of the old one.
*/
if (st.st_size != 0) {
if (st_size != 0) {
out_handle = init_handle();
xunlink(handle->ar__name);
out_handle->src_fd = xopen(handle->ar__name, O_WRONLY | O_CREAT | O_TRUNC);
@@ -174,7 +174,7 @@ static int write_ar_archive(archive_handle_t *handle)
out_handle->offset += AR_MAGIC_LEN + 1;
/* skip to the end of the archive if we have to append stuff */
if (st.st_size != 0) {
if (st_size != 0) {
handle->filter = filter_replaceable;
handle->action_data = copy_data;
unpack_ar_archive(handle);
@@ -194,8 +194,9 @@ static int write_ar_archive(archive_handle_t *handle)
}
#endif /* FEATURE_AR_CREATE */
static void FAST_FUNC header_verbose_list_ar(const file_header_t *file_header)
static void FAST_FUNC header_verbose_list_ar(archive_handle_t *archive_handle)
{
const file_header_t *file_header = archive_handle->file_header;
char mode[12];
char *mtime;
+7 -7
View File
@@ -71,8 +71,8 @@ int FAST_FUNC bbunpack(char **argv,
goto err;
} else {
/* "clever zcat" with FILE */
/* fail_if_not_compressed because zcat refuses uncompressed input */
int fd = open_zipped(filename, /*fail_if_not_compressed:*/ 1);
/* die_if_not_compressed because zcat refuses uncompressed input */
int fd = open_zipped(filename, /*die_if_not_compressed:*/ 1);
if (fd < 0)
goto err_name;
xmove_fd(fd, STDIN_FILENO);
@@ -80,7 +80,7 @@ int FAST_FUNC bbunpack(char **argv,
} else
if (option_mask32 & BBUNPK_SEAMLESS_MAGIC) {
/* "clever zcat" on stdin */
if (setup_unzip_on_fd(STDIN_FILENO, /*fail_if_not_compressed*/ 1))
if (setup_unzip_on_fd(STDIN_FILENO, /*die_if_not_compressed*/ 1))
goto err;
}
@@ -415,7 +415,7 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
//usage: "Decompress to stdout"
//config:config BUNZIP2
//config: bool "bunzip2 (8.7 kb)"
//config: bool "bunzip2 (9.1 kb)"
//config: default y
//config: select FEATURE_BZIP2_DECOMPRESS
//config: help
@@ -429,7 +429,7 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
//config: should probably say N here.
//config:
//config:config BZCAT
//config: bool "bzcat (8.7 kb)"
//config: bool "bzcat (9 kb)"
//config: default y
//config: select FEATURE_BZIP2_DECOMPRESS
//config: help
@@ -485,7 +485,7 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv)
//usage: "Decompress to stdout"
//config:config UNLZMA
//config: bool "unlzma (7.5 kb)"
//config: bool "unlzma (7.8 kb)"
//config: default y
//config: help
//config: unlzma is a compression utility using the Lempel-Ziv-Markov chain
@@ -494,7 +494,7 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv)
//config: compressors.
//config:
//config:config LZCAT
//config: bool "lzcat (7.5 kb)"
//config: bool "lzcat (7.8 kb)"
//config: default y
//config: help
//config: Alias to "unlzma -c".
+9 -3
View File
@@ -53,7 +53,7 @@
//config: help
//config: Optionally renumber inodes when creating archives.
//applet:IF_CPIO(APPLET(cpio, BB_DIR_BIN, BB_SUID_DROP))
//applet:IF_CPIO(APPLET(cpio, BB_DIR_USR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_CPIO) += cpio.o
@@ -62,7 +62,7 @@
//usage: " [-ti"IF_FEATURE_CPIO_O("o")"]" IF_FEATURE_CPIO_P(" [-p DIR]")
//usage: " [EXTR_FILE]..."
//usage:#define cpio_full_usage "\n\n"
//usage: "Extract (-i) or list (-t) files from a cpio archive"
//usage: "Extract (-i) or list (-t) files from a cpio archive on stdin"
//usage: IF_FEATURE_CPIO_O(", or"
//usage: "\ntake file list from stdin and create an archive (-o)"
//usage: IF_FEATURE_CPIO_P(" or copy files (-p)")
@@ -350,6 +350,12 @@ static NOINLINE int cpio_o(void)
st.st_dev = st.st_rdev = 0;
#endif
if (sizeof(st.st_size) > 4
&& st.st_size > (off_t)0xffffffff
) {
bb_error_msg_and_die("error: file '%s' is larger than 4GB", name);
}
bytes += printf("070701"
"%08X%08X%08X%08X%08X%08X%08X"
"%08X%08X%08X%08X" /* GNU cpio uses uppercase hex */
@@ -421,6 +427,7 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
#endif
#endif
"owner\0" Required_argument "R"
"file\0" Required_argument "F"
"verbose\0" No_argument "v"
"null\0" No_argument "0"
"quiet\0" No_argument "\xff"
@@ -504,7 +511,6 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
goto dump;
}
/* parent */
USE_FOR_NOMMU(argv[-optind][0] &= 0x7f); /* undo fork_or_rexec() damage */
xchdir(*argv++);
close(pp.wr);
xmove_fd(pp.rd, STDIN_FILENO);
+178 -140
View File
@@ -41,30 +41,30 @@
//kbuild:lib-$(CONFIG_DPKG) += dpkg.o
//usage:#define dpkg_trivial_usage
//usage: "[-ilCPru] [-F OPT] PACKAGE"
//usage: IF_LONG_OPTS("-i|P|r|--unpack|--configure [--force-OPT]")IF_NOT_LONG_OPTS("-i|P|r|u|C [-F OPT]")" PACKAGE | -l [PATTERN]"
//usage:#define dpkg_full_usage "\n\n"
//usage: "Install, remove and manage Debian packages\n"
//usage: "Manage Debian packages\n"
//usage: IF_LONG_OPTS(
//usage: "\n -i,--install Install the package"
//usage: "\n -l,--list List of installed packages"
//usage: "\n --configure Configure an unpackaged package"
//usage: "\n -P,--purge Purge all files of a package"
//usage: "\n -r,--remove Remove all but the configuration files for a package"
//usage: "\n --unpack Unpack a package, but don't configure it"
//usage: "\n -i,--install Install PACKAGE.deb"
//usage: "\n -P,--purge Purge all files of PACKAGE"
//usage: "\n -r,--remove Remove all but configuration files of PACKAGE"
//usage: "\n --unpack Unpack PACKAGE.deb relative to /, don't configure"
//usage: "\n --configure Configure unpacked PACKAGE"
//usage: "\n --force-depends Ignore dependency problems"
//usage: "\n --force-confnew Overwrite existing config files when installing"
//usage: "\n --force-confold Keep old config files when installing"
//usage: "\n -l,--list List installed packages"
//usage: )
//usage: IF_NOT_LONG_OPTS(
//usage: "\n -i Install the package"
//usage: "\n -l List of installed packages"
//usage: "\n -C Configure an unpackaged package"
//usage: "\n -P Purge all files of a package"
//usage: "\n -r Remove all but the configuration files for a package"
//usage: "\n -u Unpack a package, but don't configure it"
//usage: "\n -i Install PACKAGE.deb"
//usage: "\n -P Purge all files of PACKAGE"
//usage: "\n -r Remove all but configuration files of PACKAGE"
//usage: "\n -u Unpack PACKAGE.deb relative to /, don't configure"
//usage: "\n -C Configure unpacked PACKAGE"
//usage: "\n -F depends Ignore dependency problems"
//usage: "\n -F confnew Overwrite existing config files when installing"
//usage: "\n -F confold Keep old config files when installing"
//usage: "\n -l List installed packages"
//usage: )
#include "libbb.h"
@@ -166,8 +166,9 @@ typedef struct deb_file_s {
} deb_file_t;
static void make_hash(const char *key, unsigned *start, unsigned *decrement, const int hash_prime)
static unsigned make_hash(const char *key, unsigned *decrement, int hash_prime)
{
unsigned start;
unsigned long hash_num = key[0];
int len = strlen(key);
int i;
@@ -181,8 +182,9 @@ static void make_hash(const char *key, unsigned *start, unsigned *decrement, con
* no effect */
hash_num += (key[i] + key[i-1]) << ((key[i] * i) % 24);
}
*start = (unsigned) hash_num % hash_prime;
start = (unsigned) hash_num % hash_prime;
*decrement = (unsigned) 1 + (hash_num % (hash_prime - 1));
return start;
}
/* this adds the key to the hash table */
@@ -191,7 +193,7 @@ static int search_name_hashtable(const char *key)
unsigned probe_address;
unsigned probe_decrement;
make_hash(key, &probe_address, &probe_decrement, NAME_HASH_PRIME);
probe_address = make_hash(key, &probe_decrement, NAME_HASH_PRIME);
while (name_hashtable[probe_address] != NULL) {
if (strcmp(name_hashtable[probe_address], key) == 0) {
return probe_address;
@@ -213,7 +215,7 @@ static unsigned search_status_hashtable(const char *key)
unsigned probe_address;
unsigned probe_decrement;
make_hash(key, &probe_address, &probe_decrement, STATUS_HASH_PRIME);
probe_address = make_hash(key, &probe_decrement, STATUS_HASH_PRIME);
while (status_hashtable[probe_address] != NULL) {
if (strcmp(key, name_hashtable[package_hashtable[status_hashtable[probe_address]->package]->name]) == 0) {
break;
@@ -280,7 +282,7 @@ static int version_compare_part(const char *val, const char *ref)
* if ver1 = ver2 return 0,
* if ver1 > ver2 return 1,
*/
static int version_compare(const unsigned ver1, const unsigned ver2)
static int version_compare(unsigned ver1, unsigned ver2)
{
char *ch_ver1 = name_hashtable[ver1];
char *ch_ver2 = name_hashtable[ver2];
@@ -333,9 +335,9 @@ static int version_compare(const unsigned ver1, const unsigned ver2)
return result;
}
static int test_version(const unsigned version1, const unsigned version2, const unsigned operator)
static int test_version(unsigned version1, unsigned version2, unsigned operator)
{
const int version_result = version_compare(version1, version2);
int version_result = version_compare(version1, version2);
switch (operator) {
case VER_ANY:
return TRUE;
@@ -353,12 +355,12 @@ static int test_version(const unsigned version1, const unsigned version2, const
return FALSE;
}
static int search_package_hashtable(const unsigned name, const unsigned version, const unsigned operator)
static int search_package_hashtable(unsigned name, unsigned version, unsigned operator)
{
unsigned probe_address;
unsigned probe_decrement;
make_hash(name_hashtable[name], &probe_address, &probe_decrement, PACKAGE_HASH_PRIME);
probe_address = make_hash(name_hashtable[name], &probe_decrement, PACKAGE_HASH_PRIME);
while (package_hashtable[probe_address] != NULL) {
if (package_hashtable[probe_address]->name == name) {
if (operator == VER_ANY) {
@@ -531,90 +533,98 @@ static void free_package(common_node_t *node)
}
/*
* Gets the next package field from package_buffer, separated into the field name
* and field value, it returns the int offset to the first character of the next field
* Gets the next package field from pkg_buf:
* "NAME:<spaces|tabs>VALUE{\n|NUL}"
* "NAME:<spaces|tabs>VALUE\n
* " VALUE_LINE2{\n|NUL}"
* separated into "NAME" and "VALUE", both strdup()ed.
* (Debian does not allow whitespace before/after NAME).
* Returns offset to the first character of the next field (or to NUL).
* The pkg_buf parameter is NUL-terminated.
*
* https://manpages.debian.org/testing/dpkg-dev/deb-control.5.en.html
* """
* This file contains a number of fields. Each field begins with a tag,
* such as Package or Version (case insensitive), followed by a colon,
* and the body of the field (case sensitive unless stated otherwise).
* Fields are delimited only by field tags. In other words, field text
* may be multiple lines in length, but the installation tools will
* generally join lines when processing the body of the field (except
* in the case of the Description field, see below).
* ...
* Description: short-description (recommended)
* long-description
* The format for the package description is a short brief summary
* on the first line (after the Description field). The following lines
* should be used as a longer, more detailed description. Each line
* of the long description must be preceded by a space, and blank
* lines in the long description must contain a single '.' following
* the preceding space."""
*
* Seen in libgtk-3-0t64_3.24.52: source package's control:
* Recommends: ibus-gtk3,
* libgtk-3-bin,
* librsvg2-common
* gets translated to this in binary package's control:
* Recommends: ibus-gtk3, libgtk-3-bin, librsvg2-common
*/
static int read_package_field(const char *package_buffer, char **field_name, char **field_value)
static int read_package_field(const char *pkg_buf, char **pname, char **pvalue)
{
int offset_name_start = 0;
int offset_name_end = 0;
int offset_value_start = 0;
int offset_value_end = 0;
int offset = 0;
int next_offset;
int name_length;
int value_length;
int exit_flag = FALSE;
int name_start;
int name_end;
int value_start = value_start;
int offset;
if (package_buffer == NULL) {
*field_name = NULL;
*field_value = NULL;
return -1;
}
*pname = NULL;
*pvalue = NULL;
offset = 0;
name_start = 0;
name_end = 0; /* "we did not see ':' yet" */
while (1) {
next_offset = offset + 1;
switch (package_buffer[offset]) {
case '\0':
exit_flag = TRUE;
break;
case ':':
if (offset_name_end == 0) {
offset_name_end = offset;
offset_value_start = next_offset;
}
/* TODO: Name might still have trailing spaces if ':' isn't
* immediately after name */
break;
case '\n':
/* TODO: The char next_offset may be out of bounds */
if (package_buffer[next_offset] != ' ') {
exit_flag = TRUE;
break;
}
case '\t':
case ' ':
/* increment the value start point if its a just filler */
if (offset_name_start == offset) {
offset_name_start++;
}
if (offset_value_start == offset) {
offset_value_start++;
}
break;
}
if (exit_flag) {
/* Check that the names are valid */
offset_value_end = offset;
name_length = offset_name_end - offset_name_start;
value_length = offset_value_end - offset_value_start;
if (name_length == 0) {
break;
char ch = pkg_buf[offset];
switch (ch) {
case ':':
if (name_end == 0) {
offset++;
name_end = offset; /* points AFTER ':' - think of empty NAME case */
while (isblank(pkg_buf[offset])) /* skip spaces/tabs (not newlines!) */
offset++;
value_start = offset;
continue; /* check next char */
}
if ((name_length > 0) && (value_length > 0)) {
break;
case '\n':
if (pkg_buf[offset + 1] == ' ')
break;
/* end of VALUE - fall through */
case '\0':
/* Did we see the ':'? */
if (name_end != 0) {
/* Yes. Check that NAME is not empty */
int nlen = (name_end - 1) - name_start;
if (nlen > 0) {
//TODO: why do we disallow empty NAME? Imagine a ": VALUE\n" line
*pname = xstrndup(&pkg_buf[name_start], nlen);
*pvalue = xstrndup(&pkg_buf[value_start], offset - value_start); /* could be "" */
if (ch)
offset++; /* skip '\n' */
return offset;
}
}
if (!ch)
return offset; /* stop at NUL */
/* If not valid, start fresh with next field */
exit_flag = FALSE;
offset_name_start = offset + 1;
offset_name_end = 0;
offset_value_start = offset + 1;
offset_value_end = offset + 1;
offset++;
/* Not valid: skip '\n', start fresh with next field */
name_start = offset + 1;
name_end = 0; /* "we did not see ':' yet" */
break;
}
offset++;
}
*field_name = NULL;
if (name_length) {
*field_name = xstrndup(&package_buffer[offset_name_start], name_length);
}
*field_value = NULL;
if (value_length > 0) {
*field_value = xstrndup(&package_buffer[offset_value_start], value_length);
}
return next_offset;
} /* while (1) */
}
/* The parameter is NUL-terminated */
static unsigned fill_package_struct(char *control_buffer)
{
static const char field_names[] ALIGN1 =
@@ -623,14 +633,13 @@ static unsigned fill_package_struct(char *control_buffer)
"Conflicts\0""Suggests\0""Recommends\0""Enhances\0";
common_node_t *new_node = xzalloc(sizeof(common_node_t));
char *field_name;
char *field_value;
int field_start = 0;
int num = -1;
int buffer_length = strlen(control_buffer);
int num;
new_node->version = search_name_hashtable("unknown");
while (field_start < buffer_length) {
while (control_buffer[field_start]) {
char *field_name;
char *field_value;
unsigned field_num;
field_start += read_package_field(&control_buffer[field_start],
@@ -689,7 +698,7 @@ static unsigned fill_package_struct(char *control_buffer)
}
/* if num = 1, it returns the want status, 2 returns flag, 3 returns status */
static unsigned get_status(const unsigned status_node, const int num)
static unsigned get_status(unsigned status_node, int num)
{
char *status_string = name_hashtable[status_hashtable[status_node]->status];
char *state_sub_string;
@@ -711,9 +720,9 @@ static unsigned get_status(const unsigned status_node, const int num)
return state_sub_num;
}
static void set_status(const unsigned status_node_num, const char *new_value, const int position)
static void set_status(unsigned status_node_num, const char *new_value, int position)
{
const unsigned new_value_num = search_name_hashtable(new_value);
unsigned new_value_num = search_name_hashtable(new_value);
unsigned want = get_status(status_node_num, 1);
unsigned flag = get_status(status_node_num, 2);
unsigned status = get_status(status_node_num, 3);
@@ -771,9 +780,10 @@ static void index_status_file(const char *filename)
status_node_t *status_node = NULL;
unsigned status_num;
//FIXME: dpkg 1.22.22 recreates empty /var/lib/dpkg/status if it's missing - does not fail
status_file = xfopen_for_read(filename);
while ((control_buffer = xmalloc_fgetline_str(status_file, "\n\n")) != NULL) {
const unsigned package_num = fill_package_struct(control_buffer);
unsigned package_num = fill_package_struct(control_buffer);
if (package_num != -1) {
status_node = xmalloc(sizeof(status_node_t));
/* fill_package_struct doesn't handle the status field */
@@ -799,7 +809,7 @@ static void write_buffer_no_status(FILE *new_status_file, const char *control_bu
char *name;
char *value;
int start = 0;
while (1) {
while (control_buffer[start]) {
start += read_package_field(&control_buffer[start], &name, &value);
if (name == NULL) {
break;
@@ -807,42 +817,42 @@ static void write_buffer_no_status(FILE *new_status_file, const char *control_bu
if (strcmp(name, "Status") != 0) {
fprintf(new_status_file, "%s: %s\n", name, value);
}
free(name);
free(value);
}
}
/* This could do with a cleanup */
static void write_status_file(deb_file_t **deb_file)
{
//FIXME: dpkg 1.22.22 recreates empty /var/lib/dpkg/status if it's missing - does not fail
FILE *old_status_file = xfopen_for_read("/var/lib/dpkg/status");
FILE *new_status_file = xfopen_for_write("/var/lib/dpkg/status.udeb");
char *package_name;
char *status_from_file;
char *control_buffer = NULL;
char *tmp_string;
char *control_buffer;
int status_num;
int field_start = 0;
int write_flag;
int i = 0;
int i;
/* Update previously known packages */
while ((control_buffer = xmalloc_fgetline_str(old_status_file, "\n\n")) != NULL) {
char *package_name;
char *status_from_file;
char *tmp_string;
int write_flag;
tmp_string = strstr(control_buffer, "Package:");
if (tmp_string == NULL) {
free(control_buffer);
continue;
}
tmp_string += 8;
tmp_string += strspn(tmp_string, " \n\t");
tmp_string = skip_whitespace(tmp_string + 8);
package_name = xstrndup(tmp_string, strcspn(tmp_string, "\n"));
write_flag = FALSE;
status_from_file = NULL;
tmp_string = strstr(control_buffer, "Status:");
if (tmp_string != NULL) {
/* Separate the status value from the control buffer */
tmp_string += 7;
tmp_string += strspn(tmp_string, " \n\t");
tmp_string = skip_whitespace(tmp_string + 7);
status_from_file = xstrndup(tmp_string, strcspn(tmp_string, "\n"));
} else {
status_from_file = NULL;
}
/* Find this package in the status hashtable */
@@ -851,7 +861,7 @@ static void write_status_file(deb_file_t **deb_file)
const char *status_from_hashtable = name_hashtable[status_hashtable[status_num]->status];
if (strcmp(status_from_file, status_from_hashtable) != 0) {
/* New status isn't exactly the same as old status */
const int state_status = get_status(status_num, 3);
int state_status = get_status(status_num, 3);
if ((strcmp("installed", name_hashtable[state_status]) == 0)
|| (strcmp("unpacked", name_hashtable[state_status]) == 0)
) {
@@ -870,7 +880,7 @@ static void write_status_file(deb_file_t **deb_file)
}
i++;
}
/* This is temperary, debugging only */
/* This is temporary, debugging only */
if (deb_file[i] == NULL) {
bb_error_msg_and_die("ALERT: cannot find a control file, "
"your status file may be broken, status may be "
@@ -878,14 +888,18 @@ static void write_status_file(deb_file_t **deb_file)
}
}
else if (strcmp("not-installed", name_hashtable[state_status]) == 0) {
int field_start = 0;
/* Only write the Package, Status, Priority and Section lines */
fprintf(new_status_file, "Package: %s\n", package_name);
fprintf(new_status_file, "Status: %s\n", status_from_hashtable);
while (1) {
while (control_buffer[field_start]) {
char *field_name;
char *field_value;
field_start += read_package_field(&control_buffer[field_start], &field_name, &field_value);
//FIXME: the questionable ": VALUE" lines (empty NAME)
//probably should not stop parsing of the entire file?
if (field_name == NULL) {
break;
}
@@ -894,13 +908,17 @@ static void write_status_file(deb_file_t **deb_file)
) {
fprintf(new_status_file, "%s: %s\n", field_name, field_value);
}
free(field_name);
free(field_value);
}
write_flag = TRUE;
fputs("\n", new_status_file);
}
else if (strcmp("config-files", name_hashtable[state_status]) == 0) {
int field_start = 0;
/* only change the status line */
while (1) {
while (control_buffer[field_start]) {
char *field_name;
char *field_value;
field_start += read_package_field(&control_buffer[field_start], &field_name, &field_value);
@@ -913,13 +931,15 @@ static void write_status_file(deb_file_t **deb_file)
} else {
fprintf(new_status_file, "%s: %s\n", field_name, field_value);
}
free(field_name);
free(field_value);
}
write_flag = TRUE;
fputs("\n", new_status_file);
}
}
}
/* If the package from the status file wasn't handle above, do it now*/
/* If the package from the status file wasn't handled above, do it now */
if (!write_flag) {
fprintf(new_status_file, "%s\n\n", control_buffer);
}
@@ -927,7 +947,7 @@ static void write_status_file(deb_file_t **deb_file)
free(status_from_file);
free(package_name);
free(control_buffer);
}
} /* while (control_buffer) */
/* Write any new packages */
for (i = 0; deb_file[i] != NULL; i++) {
@@ -994,14 +1014,14 @@ static int check_deps(deb_file_t **deb_file, int deb_start /*, int dep_max_count
/* Create array of package numbers to check against
* installed package for conflicts*/
while (deb_file[i] != NULL) {
const unsigned package_num = deb_file[i]->package;
unsigned package_num = deb_file[i]->package;
conflicts = xrealloc_vector(conflicts, 2, conflicts_num);
conflicts[conflicts_num] = package_num;
conflicts_num++;
/* add provides to conflicts list */
for (j = 0; j < package_hashtable[package_num]->num_of_edges; j++) {
if (package_hashtable[package_num]->edge[j]->type == EDGE_PROVIDES) {
const int conflicts_package_num = search_package_hashtable(
int conflicts_package_num = search_package_hashtable(
package_hashtable[package_num]->edge[j]->name,
package_hashtable[package_num]->edge[j]->version,
package_hashtable[package_num]->edge[j]->operator);
@@ -1036,7 +1056,7 @@ static int check_deps(deb_file_t **deb_file, int deb_start /*, int dep_max_count
const edge_t *package_edge = package_node->edge[j];
if (package_edge->type == EDGE_CONFLICTS) {
const unsigned package_num =
unsigned package_num =
search_package_hashtable(package_edge->name,
package_edge->version,
package_edge->operator);
@@ -1065,7 +1085,7 @@ static int check_deps(deb_file_t **deb_file, int deb_start /*, int dep_max_count
for (i = 0; i < PACKAGE_HASH_PRIME; i++) {
int status_num = 0;
int number_of_alternatives = 0;
const edge_t * root_of_alternatives = NULL;
const edge_t *root_of_alternatives = NULL;
const common_node_t *package_node = package_hashtable[i];
/* If the package node does not exist then this
@@ -1115,7 +1135,7 @@ static int check_deps(deb_file_t **deb_file, int deb_start /*, int dep_max_count
if (package_edge->type == EDGE_PRE_DEPENDS
|| package_edge->type == EDGE_DEPENDS
) {
int result=1;
int result = 1;
status_num = 0;
/* If we are inside an alternative then check
@@ -1381,12 +1401,12 @@ static void list_packages(const char *pattern)
}
}
static void remove_package(const unsigned package_num, int noisy)
static void remove_package(unsigned package_num, int noisy)
{
const char *package_name = name_hashtable[package_hashtable[package_num]->name];
const char *package_version = name_hashtable[package_hashtable[package_num]->version];
const unsigned status_num = search_status_hashtable(package_name);
const int package_name_length = strlen(package_name);
unsigned status_num = search_status_hashtable(package_name);
int package_name_length = strlen(package_name);
char **remove_files;
char **exclude_files;
char list_name[package_name_length + 25];
@@ -1432,11 +1452,11 @@ static void remove_package(const unsigned package_num, int noisy)
set_status(status_num, "config-files", 3);
}
static void purge_package(const unsigned package_num)
static void purge_package(unsigned package_num)
{
const char *package_name = name_hashtable[package_hashtable[package_num]->name];
const char *package_version = name_hashtable[package_hashtable[package_num]->version];
const unsigned status_num = search_status_hashtable(package_name);
unsigned status_num = search_status_hashtable(package_name);
char **remove_files;
char **exclude_files;
char list_name[strlen(package_name) + 25];
@@ -1654,8 +1674,8 @@ enum {
static void unpack_package(deb_file_t *deb_file)
{
const char *package_name = name_hashtable[package_hashtable[deb_file->package]->name];
const unsigned status_num = search_status_hashtable(package_name);
const unsigned status_package_num = status_hashtable[status_num]->package;
unsigned status_num = search_status_hashtable(package_name);
unsigned status_package_num = status_hashtable[status_num]->package;
char *info_prefix;
char *list_filename;
archive_handle_t *archive_handle;
@@ -1689,7 +1709,7 @@ static void unpack_package(deb_file_t *deb_file)
accept_list = NULL;
i = 0;
while (i < ARRAY_SIZE(all_control_files)) {
char *c = xasprintf("./%s", all_control_files[i]);
char *c = concat_path_file(".", all_control_files[i]);
llist_add_to(&accept_list, c);
i++;
}
@@ -1745,7 +1765,7 @@ static void configure_package(deb_file_t *deb_file)
{
const char *package_name = name_hashtable[package_hashtable[deb_file->package]->name];
const char *package_version = name_hashtable[package_hashtable[deb_file->package]->version];
const int status_num = search_status_hashtable(package_name);
int status_num = search_status_hashtable(package_name);
printf("Setting up %s (%s)...\n", package_name, package_version);
@@ -1786,6 +1806,24 @@ int dpkg_main(int argc UNUSED_PARAM, char **argv)
"force-confold\0" No_argument "\xfd"
;
#endif
//--admindir=DIR
// Set the administrative directory to DIR. This directory
// contains many files that give information about status of
// installed or uninstalled packages, etc. Defaults to
// /var/lib/dpkg if DPKG_ADMINDIR has not been set.
//--instdir=DIR
// Set the installation directory, which refers to the directory
// where packages are to be installed. DIR is also the
// directory passed to chroot(2) before running package's
// installation scripts, which means that the scripts see DIR
// as a root directory. Defaults to / if DPKG_ROOT has not
// been set (since dpkg 1.21.10).
//--root=DIR
// Set the root directory to DIR, which sets the
// installation directory to DIR and the administrative
// directory to DIR/var/lib/dpkg if DPKG_ROOT
// has not been set (since dpkg 1.21.10).
//TODO: implement --root=DIR? necessary for testing
INIT_G();
+1 -1
View File
@@ -5,7 +5,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config DPKG_DEB
//config: bool "dpkg-deb (30 kb)"
//config: bool "dpkg-deb (29 kb)"
//config: default y
//config: select FEATURE_SEAMLESS_GZ
//config: help
+3
View File
@@ -2215,6 +2215,9 @@ int gzip_main(int argc UNUSED_PARAM, char **argv)
};
#endif
// TODO: use less ugly "split-globals" trick via SET_OFFSET_PTR_TO_GLOBALS().
// The problem is, the current method strategically places G2.heap[]
// (~24 references) so that it has zero offset.
SET_PTR_TO_GLOBALS((char *)xzalloc(sizeof(struct globals)+sizeof(struct globals2))
+ sizeof(struct globals));
+3 -3
View File
@@ -12,6 +12,7 @@ COMMON_FILES:= \
data_extract_all.o \
data_extract_to_stdout.o \
\
unsafe_prefix.o \
unsafe_symlink_target.o \
\
filter_accept_all.o \
@@ -32,7 +33,6 @@ COMMON_FILES:= \
DPKG_FILES:= \
unpack_ar_archive.o \
filter_accept_list_reassign.o \
unsafe_prefix.o \
get_header_ar.o \
get_header_tar.o \
get_header_tar_gz.o \
@@ -47,7 +47,7 @@ lib-$(CONFIG_DPKG_DEB) += $(DPKG_FILES)
lib-$(CONFIG_AR) += get_header_ar.o unpack_ar_archive.o
lib-$(CONFIG_CPIO) += get_header_cpio.o
lib-$(CONFIG_TAR) += get_header_tar.o unsafe_prefix.o
lib-$(CONFIG_TAR) += get_header_tar.o
lib-$(CONFIG_FEATURE_TAR_TO_COMMAND) += data_extract_to_command.o
lib-$(CONFIG_LZOP) += lzo1x_1.o lzo1x_1o.o lzo1x_d.o
lib-$(CONFIG_UNLZOP) += lzo1x_1.o lzo1x_1o.o lzo1x_d.o
@@ -67,7 +67,7 @@ lib-$(CONFIG_FEATURE_UNZIP_XZ) += open_transformer.o decompress_unxz.o
# 'gzip -d', gunzip or zcat selects FEATURE_GZIP_DECOMPRESS
lib-$(CONFIG_FEATURE_GZIP_DECOMPRESS) += open_transformer.o decompress_gunzip.o
lib-$(CONFIG_UNCOMPRESS) += open_transformer.o decompress_uncompress.o
lib-$(CONFIG_UNZIP) += open_transformer.o decompress_gunzip.o unsafe_prefix.o
lib-$(CONFIG_UNZIP) += open_transformer.o decompress_gunzip.o
lib-$(CONFIG_RPM2CPIO) += open_transformer.o decompress_gunzip.o get_header_cpio.o
lib-$(CONFIG_RPM) += open_transformer.o decompress_gunzip.o get_header_cpio.o
lib-$(CONFIG_GZIP) += open_transformer.o
+13 -2
View File
@@ -65,6 +65,18 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
} while (--n != 0);
}
#endif
#if ENABLE_FEATURE_PATH_TRAVERSAL_PROTECTION
/* Skip leading "/" and past last ".." path component */
# if ENABLE_FEATURE_TAR_LONG_OPTIONS
dst_name = (char *)skip_unsafe_prefix(dst_name);
# else /* dst_name is file_header->name, which is free()d by e.g. cpio - must copy, can't just advance the ptr */
strip_unsafe_prefix(dst_name);
# endif
#endif
// ^^^ This may be a problem if some applets do need to extract absolute names.
// (Probably will need to invent ARCHIVE_ALLOW_UNSAFE_NAME flag).
// You might think that rpm needs it, but in my tests rpm's internal cpio
// archive has names like "./usr/bin/FOO", not "/usr/bin/FOO".
if (archive_handle->ah_flags & ARCHIVE_CREATE_LEADING_DIRS) {
char *slash = strrchr(dst_name, '/');
@@ -177,8 +189,7 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
/* To avoid a directory traversal attack via symlinks,
* do not restore symlinks with ".." components
* or symlinks starting with "/", unless a magic
* envvar is set.
* or symlinks starting with "/"
*
* For example, consider a .tar created via:
* $ tar cvf bug.tar anything.txt
+7 -8
View File
@@ -463,13 +463,12 @@ static int get_next_block(bunzip_data *bd)
symbols, but a run of length 0 doesn't mean anything in this
context). Thus space is saved. */
runCnt += (runPos << nextSym); /* +runPos if RUNA; +2*runPos if RUNB */
//The 32-bit overflow of runCnt wasn't yet seen, but probably can happen.
//This would be the fix (catches too large count way before it can overflow):
// if (runCnt > bd->dbufSize) {
// dbg("runCnt:%u > dbufSize:%u RETVAL_DATA_ERROR",
// runCnt, bd->dbufSize);
// return RETVAL_DATA_ERROR;
// }
/* Catch 32-bit overflow (we have an example .bz2 file) */
if ((int)runCnt < 0) {
dbg("runCnt:%u > dbufSize:%u RETVAL_DATA_ERROR",
runCnt, bd->dbufSize);
return RETVAL_DATA_ERROR;
}
if (runPos < bd->dbufSize) runPos <<= 1;
goto end_of_huffman_loop;
}
@@ -654,7 +653,7 @@ static int read_bunzip(bunzip_data *bd, char *outbuf, int len)
/* Subtract the 1 copy we'd output anyway to get extras */
--bd->writeCopies;
}
} /* for(;;) */
} /* for (;;) */
/* Decompression of this input block completed successfully */
bd->writeCRC = CRC = ~CRC;
+1 -1
View File
@@ -124,7 +124,7 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
typed->name[strcspn(typed->name, " /")] = '\0';
if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) {
archive_handle->action_header(typed);
archive_handle->action_header(archive_handle);
#if ENABLE_DPKG || ENABLE_DPKG_DEB
if (archive_handle->dpkg__sub_archive) {
struct archive_handle_t *sa = archive_handle->dpkg__sub_archive;
+1 -1
View File
@@ -125,7 +125,7 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
//cpio: etc/hosts not created: newer or same age file exists
//etc/hosts <-- should NOT show it
//2 blocks <-- should say "0 blocks"
archive_handle->action_header(file_header);
archive_handle->action_header(archive_handle);
} else {
data_skip(archive_handle);
}
+12 -3
View File
@@ -147,11 +147,13 @@ static void process_pax_hdr(archive_handle_t *archive_handle, unsigned sz, int g
#endif
}
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
static void die_if_bad_fnamesize(off_t sz)
{
if ((uoff_t)sz > 0xfff) /* more than 4k?! no funny business please */
bb_simple_error_msg_and_die("bad archive");
}
#endif
char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
{
@@ -452,15 +454,22 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
#endif
/* Everything up to and including last ".." component is stripped */
overlapping_strcpy(file_header->name, strip_unsafe_prefix(file_header->name));
//TODO: do the same for file_header->link_target?
strip_unsafe_prefix(file_header->name);
if (file_header->link_target && !S_ISLNK(file_header->mode)) {
/* GNU tar 1.34 examples:
* tar: Removing leading '/' from hard link targets
* tar: Removing leading '../' from hard link targets
* tar: Removing leading 'etc/../' from hard link targets
*/
strip_unsafe_prefix(file_header->link_target);
}
/* Strip trailing '/' in directories */
/* Must be done after mode is set as '/' is used to check if it's a directory */
cp = last_char_is(file_header->name, '/');
if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) {
archive_handle->action_header(/*archive_handle->*/ file_header);
archive_handle->action_header(archive_handle);
/* Note that we kill the '/' only after action_header() */
/* (like GNU tar 1.15.1: verbose mode outputs "dir/dir/") */
if (cp)
+7 -2
View File
@@ -5,8 +5,13 @@
#include "libbb.h"
#include "bb_archive.h"
void FAST_FUNC header_list(const file_header_t *file_header)
void FAST_FUNC header_list(archive_handle_t *archive_handle)
{
//TODO: cpio -vp DIR should output "DIR/NAME", not just "NAME" */
puts(file_header->name);
const file_header_t *file_header = archive_handle->file_header;
/* "tar xvOf TARFILE >OUTFILE" should use stderr for file list output: */
FILE *fp = (archive_handle->action_data == data_extract_to_stdout) ? stderr : stdout;
fprintf(fp, "%s\n", printable_string(file_header->name));
}
+1 -1
View File
@@ -5,6 +5,6 @@
#include "libbb.h"
#include "bb_archive.h"
void FAST_FUNC header_skip(const file_header_t *file_header UNUSED_PARAM)
void FAST_FUNC header_skip(archive_handle_t *archive_handle UNUSED_PARAM)
{
}
+10 -7
View File
@@ -5,11 +5,14 @@
#include "libbb.h"
#include "bb_archive.h"
void FAST_FUNC header_verbose_list(const file_header_t *file_header)
void FAST_FUNC header_verbose_list(archive_handle_t *archive_handle)
{
const file_header_t *file_header = archive_handle->file_header;
struct tm tm_time;
struct tm *ptm = &tm_time; //localtime(&file_header->mtime);
char modestr[12];
/* "tar xvvOf TARFILE >OUTFILE" should use stderr for file list output: */
FILE *fp = (archive_handle->action_data == data_extract_to_stdout) ? stderr : stdout;
#if ENABLE_FEATURE_TAR_UNAME_GNAME
char uid[sizeof(int)*3 + 2];
@@ -29,7 +32,7 @@ void FAST_FUNC header_verbose_list(const file_header_t *file_header)
/*sprintf(gid, "%u", (unsigned)file_header->gid);*/
group = utoa(file_header->gid);
}
printf("%s %s/%s %9"OFF_FMT"u %4u-%02u-%02u %02u:%02u:%02u %s",
fprintf(fp, "%s %s/%s %9"OFF_FMT"u %4u-%02u-%02u %02u:%02u:%02u %s",
bb_mode_string(modestr, file_header->mode),
user,
group,
@@ -40,13 +43,13 @@ void FAST_FUNC header_verbose_list(const file_header_t *file_header)
ptm->tm_hour,
ptm->tm_min,
ptm->tm_sec,
file_header->name);
printable_string(file_header->name));
#else /* !FEATURE_TAR_UNAME_GNAME */
localtime_r(&file_header->mtime, ptm);
printf("%s %u/%u %9"OFF_FMT"u %4u-%02u-%02u %02u:%02u:%02u %s",
fprintf(fp, "%s %u/%u %9"OFF_FMT"u %4u-%02u-%02u %02u:%02u:%02u %s",
bb_mode_string(modestr, file_header->mode),
(unsigned)file_header->uid,
(unsigned)file_header->gid,
@@ -57,13 +60,13 @@ void FAST_FUNC header_verbose_list(const file_header_t *file_header)
ptm->tm_hour,
ptm->tm_min,
ptm->tm_sec,
file_header->name);
printable_string(file_header->name));
#endif /* FEATURE_TAR_UNAME_GNAME */
/* NB: GNU tar shows "->" for symlinks and "link to" for hardlinks */
if (file_header->link_target) {
printf(" -> %s", file_header->link_target);
fprintf(fp, " -> %s", printable_string(file_header->link_target));
}
bb_putchar('\n');
putc('\n', fp);
}
-2
View File
@@ -797,7 +797,6 @@ static int lzo1x_999_compress_internal(const uint8_t *in, unsigned in_len,
if (swd->use_best_off)
better_match(swd, &m_len, &m_off);
#endif
/* shall we try a lazy match ? */
ahead = 0;
if (m_len >= max_lazy) {
@@ -811,7 +810,6 @@ static int lzo1x_999_compress_internal(const uint8_t *in, unsigned in_len,
max_ahead = LZO_MIN(2, (unsigned)l1 - 1);
}
while (ahead < max_ahead && c->look > m_len) {
int lazy_match_min_gain;
+14 -12
View File
@@ -157,7 +157,7 @@ void FAST_FUNC fork_transformer(int fd, const char *transform_prog)
/* Used by e.g. rpm which gives us a fd without filename,
* thus we can't guess the format from filename's extension.
*/
static transformer_state_t *setup_transformer_on_fd(int fd, int fail_if_not_compressed)
static transformer_state_t *setup_transformer_on_fd(int fd, int die_if_not_compressed)
{
transformer_state_t *xstate;
@@ -204,7 +204,7 @@ static transformer_state_t *setup_transformer_on_fd(int fd, int fail_if_not_comp
}
/* No known magic seen */
if (fail_if_not_compressed)
if (die_if_not_compressed)
bb_simple_error_msg_and_die("no gzip"
IF_FEATURE_SEAMLESS_BZ2("/bzip2")
IF_FEATURE_SEAMLESS_XZ("/xz")
@@ -240,13 +240,15 @@ static void fork_transformer_and_free(transformer_state_t *xstate)
/* Used by e.g. rpm which gives us a fd without filename,
* thus we can't guess the format from filename's extension.
*/
int FAST_FUNC setup_unzip_on_fd(int fd, int fail_if_not_compressed)
int FAST_FUNC setup_unzip_on_fd(int fd, int die_if_not_compressed)
{
transformer_state_t *xstate = setup_transformer_on_fd(fd, fail_if_not_compressed);
transformer_state_t *xstate = setup_transformer_on_fd(fd, die_if_not_compressed);
if (!xstate->xformer) {
/* Not compressed */
int retval = xstate->signature_skipped; /* never zero */
free(xstate);
return 1;
return retval;
}
fork_transformer_and_free(xstate);
@@ -264,7 +266,7 @@ void FAST_FUNC setup_lzma_on_fd(int fd)
}
#endif
static transformer_state_t *open_transformer(const char *fname, int fail_if_not_compressed)
static transformer_state_t *open_transformer(const char *fname, int die_if_not_compressed)
{
transformer_state_t *xstate;
int fd;
@@ -284,18 +286,18 @@ static transformer_state_t *open_transformer(const char *fname, int fail_if_not_
}
}
xstate = setup_transformer_on_fd(fd, fail_if_not_compressed);
xstate = setup_transformer_on_fd(fd, die_if_not_compressed);
return xstate;
}
int FAST_FUNC open_zipped(const char *fname, int fail_if_not_compressed)
int FAST_FUNC open_zipped(const char *fname, int die_if_not_compressed)
{
int fd;
transformer_state_t *xstate;
xstate = open_transformer(fname, fail_if_not_compressed);
if (!xstate)
xstate = open_transformer(fname, die_if_not_compressed);
if (!xstate) /* open error */
return -1;
fd = xstate->src_fd;
@@ -326,7 +328,7 @@ void* FAST_FUNC xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_
transformer_state_t *xstate;
char *image;
xstate = open_transformer(fname, /*fail_if_not_compressed:*/ 0);
xstate = open_transformer(fname, /*die_if_not_compressed:*/ 0);
if (!xstate) /* file open error */
return NULL;
@@ -371,7 +373,7 @@ void* FAST_FUNC xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_
int fd;
char *image;
fd = open_zipped(fname, /*fail_if_not_compressed:*/ 0);
fd = open_zipped(fname, /*die_if_not_compressed:*/ 0);
if (fd < 0)
return NULL;
+36 -6
View File
@@ -5,23 +5,48 @@
#include "libbb.h"
#include "bb_archive.h"
const char* FAST_FUNC strip_unsafe_prefix(const char *str)
const char* FAST_FUNC skip_unsafe_prefix(const char *str)
{
const char *cp = str;
/* if "..": malicious, return "" */
/* (causes harmless errors trying to create or hardlink a file named "") */
if (cp[0] == '.' && cp[1] == '.' && cp[2] == '\0')
return cp + 2;
while (1) {
char *cp2;
const char *cp2;
if (*cp == '/') {
cp++;
continue;
}
if (is_prefixed_with(cp, "/../"+1)) {
/* We are called lots of times.
* is_prefixed_with(cp, "../") is slower than open-coding it,
* with minimal code growth (~few bytes).
*/
if (cp[0] == '.' && cp[1] == '.' && cp[2] == '/') {
cp += 3;
continue;
}
cp2 = strstr(cp, "/../");
cp2 = cp;
find_dotdot:
cp2 = strstr(cp2, "/..");
if (!cp2)
break;
cp = cp2 + 4;
break; /* No (more) malicious components */
/* We found "/..something" */
cp2 += 3;
if (*cp2 != '/') {
if (*cp2 == '\0') {
/* Trailing "/..": malicious, return "" */
/* (causes harmless errors trying to create or hardlink a file named "") */
return cp2;
}
/* "/..name" is not malicious, look for next "/.." */
goto find_dotdot;
}
/* Found "/../": malicious, advance past it */
cp = cp2 + 1;
}
if (cp != str) {
static smallint warned = 0;
@@ -33,3 +58,8 @@ const char* FAST_FUNC strip_unsafe_prefix(const char *str)
}
return cp;
}
void FAST_FUNC strip_unsafe_prefix(char *str)
{
overlapping_strcpy(str, skip_unsafe_prefix(str));
}
+47 -7
View File
@@ -17,25 +17,65 @@ void FAST_FUNC create_or_remember_link(llist_t **link_placeholders,
return;
}
if (symlink(target, linkname) != 0) {
/* shared message */
// shared message
bb_perror_msg_and_die("can't create %slink '%s' to '%s'",
"sym", linkname, target
);
}
}
static int all_dir_components_are_dirs(char *path)
{
struct stat sb;
char *slash;
slash = path;
while ((slash = strchr(slash, '/')) != NULL) {
int ok;
*slash = '\0';
ok = (lstat(path, &sb) == 0 && S_ISDIR(sb.st_mode));
*slash++ = '/';
if (!ok)
return 0;
}
return 1;
}
void FAST_FUNC create_links_from_list(llist_t *list)
{
// This idea sounds better (fewer file ops):
// Create hardlinks first, then symlinks.
// ^^^ but it breaks the "hardlink to symlink" case:
// mkdir dir
// >dir/a
// ln -s ../dir/a dir/b
// ln dir/b dir/c
// mkdir new; tar cf - dir/a dir/b dir/c | tar -C new -xvf -
// On extract, 'c' will have no 'b' to be a hardlink to.
while (list) {
char *target;
char *linkname = list->data + 1;
target = list->data + 1 + strlen(list->data + 1) + 1;
if ((*list->data ? link : symlink) (target, list->data + 1)) {
/* shared message */
bb_error_msg_and_die("can't create %slink '%s' to '%s'",
*list->data ? "hard" : "sym",
list->data + 1, target
target = linkname + strlen(linkname) + 1;
// Check whether the linkname has suspicious components:
// SYMLINK_OUTSIDE_EXTRACT_DIR/etc/passwd sort of thing.
// (Our delayed creation of symlinks is not defending against it,
// we could create SYMLINK_OUTSIDE_EXTRACT_DIR ourself!)
if (!all_dir_components_are_dirs(linkname)) {
errno = ENOTDIR;
goto err;
}
if ((list->data[0] ? link : symlink) (target, linkname)) {
// shared message
err:
bb_perror_msg_and_die("can't create %slink '%s' to '%s'",
list->data[0] ? "hard" : "sym",
linkname, target
);
// Note: GNU tar 1.34 errors out only _after_ all links are (attempted to be) created
// We bail out at once
}
list = list->link;
}
+7 -8
View File
@@ -25,7 +25,7 @@
"Minimalized" for busybox by Alain Knaff
*/
//config:config LZOP
//config: bool "lzop (12 kb)"
//config: bool "lzop (13 kb)"
//config: default y
//config: help
//config: Lzop compression/decompresion.
@@ -154,7 +154,7 @@ static NOINLINE int lzo1x_optimize(uint8_t *in, unsigned in_len,
unsigned lit = 0;
unsigned next_lit = NO_LIT;
unsigned nl;
unsigned long o_m1_a = 0, o_m1_b = 0, o_m2 = 0, o_m3_a = 0, o_m3_b = 0;
// unsigned long o_m1_a = 0, o_m1_b = 0, o_m2 = 0, o_m3_a = 0, o_m3_b = 0;
// LZO_UNUSED(wrkmem);
@@ -208,7 +208,6 @@ static NOINLINE int lzo1x_optimize(uint8_t *in, unsigned in_len,
lit = 0;
goto match_done;
/* handle matches */
do {
if (t < 16) { /* a M1 match */
@@ -228,7 +227,7 @@ static NOINLINE int lzo1x_optimize(uint8_t *in, unsigned in_len,
*litp = (unsigned char)((*litp & ~3) | lit);
/* copy over the 2 literals that replace the match */
copy2(ip-2, m_pos, pd(op, m_pos));
o_m1_a++;
// o_m1_a++;
}
/* test if a literal run follows */
else
@@ -250,7 +249,7 @@ static NOINLINE int lzo1x_optimize(uint8_t *in, unsigned in_len,
lit += 2 + t + 3;
*litp = (unsigned char)(lit - 3);
o_m1_b++;
// o_m1_b++;
*op++ = *m_pos++;
*op++ = *m_pos++;
goto copy_literal_run;
@@ -285,7 +284,7 @@ static NOINLINE int lzo1x_optimize(uint8_t *in, unsigned in_len,
/* set new length of previous literal run */
lit += 3 + t + 3;
*litp = (unsigned char)(lit - 3);
o_m2++;
// o_m2++;
*op++ = *m_pos++;
*op++ = *m_pos++;
*op++ = *m_pos++;
@@ -331,7 +330,7 @@ static NOINLINE int lzo1x_optimize(uint8_t *in, unsigned in_len,
*litp = (unsigned char)((*litp & ~3) | lit);
/* copy over the 3 literals that replace the match */
copy3(ip-3, m_pos, pd(op, m_pos));
o_m3_a++;
// o_m3_a++;
}
/* test if a literal run follows */
else if (t == 1 && lit <= 3 && nl == 0
@@ -350,7 +349,7 @@ static NOINLINE int lzo1x_optimize(uint8_t *in, unsigned in_len,
lit += 3 + t + 3;
*litp = (unsigned char)(lit - 3);
o_m3_b++;
// o_m3_b++;
*op++ = *m_pos++;
*op++ = *m_pos++;
*op++ = *m_pos++;
+15 -4
View File
@@ -116,8 +116,13 @@ static int rpm_gettags(const char *filename)
xread(fd, &header, sizeof(header));
if (header.magic_and_ver != htonl(RPM_HEADER_MAGICnVER))
bb_error_msg_and_die("invalid RPM header magic in '%s'", filename);
#if BB_LITTLE_ENDIAN
header.size = ntohl(header.size);
#endif
cnt = ntohl(header.entries);
/* Prevent multiplication overflow leading to undersized allocations */
if (sizeof(cnt) <= 4 && cnt >= 0x00400000) /* ~4 million */
bb_error_msg_and_die("bad RPM header.entries:%u", cnt);
storepos += sizeof(header) + cnt * 16;
G.tagcount += cnt;
@@ -125,9 +130,11 @@ static int rpm_gettags(const char *filename)
xread(fd, &tags[idx], sizeof(tags[0]) * cnt);
while (cnt--) {
rpm_index *tag = &tags[idx];
#if BB_LITTLE_ENDIAN
tag->tag = ntohl(tag->tag);
tag->type = ntohl(tag->type);
tag->count = ntohl(tag->count);
#endif
tag->offset = storepos + ntohl(tag->offset);
if (pass == 0)
tag->tag -= 743;
@@ -146,7 +153,6 @@ static int rpm_gettags(const char *filename)
storepos = (storepos + G_pagesize) & -(int)G_pagesize;
/* remember size for munmap */
G.mapsize = storepos;
/* some NOMMU systems prefer MAP_PRIVATE over MAP_SHARED */
G.map = mmap_read(fd, storepos);
if (G.map == MAP_FAILED)
bb_perror_msg_and_die("mmap '%s'", filename);
@@ -316,7 +322,7 @@ static void extract_cpio(int fd, const char *source_rpm)
archive_handle->src_fd = fd;
/*archive_handle->offset = 0; - init_handle() did it */
setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_compressed:*/ 1);
setup_unzip_on_fd(archive_handle->src_fd, /*die_if_not_compressed:*/ 1);
while (get_header_cpio(archive_handle) == EXIT_SUCCESS)
continue;
}
@@ -533,15 +539,20 @@ int rpm2cpio_main(int argc UNUSED_PARAM, char **argv)
// /* We need to know whether child (gzip/bzip/etc) exits abnormally */
// signal(SIGCHLD, check_errors_in_children);
str = rpm_getstr0(TAG_PAYLOADCOMPRESSOR);
if (ENABLE_FEATURE_SEAMLESS_LZMA
&& (str = rpm_getstr0(TAG_PAYLOADCOMPRESSOR)) != NULL
&& str != NULL
&& strcmp(str, "lzma") == 0
) {
// lzma compression can't be detected
// set up decompressor without detection
setup_lzma_on_fd(rpm_fd);
} else {
setup_unzip_on_fd(rpm_fd, /*fail_if_not_compressed:*/ 1);
int signature_bytes = setup_unzip_on_fd(rpm_fd, /*die_if_not_compressed:*/ 0);
if (signature_bytes != 0) {
xlseek(rpm_fd, - signature_bytes, SEEK_CUR);
bb_error_msg("warning, unknown compression '%s'", str);
}
}
if (bb_copyfd_eof(rpm_fd, STDOUT_FILENO) < 0)
+8 -4
View File
@@ -119,6 +119,7 @@
#include "libbb.h"
#include "common_bufsiz.h"
#include "bb_archive.h"
#include "unicode.h"
/* FIXME: Stop using this non-standard feature */
#ifndef FNM_LEADING_DIR
# define FNM_LEADING_DIR 0
@@ -427,7 +428,7 @@ static int writeTarHeader(struct TarBallInfo *tbInfo,
/* GNU "tar cvvf" prints "extended" listing a-la "ls -l" */
/* We don't have such excesses here: for us "v" == "vv" */
/* '/' is probably a GNUism */
fprintf(vbFd, "%s%s\n", header_name,
fprintf(vbFd, "%s%s\n", printable_string(header_name),
S_ISDIR(statbuf->st_mode) ? "/" : "");
}
@@ -475,7 +476,7 @@ static int FAST_FUNC writeFileToTarball(struct recursive_state *state,
DBG("writeFileToTarball('%s')", fileName);
/* Strip leading '/' and such (must be before memorizing hardlink's name) */
header_name = strip_unsafe_prefix(fileName);
header_name = skip_unsafe_prefix(fileName);
if (header_name[0] == '\0')
return TRUE;
@@ -621,7 +622,7 @@ static void NOINLINE vfork_compressor(int tar_fd, const char *gzip)
execlp(gzip, gzip, "-f", (char *)0);
vfork_exec_errno = errno;
_exit(EXIT_FAILURE);
_exit_FAILURE();
}
/* parent */
@@ -1133,6 +1134,9 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
if (tar_handle->accept || tar_handle->reject)
tar_handle->filter = filter_accept_reject_list;
/* For "tar xvf/tvf" output and Unicode in names */
init_unicode();
/* Open the tar file */
{
int tar_fd = STDIN_FILENO;
@@ -1164,7 +1168,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
* on e.g. tarball with 1st file named "BZh5".
*/
) {
tar_handle->src_fd = open_zipped(tar_filename, /*fail_if_not_compressed:*/ 0);
tar_handle->src_fd = open_zipped(tar_filename, /*die_if_not_compressed:*/ 0);
if (tar_handle->src_fd < 0)
bb_perror_msg_and_die("can't open '%s'", tar_filename);
} else {
+22 -4
View File
@@ -56,7 +56,7 @@
//kbuild:lib-$(CONFIG_UNZIP) += unzip.o
//usage:#define unzip_trivial_usage
//usage: "[-lnojpq] FILE[.zip] [FILE]... [-x FILE]... [-d DIR]"
//usage: "[-lnojpqK] FILE[.zip] [FILE]... [-x FILE]... [-d DIR]"
//usage:#define unzip_full_usage "\n\n"
//usage: "Extract FILEs from ZIP archive\n"
//usage: "\n -l List contents (with -q for short form)"
@@ -66,6 +66,7 @@
//usage: "\n -p Write to stdout"
//usage: "\n -t Test"
//usage: "\n -q Quiet"
//usage: "\n -K Do not clear SUID bit"
//usage: "\n -x FILE Exclude FILEs"
//usage: "\n -d DIR Extract into DIR"
@@ -118,6 +119,8 @@ typedef union {
#define FIX_ENDIANNESS_ZIP(zip) \
do { if (BB_BIG_ENDIAN) { \
(zip).fmt.method = SWAP_LE16((zip).fmt.method ); \
(zip).fmt.modtime = SWAP_LE16((zip).fmt.modtime ); \
(zip).fmt.moddate = SWAP_LE16((zip).fmt.moddate ); \
(zip).fmt.crc32 = SWAP_LE32((zip).fmt.crc32 ); \
(zip).fmt.cmpsize = SWAP_LE32((zip).fmt.cmpsize ); \
(zip).fmt.ucmpsize = SWAP_LE32((zip).fmt.ucmpsize ); \
@@ -492,6 +495,7 @@ int unzip_main(int argc, char **argv)
OPT_l = (1 << 0),
OPT_x = (1 << 1),
OPT_j = (1 << 2),
OPT_K = (1 << 3),
};
unsigned opts;
smallint quiet = 0;
@@ -555,9 +559,14 @@ int unzip_main(int argc, char **argv)
* 204372 1 file
*/
//TODO: accept and ignore these?
// -a convert to text files with 't' label, -aa: all files
// -b do not convert to text - bbox: we don't convert anything
// -D skip restoration of timestamps for extracted items - bbox: we don't restore these (yet?)
// -X restore user:group ownership
opts = 0;
/* '-' makes getopt return 1 for non-options */
while ((i = getopt(argc, argv, "-d:lnotpqxjv")) != -1) {
while ((i = getopt(argc, argv, "-d:lnotpqxjvK")) != -1) {
switch (i) {
case 'd': /* Extract to base directory */
base_dir = optarg;
@@ -579,6 +588,7 @@ int unzip_main(int argc, char **argv)
xmove_fd(xopen("/dev/null", O_WRONLY), STDOUT_FILENO);
/*fallthrough*/
// NB: -c extract files to stdout/screen (unlike -p, also prints .zip and file names to stdout)
case 'p': /* Extract files to stdout */
dst_fd = STDOUT_FILENO;
/*fallthrough*/
@@ -600,6 +610,10 @@ int unzip_main(int argc, char **argv)
opts |= OPT_j;
break;
case 'K':
opts |= OPT_K;
break;
case 1:
if (!src_fn) {
/* The zip file */
@@ -817,7 +831,10 @@ int unzip_main(int argc, char **argv)
# endif
if ((cdf.fmt.version_made_by >> 8) == 3) {
/* This archive is created on Unix */
dir_mode = file_mode = (cdf.fmt.external_attributes >> 16);
file_mode = (cdf.fmt.external_attributes >> 16);
if (!(opts & OPT_K))
file_mode &= ~(mode_t)(S_ISUID | S_ISGID);
dir_mode = file_mode;
}
}
#endif
@@ -842,7 +859,8 @@ int unzip_main(int argc, char **argv)
unzip_skip(zip.fmt.extra_len);
/* Guard against "/abspath", "/../" and similar attacks */
overlapping_strcpy(dst_fn, strip_unsafe_prefix(dst_fn));
// NB: UnZip 6.00 has option -: to disable this
strip_unsafe_prefix(dst_fn);
/* Filter zip entries */
if (find_list_entry(zreject, dst_fn)
+47
View File
@@ -0,0 +1,47 @@
/* Add SORT_BY_ALIGNMENT to linker script (found in busybox_unstripped.out):
## .rodata : { *(.rodata SORT_BY_ALIGNMENT(.rodata.*) .gnu.linkonce.r.*) }
## .data : { *(.data SORT_BY_ALIGNMENT(.data.*) .gnu.linkonce.d.*) }
## .bss : { *(.bss SORT_BY_ALIGNMENT(.bss.*) .gnu.linkonce.b.*) }
## This will eliminate most of the padding (~3kb).
## Hmm, "ld --sort-section alignment" should do it too.
##
## There is a ld hack which is meant to decrease disk usage
## at the cost of more RAM usage (??!!) in standard ld script:
## . = ALIGN (0x1000) - ((0x1000 - .) & (0x1000 - 1)); . = DATA_SEGMENT_ALIGN (0x1000, 0x1000);
## Replace it with:
## . = ALIGN (0x1000); . = DATA_SEGMENT_ALIGN (0x1000, 0x1000);
## to unconditionally align .data to the next page boundary,
## instead of "next page, plus current offset in this page"
*/
/* To reduce the number of VMAs each bbox process has,
## move *(.bss SORT_BY_ALIGNMENT(.bss.*) ...)
## part from .bss : {...} block to .data : { ... } block.
## (This usually increases .data section by only one page).
## Result:
##
## text data bss dec hex filename
## 1050792 560 7580 1058932 102874 busybox.bss
## 1050792 8149 0 1058941 10287d busybox.nobss
##
## $ exec busybox.bss pmap $$
## 0000000008048000 1028K r-xp /path/to/busybox.bss
## 0000000008149000 8K rw-p /path/to/busybox.bss
## 000000000814b000 4K rw-p [ anon ] <---- this VMA is eliminated
## 00000000085f5000 4K ---p [heap]
## 00000000085f6000 4K rw-p [heap]
## 00000000f7778000 8K rw-p [ anon ]
## 00000000f777a000 12K r--p [vvar]
## 00000000f777d000 8K r-xp [vdso]
## 00000000ff7e9000 132K rw-p [stack]
##
## $ exec busybox.nobss pmap $$
## 0000000008048000 1028K r-xp /path/to/busybox.nobss
## 0000000008149000 12K rw-p /path/to/busybox.nobss
## 00000000086f0000 4K ---p [heap]
## 00000000086f1000 4K rw-p [heap]
## 00000000f7783000 8K rw-p [ anon ]
## 00000000f7785000 12K r--p [vvar]
## 00000000f7788000 8K r-xp [vdso]
## 00000000ffac0000 132K rw-p [stack]
*/
+1
View File
@@ -703,6 +703,7 @@ CONFIG_FEATURE_INETD_RPC=y
CONFIG_IP=y
CONFIG_FEATURE_IP_ADDRESS=y
CONFIG_FEATURE_IP_LINK=y
CONFIG_FEATURE_IP_LINK_CAN=y
CONFIG_FEATURE_IP_ROUTE=y
CONFIG_FEATURE_IP_TUNNEL=y
CONFIG_FEATURE_IP_RULE=y
+605 -367
View File
File diff suppressed because it is too large. Load diff
+1 -1
View File
@@ -7,7 +7,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config CHVT
//config: bool "chvt (2 kb)"
//config: bool "chvt (2.2 kb)"
//config: default y
//config: help
//config: This program is used to change to another terminal.
+1 -1
View File
@@ -7,7 +7,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config CLEAR
//config: bool "clear (tiny)"
//config: bool "clear (371 bytes)"
//config: default y
//config: help
//config: This program clears the terminal screen.
+1 -1
View File
@@ -8,7 +8,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config DEALLOCVT
//config: bool "deallocvt (1.9 kb)"
//config: bool "deallocvt (2.2 kb)"
//config: default y
//config: help
//config: This program deallocates unused virtual consoles.
+1 -1
View File
@@ -7,7 +7,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config DUMPKMAP
//config: bool "dumpkmap (1.6 kb)"
//config: bool "dumpkmap (1.9 kb)"
//config: default y
//config: help
//config: This program dumps the kernel's keyboard translation table to
+1 -1
View File
@@ -7,7 +7,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config FGCONSOLE
//config: bool "fgconsole (1.5 kb)"
//config: bool "fgconsole (1.8 kb)"
//config: default y
//config: help
//config: This program prints active (foreground) console number.
+1 -1
View File
@@ -9,7 +9,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config KBD_MODE
//config: bool "kbd_mode (4.1 kb)"
//config: bool "kbd_mode (4.3 kb)"
//config: default y
//config: help
//config: This program reports and sets keyboard mode.
+1 -1
View File
@@ -10,7 +10,7 @@
* Licensed under GPLv2, see file LICENSE in this source tree.
*/
//config:config LOADFONT
//config: bool "loadfont (5.2 kb)"
//config: bool "loadfont (5.4 kb)"
//config: default y
//config: help
//config: This program loads a console font from standard input.
+1 -1
View File
@@ -7,7 +7,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config LOADKMAP
//config: bool "loadkmap (1.8 kb)"
//config: bool "loadkmap (2.1 kb)"
//config: default y
//config: help
//config: This program loads a keyboard translation table from
+1 -1
View File
@@ -8,7 +8,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config OPENVT
//config: bool "openvt (7.2 kb)"
//config: bool "openvt (7.4 kb)"
//config: default y
//config: help
//config: This program is used to start a command on an unused
+3 -3
View File
@@ -8,7 +8,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config RESET
//config: bool "reset (345 bytes)"
//config: bool "reset (676 bytes)"
//config: default y
//config: help
//config: This program is used to reset the terminal screen, if it
@@ -21,7 +21,7 @@
//usage:#define reset_trivial_usage
//usage: ""
//usage:#define reset_full_usage "\n\n"
//usage: "Reset the screen"
//usage: "Reset terminal (ESC codes) and termios (signals, buffering, echo)"
/* "Standard" version of this tool is in ncurses package */
@@ -36,7 +36,7 @@ int stty_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int reset_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int reset_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
{
static const char *const args[] = {
static const char *const args[] ALIGN_PTR = {
"stty", "sane", NULL
};
+2 -2
View File
@@ -7,7 +7,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config RESIZE
//config: bool "resize (903 bytes)"
//config: bool "resize (1.2 kb)"
//config: default y
//config: help
//config: This program is used to (re)set the width and height of your current
@@ -45,7 +45,7 @@ static void
onintr(int sig UNUSED_PARAM)
{
tcsetattr(STDERR_FILENO, TCSANOW, old_termios_p);
_exit(EXIT_FAILURE);
_exit_FAILURE();
}
int resize_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+1 -1
View File
@@ -8,7 +8,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config SETCONSOLE
//config: bool "setconsole (3.6 kb)"
//config: bool "setconsole (3.8 kb)"
//config: default y
//config: help
//config: Redirect writes to /dev/console to another device,
+1 -1
View File
@@ -9,7 +9,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config SETKEYCODES
//config: bool "setkeycodes (2.1 kb)"
//config: bool "setkeycodes (2.4 kb)"
//config: default y
//config: help
//config: This program loads entries into the kernel's scancode-to-keycode
+1 -1
View File
@@ -9,7 +9,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config SETLOGCONS
//config: bool "setlogcons (1.8 kb)"
//config: bool "setlogcons (2 kb)"
//config: default y
//config: help
//config: This program redirects the output console of kernel messages.
+3 -3
View File
@@ -7,7 +7,7 @@
* Licensed under GPLv2, see file LICENSE in this source tree.
*/
//config:config SHOWKEY
//config: bool "showkey (4.7 kb)"
//config: bool "showkey (4.9 kb)"
//config: default y
//config: help
//config: Shows keys pressed.
@@ -70,8 +70,8 @@ int showkey_main(int argc UNUSED_PARAM, char **argv)
INIT_G();
// FIXME: aks are all mutually exclusive
getopt32(argv, "aks");
// a,k,s are all mutually exclusive
getopt32(argv, "^" "aks" "\0" "a--ks:k--as:s--ak");
// prepare for raw mode
xget1(&tio, &tio0);
+1 -1
View File
@@ -14,7 +14,7 @@
* 3) Save some space by using strcmp(). Calling strncmp() here was silly.
*/
//config:config BASENAME
//config: bool "basename (438 bytes)"
//config: bool "basename (3.7 kb)"
//config: default y
//config: help
//config: basename is used to strip the directory and suffix from filenames,
+1 -1
View File
@@ -7,7 +7,7 @@
* Licensed under GPLv2, see file LICENSE in this source tree.
*/
//config:config CAT
//config: bool "cat (5.6 kb)"
//config: bool "cat (5.8 kb)"
//config: default y
//config: help
//config: cat is used to concatenate files and print them to the standard
+1 -1
View File
@@ -7,7 +7,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config CHROOT
//config: bool "chroot (3.7 kb)"
//config: bool "chroot (4 kb)"
//config: default y
//config: help
//config: chroot is used to change the root directory and run a command.
+3 -3
View File
@@ -7,11 +7,11 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config CKSUM
//config: bool "cksum (4.1 kb)"
//config: bool "cksum (4.3 kb)"
//config: default y
//config:
//config:config CRC32
//config: bool "crc32 (4.1 kb)"
//config: bool "crc32 (4.2 kb)"
//config: default y
// APPLET_NOEXEC:name main location suid_type help
@@ -39,7 +39,7 @@ int cksum_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int cksum_main(int argc UNUSED_PARAM, char **argv)
{
uint32_t *crc32_table = crc32_filltable(NULL, IS_CKSUM);
int exit_code = EXIT_SUCCESS;
exitcode_t exit_code = EXIT_SUCCESS;
#if ENABLE_DESKTOP
getopt32(argv, ""); /* cksum coreutils 6.9 compat */
+1 -1
View File
@@ -7,7 +7,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config COMM
//config: bool "comm (4.2 kb)"
//config: bool "comm (4.4 kb)"
//config: default y
//config: help
//config: comm is used to compare two files line by line and return
+30 -1
View File
@@ -29,6 +29,11 @@
//config: bool "Enable --reflink[=auto]"
//config: default y
//config: depends on FEATURE_CP_LONG_OPTIONS
//config:
//config:config FEATURE_CP_SPARSE
//config: bool "Enable --sparse=WHEN"
//config: default y
//config: depends on FEATURE_CP_LONG_OPTIONS
//applet:IF_CP(APPLET_NOEXEC(cp, cp, BB_DIR_BIN, BB_SUID_DROP, cp))
/* NOEXEC despite cases when it can be a "runner" (cp -r LARGE_DIR NEW_DIR) */
@@ -108,6 +113,8 @@
#include "libbb.h"
#include "libcoreutils/coreutils.h"
#define DBG_OPTION_PARSING 0
/* This is a NOEXEC applet. Be very careful! */
int cp_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
@@ -129,6 +136,9 @@ int cp_main(int argc, char **argv)
};
# if ENABLE_FEATURE_CP_REFLINK
char *reflink = NULL;
# endif
# if ENABLE_FEATURE_CP_SPARSE
char *sparse = NULL;
# endif
flags = getopt32long(argv, "^"
FILEUTILS_CP_OPTSTR
@@ -158,12 +168,20 @@ int cp_main(int argc, char **argv)
"parents\0" No_argument "\xfe"
# if ENABLE_FEATURE_CP_REFLINK
"reflink\0" Optional_argument "\xfd"
# endif
# if ENABLE_FEATURE_CP_SPARSE
"sparse\0" Required_argument "\xfc"
# endif
, &last
# if ENABLE_FEATURE_CP_REFLINK
, &reflink
# endif
# if ENABLE_FEATURE_CP_SPARSE
// NOP for now
, &sparse
# endif
);
# if ENABLE_FEATURE_CP_REFLINK
BUILD_BUG_ON((int)OPT_reflink != (int)FILEUTILS_REFLINK);
if (flags & FILEUTILS_REFLINK) {
@@ -175,6 +193,16 @@ int cp_main(int argc, char **argv)
bb_show_usage();
}
# endif
# if DBG_OPTION_PARSING
bb_error_msg("flags: 0x%08x", flags);
# define showopt(o) bb_error_msg("flags & %s(%x):\t%x", #o, o, flags & o);
showopt(FILEUTILS_RMDEST );
showopt(OPT_parents );
showopt(OPT_reflink );
showopt(FILEUTILS_REFLINK_ALWAYS);
return 0;
# undef showopt
# endif
#else
flags = getopt32(argv, "^"
FILEUTILS_CP_OPTSTR
@@ -215,7 +243,8 @@ int cp_main(int argc, char **argv)
(flags & FILEUTILS_DEREFERENCE) ? stat : lstat);
if (s_flags < 0) /* error other than ENOENT */
return EXIT_FAILURE;
d_flags = cp_mv_stat(last, &dest_stat);
d_flags = cp_mv_stat2(last, &dest_stat,
(flags & FILEUTILS_NO_TARGET_DIR) ? lstat : stat);
if (d_flags < 0) /* error other than ENOENT */
return EXIT_FAILURE;
+272 -168
View File
@@ -9,7 +9,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config CUT
//config: bool "cut (5.8 kb)"
//config: bool "cut (6.7 kb)"
//config: default y
//config: help
//config: cut is used to print selected parts of lines from
@@ -27,21 +27,34 @@
//kbuild:lib-$(CONFIG_CUT) += cut.o
//usage:#define cut_trivial_usage
//usage: "[OPTIONS] [FILE]..."
//usage: "{-b|c LIST | -f"IF_FEATURE_CUT_REGEX("|F")" LIST [-d SEP] [-s]} [-D] [-O SEP] [FILE]..."
// --output-delimiter SEP is too long to fit into 80 char-wide help ----------------^^^^^^^^
//usage:#define cut_full_usage "\n\n"
//usage: "Print selected fields from FILEs to stdout\n"
//usage: "\n -b LIST Output only bytes from LIST"
//usage: "\n -c LIST Output only characters from LIST"
//usage: "\n -d SEP Field delimiter for input (default -f TAB, -F run of whitespace)"
//usage: "\n -O SEP Field delimeter for output (default = -d for -f, one space for -F)"
//usage: "\n -D Don't sort/collate sections or match -fF lines without delimeter"
//usage: IF_FEATURE_CUT_REGEX(
//usage: "\n -d SEP Input field delimiter (default -f TAB, -F run of whitespace)"
//usage: ) IF_NOT_FEATURE_CUT_REGEX(
//usage: "\n -d SEP Input field delimiter (default TAB)"
//usage: )
//usage: "\n -f LIST Print only these fields (-d is single char)"
//usage: IF_FEATURE_CUT_REGEX(
//usage: "\n -F LIST Print only these fields (-d is regex)"
//usage: )
//usage: "\n -s Output only lines containing delimiter"
//usage: "\n -s Drop lines with no delimiter (else print them in full)"
//usage: "\n -D Don't sort ranges; line without delimiters has one field"
//usage: IF_LONG_OPTS(
//usage: "\n --output-delimiter SEP Output field delimeter"
//usage: ) IF_NOT_LONG_OPTS(
//usage: IF_FEATURE_CUT_REGEX(
//usage: "\n -O SEP Output field delimeter (default = -d for -f, one space for -F)"
//usage: ) IF_NOT_FEATURE_CUT_REGEX(
//usage: "\n -O SEP Output field delimeter (default = -d)"
//usage: )
//usage: )
//usage: "\n -n Ignored"
//(manpage:-n with -b: don't split multibyte characters)
//(manpage:-n with -b: don't split multibyte characters)
//usage:
//usage:#define cut_example_usage
//usage: "$ echo \"Hello world\" | cut -f 1 -d ' '\n"
@@ -53,11 +66,6 @@
#if ENABLE_FEATURE_CUT_REGEX
#include "xregex.h"
#else
#define regex_t int
typedef struct { int rm_eo, rm_so; } regmatch_t;
#define xregcomp(x, ...) *(x) = 0
#define regexec(...) 0
#endif
/* This is a NOEXEC applet. Be very careful! */
@@ -65,253 +73,349 @@ typedef struct { int rm_eo, rm_so; } regmatch_t;
/* option vars */
#define OPT_STR "b:c:f:d:O:sD"IF_FEATURE_CUT_REGEX("F:")"n"
#define CUT_OPT_BYTE_FLGS (1 << 0)
#define CUT_OPT_CHAR_FLGS (1 << 1)
#define CUT_OPT_FIELDS_FLGS (1 << 2)
#define CUT_OPT_DELIM_FLGS (1 << 3)
#define CUT_OPT_ODELIM_FLGS (1 << 4)
#define CUT_OPT_SUPPRESS_FLGS (1 << 5)
#define CUT_OPT_NOSORT_FLGS (1 << 6)
#define CUT_OPT_REGEX_FLGS ((1 << 7) * ENABLE_FEATURE_CUT_REGEX)
#define OPT_BYTE (1 << 0)
#define OPT_CHAR (1 << 1)
#define OPT_FIELDS (1 << 2)
#define OPT_DELIM (1 << 3)
#define OPT_ODELIM (1 << 4)
#define OPT_SUPPRESS (1 << 5)
#define OPT_NOSORT (1 << 6)
#define OPT_REGEX ((1 << 7) * ENABLE_FEATURE_CUT_REGEX)
struct cut_list {
int startpos;
int endpos;
#define opt_REGEX (option_mask32 & OPT_REGEX)
struct cut_range {
unsigned startpos;
unsigned endpos;
};
static int cmpfunc(const void *a, const void *b)
{
return (((struct cut_list *) a)->startpos -
((struct cut_list *) b)->startpos);
const struct cut_range *aa = a;
const struct cut_range *bb = b;
return aa->startpos - bb->startpos;
}
#define END_OF_LIST(list_elem) ((list_elem).startpos == UINT_MAX)
#define NOT_END_OF_LIST(list_elem) ((list_elem).startpos != UINT_MAX)
static void cut_file(FILE *file, const char *delim, const char *odelim,
const struct cut_list *cut_lists, unsigned nlists)
const struct cut_range *cut_list)
{
char *line;
unsigned linenum = 0; /* keep these zero-based to be consistent */
regex_t reg;
int spos, shoe = option_mask32 & CUT_OPT_REGEX_FLGS;
if (shoe) xregcomp(&reg, delim, REG_EXTENDED);
int first_print = 1;
/* go through every line in the file */
while ((line = xmalloc_fgetline(file)) != NULL) {
/* set up a list so we can keep track of what's been printed */
int linelen = strlen(line);
char *printed = xzalloc(linelen + 1);
char *orig_line = line;
unsigned linelen = strlen(line);
unsigned cl_pos = 0;
/* cut based on chars/bytes XXX: only works when sizeof(char) == byte */
if (option_mask32 & (CUT_OPT_CHAR_FLGS | CUT_OPT_BYTE_FLGS)) {
/* Cut based on chars/bytes XXX: only works when sizeof(char) == byte */
if (option_mask32 & (OPT_CHAR | OPT_BYTE)) {
char *printed = xzalloc(linelen + 1);
int need_odelim = 0;
/* print the chars specified in each cut list */
for (; cl_pos < nlists; cl_pos++) {
for (spos = cut_lists[cl_pos].startpos; spos < linelen;) {
for (; NOT_END_OF_LIST(cut_list[cl_pos]); cl_pos++) {
unsigned spos = cut_list[cl_pos].startpos;
while (spos < linelen) {
if (!printed[spos]) {
printed[spos] = 'X';
if (need_odelim && spos != 0 && !printed[spos-1]) {
need_odelim = 0;
fputs_stdout(odelim);
}
putchar(line[spos]);
}
if (++spos > cut_lists[cl_pos].endpos) {
spos++;
if (spos > cut_list[cl_pos].endpos) {
/* will print OSEP (if not empty) */
need_odelim = (odelim && odelim[0]);
break;
}
}
}
} else if (*delim == '\n') { /* cut by lines */
spos = cut_lists[cl_pos].startpos;
free(printed);
/* Cut by lines */
} else if (!opt_REGEX && *delim == '\n') {
unsigned spos = cut_list[cl_pos].startpos;
/* get out if we have no more lists to process or if the lines
linenum++;
/* get out if we have no more ranges to process or if the lines
* are lower than what we're interested in */
if (((int)linenum < spos) || (cl_pos >= nlists))
if (linenum <= spos || END_OF_LIST(cut_list[cl_pos]))
goto next_line;
/* if the line we're looking for is lower than the one we were
* passed, it means we displayed it already, so move on */
while (spos < (int)linenum) {
spos++;
while (++spos < linenum) {
/* go to the next list if we're at the end of this one */
if (spos > cut_lists[cl_pos].endpos) {
if (spos > cut_list[cl_pos].endpos) {
cl_pos++;
/* get out if there's no more lists to process */
if (cl_pos >= nlists)
/* get out if there's no more ranges to process */
if (END_OF_LIST(cut_list[cl_pos]))
goto next_line;
spos = cut_lists[cl_pos].startpos;
spos = cut_list[cl_pos].startpos;
/* get out if the current line is lower than the one
* we just became interested in */
if ((int)linenum < spos)
if (linenum <= spos)
goto next_line;
}
}
/* If we made it here, it means we've found the line we're
* looking for, so print it */
puts(line);
if (first_print) {
first_print = 0;
fputs_stdout(line);
} else
printf("%s%s", odelim, line);
goto next_line;
} else { /* cut by fields */
unsigned uu = 0, start = 0, end = 0, out = 0;
int dcount = 0;
/* Cut by fields */
} else {
unsigned next = 0, start = 0, end = 0;
unsigned dcount = 0; /* we saw Nth delimiter (0 - didn't see any yet) */
/* Blank line? Check -s (later check for -s does not catch empty lines) */
if (linelen == 0) {
if (option_mask32 & OPT_SUPPRESS)
goto next_line;
}
if (!odelim)
odelim = "\t";
first_print = 1;
/* Loop through bytes, finding next delimiter */
for (;;) {
/* End of current range? */
if (end == linelen || dcount > cut_lists[cl_pos].endpos) {
if (++cl_pos >= nlists) break;
if (option_mask32 & CUT_OPT_NOSORT_FLGS)
start = dcount = uu = 0;
end = 0;
if (end == linelen || dcount > cut_list[cl_pos].endpos) {
end_of_range:
cl_pos++;
if (END_OF_LIST(cut_list[cl_pos]))
break;
if (option_mask32 & OPT_NOSORT)
start = dcount = next = 0;
end = 0; /* (why?) */
//bb_error_msg("End of current range");
}
/* End of current line? */
if (uu == linelen) {
/* If we've seen no delimiters, check -s */
if (!cl_pos && !dcount && !shoe) {
if (option_mask32 & CUT_OPT_SUPPRESS_FLGS)
if (next == linelen) {
end = linelen; /* print up to end */
/* If we've seen no delimiters, and no -D, check -s */
if (!(option_mask32 & OPT_NOSORT) && cl_pos == 0 && dcount == 0) {
if (option_mask32 & OPT_SUPPRESS)
goto next_line;
} else if (dcount<cut_lists[cl_pos].startpos)
start = linelen;
end = linelen;
/* else: will print entire line */
} else if (dcount < cut_list[cl_pos].startpos) {
/* echo 1.2 | cut -d. -f1,3: prints "1", not "1." */
//break;
/* ^^^ this fails a case with -D:
* echo 1 2 | cut -DF 1,3,2:
* do not end line processing when didn't find field#3
*/
//if (option_mask32 & OPT_NOSORT) - no, just do it always
goto end_of_range;
}
//bb_error_msg("End of current line: s:%d e:%d", start, end);
} else {
/* Find next delimiter */
if (shoe) {
regmatch_t rr = {-1, -1};
#if ENABLE_FEATURE_CUT_REGEX
if (opt_REGEX) {
regmatch_t rr;
regex_t *reg = (void*) delim;
if (!regexec(&reg, line+uu, 1, &rr, REG_NOTBOL|REG_NOTEOL)) {
end = uu + rr.rm_so;
uu += rr.rm_eo;
} else {
uu = linelen;
if (regexec(reg, line + next, 1, &rr, REG_NOTBOL|REG_NOTEOL) != 0) {
/* not found, go to "end of line" logic */
next = linelen;
continue;
}
} else if (line[end = uu++] != *delim)
continue;
/* Got delimiter. Loop if not yet within range. */
if (dcount++ < cut_lists[cl_pos].startpos) {
start = uu;
end = next + rr.rm_so;
next += (rr.rm_eo ? rr.rm_eo : 1);
/* ^^^ advancing by at least 1 prevents infinite loops */
/* testcase: echo "no at sign" | cut -d'@*' -F 1- */
} else
#endif
{
end = next++;
if (line[end] != *delim)
continue;
}
/* Got delimiter */
dcount++;
if (dcount <= cut_list[cl_pos].startpos) {
/* Not yet within range - loop */
start = next;
continue;
}
/* -F N-M preserves intermediate delimiters: */
//printf "1 2 3 4 5 6 7\n" | toybox cut -O: -F2,4-6,7
//2:4 5 6:7
if (opt_REGEX && dcount <= cut_list[cl_pos].endpos)
continue;
// NB: toybox does the above for -f too, but it's a compatibility bug:
//printf "1 2 3 4 5 6 7 8\n" | toybox cut -d' ' -O: -f2,4-6,7
//2:4 5 6:7 // WRONG!
//printf "1 2 3 4 5 6 7 8\n" | cut -d' ' --output-delimiter=: -f2,4-6,7
//2:4:5:6:7 // GNU coreutils 9.1
}
if (end != start || !shoe)
printf("%s%.*s", out++ ? odelim : "", end-start, line + start);
start = uu;
if (!dcount)
break;
}
#if ENABLE_FEATURE_CUT_REGEX
if (end != start || !opt_REGEX)
#endif
{
if (first_print) {
first_print = 0;
printf("%.*s", end - start, line + start);
} else
printf("%s%.*s", odelim, end - start, line + start);
}
start = next;
//if (dcount == 0)
// break; - why?
} /* byte loop */
}
/* if we printed anything, finish with newline */
putchar('\n');
next_line:
linenum++;
free(printed);
free(orig_line);
}
free(line);
} /* while (got line) */
/* For -d$'\n' --output-delimiter=^, the overall output is still terminated with \n, not ^ */
if (!opt_REGEX && *delim == '\n' && !first_print)
putchar('\n');
}
int cut_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int cut_main(int argc UNUSED_PARAM, char **argv)
{
/* growable array holding a series of lists */
struct cut_list *cut_lists = NULL;
unsigned nlists = 0; /* number of elements in above list */
char *sopt, *ltok;
/* growable array holding a series of ranges */
struct cut_range *cut_list = NULL;
unsigned nranges = 0; /* number of elements in above list */
char *LIST, *ltok;
const char *delim = NULL;
const char *odelim = NULL;
unsigned opt;
#if ENABLE_FEATURE_CUT_REGEX
regex_t reg;
#endif
#if ENABLE_LONG_OPTS
static const char cut_longopts[] ALIGN1 =
"output-delimiter\0" Required_argument "O"
;
#endif
#define ARG "bcf"IF_FEATURE_CUT_REGEX("F")
opt = getopt32(argv, "^"
#if ENABLE_LONG_OPTS
opt = getopt32long
#else
opt = getopt32
#endif
(argv, "^"
OPT_STR // = "b:c:f:d:O:sD"IF_FEATURE_CUT_REGEX("F:")"n"
"\0" "b--"ARG":c--"ARG":f--"ARG IF_FEATURE_CUT_REGEX("F--"ARG),
&sopt, &sopt, &sopt, &delim, &odelim IF_FEATURE_CUT_REGEX(, &sopt)
);
if (!delim || !*delim)
delim = (opt & CUT_OPT_REGEX_FLGS) ? "[[:space:]]+" : "\t";
if (!odelim) odelim = (opt & CUT_OPT_REGEX_FLGS) ? " " : delim;
"\0" "b:c:f:" IF_FEATURE_CUT_REGEX("F:") /* one of -bcfF is required */
"b--"ARG":c--"ARG":f--"ARG IF_FEATURE_CUT_REGEX(":F--"ARG), /* they are mutually exclusive */
IF_LONG_OPTS(cut_longopts,)
&LIST, &LIST, &LIST, &delim, &odelim IF_FEATURE_CUT_REGEX(, &LIST)
);
if (!odelim)
odelim = (opt & OPT_REGEX) ? " " : delim;
if (!delim)
delim = (opt & OPT_REGEX) ? "[[:space:]]+" : "\t";
// argc -= optind;
argv += optind;
if (!(opt & (CUT_OPT_BYTE_FLGS | CUT_OPT_CHAR_FLGS | CUT_OPT_FIELDS_FLGS | CUT_OPT_REGEX_FLGS)))
bb_simple_error_msg_and_die("expected a list of bytes, characters, or fields");
//if (!(opt & (OPT_BYTE | OPT_CHAR | OPT_FIELDS | OPT_REGEX)))
// bb_simple_error_msg_and_die("expected a list of bytes, characters, or fields");
//^^^ handled by getopt32
/* non-field (char or byte) cutting has some special handling */
if (!(opt & (CUT_OPT_FIELDS_FLGS|CUT_OPT_REGEX_FLGS))) {
static const char _op_on_field[] ALIGN1 = " only when operating on fields";
if (opt & CUT_OPT_SUPPRESS_FLGS) {
bb_error_msg_and_die
("suppressing non-delimited lines makes sense%s", _op_on_field);
}
if (opt & CUT_OPT_DELIM_FLGS) {
bb_error_msg_and_die
("a delimiter may be specified%s", _op_on_field);
}
/* non-field (char or byte) cutting has some special handling */
if (!(opt & (OPT_FIELDS|OPT_REGEX))) {
static const char requires_f[] ALIGN1 = " requires -f"
IF_FEATURE_CUT_REGEX(" or -F");
if (opt & OPT_SUPPRESS)
bb_error_msg_and_die("-s%s", requires_f);
if (opt & OPT_DELIM)
bb_error_msg_and_die("-d DELIM%s", requires_f);
}
/*
* parse list and put values into startpos and endpos.
* valid list formats: N, N-, N-M, -M
* more than one list can be separated by commas
* valid range formats: N, N-, N-M, -M
* more than one range can be separated by commas
*/
{
/* take apart the ranges, one by one (separated with commas) */
while ((ltok = strsep(&LIST, ",")) != NULL) {
char *ntok;
int s = 0, e = 0;
int s, e;
/* take apart the lists, one by one (they are separated with commas) */
while ((ltok = strsep(&sopt, ",")) != NULL) {
/* it's actually legal to pass an empty list */
//if (!ltok[0])
// continue;
//^^^ testcase?
/* it's actually legal to pass an empty list */
if (!ltok[0])
continue;
/* get the start pos */
ntok = strsep(&ltok, "-");
if (!ntok[0]) {
s = 0;
} else {
s = xatoi_positive(ntok);
/* account for the fact that arrays are zero based, while
* the user expects the first char on the line to be char #1 */
if (s != 0)
s--;
}
/* get the end pos */
if (ltok == NULL) {
e = s;
} else if (!ltok[0]) {
e = INT_MAX;
} else {
e = xatoi_positive(ltok);
/* if the user specified and end position of 0,
* that means "til the end of the line" */
if (!*ltok)
e = INT_MAX;
else if (e < s)
bb_error_msg_and_die("%d<%d", e, s);
e--; /* again, arrays are zero based, lines are 1 based */
}
/* add the new list */
cut_lists = xrealloc_vector(cut_lists, 4, nlists);
/* NB: startpos is always >= 0 */
cut_lists[nlists].startpos = s;
cut_lists[nlists].endpos = e;
nlists++;
/* get the start pos */
ntok = strsep(&ltok, "-");
if (!ntok[0]) {
if (!ltok) /* testcase: -f '' */
bb_show_usage();
if (!ltok[0]) /* testcase: -f - */
bb_show_usage();
s = 0; /* "-M" means "1-M" */
} else {
/* "N" or "N-[M]" */
/* arrays are zero based, while the user expects
* the first field/char on the line to be char #1 */
s = xatoi_positive(ntok) - 1;
}
/* make sure we got some cut positions out of all that */
if (nlists == 0)
bb_simple_error_msg_and_die("missing list of positions");
/* get the end pos */
if (!ltok) {
e = s; /* "N" means "N-N" */
} else if (!ltok[0]) {
/* "N-" means "until the end of the line" */
e = INT_MAX;
} else {
/* again, arrays are zero based, fields are 1 based */
e = xatoi_positive(ltok) - 1;
}
/* now that the lists are parsed, we need to sort them to make life
* easier on us when it comes time to print the chars / fields / lines
*/
if (!(opt & CUT_OPT_NOSORT_FLGS))
qsort(cut_lists, nlists, sizeof(cut_lists[0]), cmpfunc);
if (s < 0 || e < s)
bb_error_msg_and_die("invalid range %s-%s", ntok, ltok ?: ntok);
/* add the new range */
cut_list = xrealloc_vector(cut_list, 4, nranges);
/* NB: s is always >= 0 */
cut_list[nranges].startpos = s;
cut_list[nranges].endpos = e;
nranges++;
}
cut_list[nranges].startpos = UINT_MAX; /* end indicator */
/* make sure we got some cut positions out of all that */
//if (nranges == 0)
// bb_simple_error_msg_and_die("missing list of positions");
//^^^ this is impossible since one of -bcfF is required,
// they populate LIST with non-NULL string and when it is parsed,
// cut_list[] gets at least one element.
/* now that the lists are parsed, we need to sort them to make life
* easier on us when it comes time to print the chars / fields / lines
*/
if (!(opt & OPT_NOSORT))
qsort(cut_list, nranges, sizeof(cut_list[0]), cmpfunc);
#if ENABLE_FEATURE_CUT_REGEX
if (opt & OPT_REGEX) {
xregcomp(&reg, delim, REG_EXTENDED);
delim = (void*) &reg;
}
#endif
{
int retval = EXIT_SUCCESS;
exitcode_t retval = EXIT_SUCCESS;
if (!*argv)
*--argv = (char *)"-";
@@ -322,12 +426,12 @@ int cut_main(int argc UNUSED_PARAM, char **argv)
retval = EXIT_FAILURE;
continue;
}
cut_file(file, delim, odelim, cut_lists, nlists);
cut_file(file, delim, odelim, cut_list);
fclose_if_not_stdin(file);
} while (*++argv);
if (ENABLE_FEATURE_CLEAN_UP)
free(cut_lists);
free(cut_list);
fflush_stdout_and_exit(retval);
}
}
+2 -2
View File
@@ -19,7 +19,7 @@
much as possible, missed out a lot of bounds checking */
//config:config DATE
//config: bool "date (7 kb)"
//config: bool "date (7.2 kb)"
//config: default y
//config: help
//config: date is used to set the system date or display the
@@ -289,7 +289,7 @@ int date_main(int argc UNUSED_PARAM, char **argv)
/* if setting time, set it */
if ((opt & OPT_SET) && clock_settime(CLOCK_REALTIME, &ts) < 0) {
bb_simple_perror_msg("can't set date");
bb_simple_perror_msg_and_die("can't set date");
}
}
+23 -13
View File
@@ -7,7 +7,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config DD
//config: bool "dd (7.5 kb)"
//config: bool "dd (8.3 kb)"
//config: default y
//config: help
//config: dd copies a file (from standard input to standard output,
@@ -200,6 +200,7 @@ static void dd_output_status(int UNUSED_PARAM cur_signal)
}
#if ENABLE_FEATURE_DD_IBS_OBS
# ifdef O_DIRECT
static int clear_O_DIRECT(int fd)
{
if (errno == EINVAL) {
@@ -211,6 +212,7 @@ static int clear_O_DIRECT(int fd)
}
return 0;
}
# endif
#endif
static ssize_t dd_read(void *ibuf, size_t ibs)
@@ -225,8 +227,10 @@ static ssize_t dd_read(void *ibuf, size_t ibs)
#endif
n = safe_read(ifd, ibuf, ibs);
#if ENABLE_FEATURE_DD_IBS_OBS
# ifdef O_DIRECT
if (n < 0 && (G.flags & FLAG_IDIRECT) && clear_O_DIRECT(ifd))
goto read_again;
# endif
#endif
return n;
}
@@ -239,8 +243,10 @@ static bool write_and_stats(const void *buf, size_t len, size_t obs,
IF_FEATURE_DD_IBS_OBS(write_again:)
n = full_write(ofd, buf, len);
#if ENABLE_FEATURE_DD_IBS_OBS
# ifdef O_DIRECT
if (n < 0 && (G.flags & FLAG_ODIRECT) && clear_O_DIRECT(ofd))
goto write_again;
# endif
#endif
#if ENABLE_FEATURE_DD_THIRD_STATUS_LINE
@@ -266,12 +272,6 @@ static bool write_and_stats(const void *buf, size_t len, size_t obs,
return 1;
}
#if ENABLE_LFS
# define XATOU_SFX xatoull_sfx
#else
# define XATOU_SFX xatoul_sfx
#endif
#if ENABLE_FEATURE_DD_IBS_OBS
static int parse_comma_flags(char *val, const char *words, const char *error_in)
{
@@ -369,7 +369,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
OP_oflag_direct,
#endif
};
smallint exitcode = EXIT_FAILURE;
exitcode_t exitcode = EXIT_FAILURE;
int i;
size_t ibs = 512;
char *ibuf;
@@ -451,15 +451,15 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
/* These can be large: */
if (what == OP_count) {
G.flags |= FLAG_COUNT;
count = XATOU_SFX(val, cwbkMG_suffixes);
count = XATOOFF_SFX(val, cwbkMG_suffixes);
/*continue;*/
}
if (what == OP_seek) {
seek = XATOU_SFX(val, cwbkMG_suffixes);
seek = XATOOFF_SFX(val, cwbkMG_suffixes);
/*continue;*/
}
if (what == OP_skip) {
skip = XATOU_SFX(val, cwbkMG_suffixes);
skip = XATOOFF_SFX(val, cwbkMG_suffixes);
/*continue;*/
}
if (what == OP_if) {
@@ -501,8 +501,13 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
if (infile) {
int iflag = O_RDONLY;
#if ENABLE_FEATURE_DD_IBS_OBS
if (G.flags & FLAG_IDIRECT)
if (G.flags & FLAG_IDIRECT) {
# ifdef O_DIRECT
iflag |= O_DIRECT;
# else
bb_error_msg_and_die("O_DIRECT not supported on this platform");
# endif
}
#endif
xmove_fd(xopen(infile, iflag), ifd);
} else {
@@ -516,8 +521,13 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
if (G.flags & FLAG_APPEND)
oflag |= O_APPEND;
#if ENABLE_FEATURE_DD_IBS_OBS
if (G.flags & FLAG_ODIRECT)
if (G.flags & FLAG_ODIRECT) {
# ifdef O_DIRECT
oflag |= O_DIRECT;
# else
bb_error_msg_and_die("O_DIRECT not supported on this platform");
# endif
}
#endif
xmove_fd(xopen(outfile, oflag), ofd);
+7 -4
View File
@@ -18,7 +18,7 @@
* Implement -P and -B; better coreutils compat; cleanup
*/
//config:config DF
//config: bool "df (6.8 kb)"
//config: bool "df (7.1 kb)"
//config: default y
//config: help
//config: df reports the amount of disk space used and available
@@ -113,7 +113,7 @@ int df_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int df_main(int argc UNUSED_PARAM, char **argv)
{
unsigned long df_disp_hr = 1024;
int status = EXIT_SUCCESS;
exitcode_t status = EXIT_SUCCESS;
unsigned opt;
FILE *mount_table;
struct mntent *mount_entry;
@@ -155,6 +155,9 @@ int df_main(int argc UNUSED_PARAM, char **argv)
, &opt_t
IF_FEATURE_DF_FANCY(, &chp)
);
/* -k overrides $POSIXLY_CORRECT: */
if (opt & OPT_KILO)
df_disp_hr = 1024;
if (opt & OPT_MEGA)
df_disp_hr = 1024*1024;
@@ -185,8 +188,8 @@ int df_main(int argc UNUSED_PARAM, char **argv)
if (disp_units_hdr == NULL) {
#if ENABLE_FEATURE_HUMAN_READABLE
disp_units_hdr = xasprintf("%s-blocks",
/* print df_disp_hr, show no fractionals,
* use suffixes if OPT_POSIX is set in opt */
/* print df_disp_hr; show no fractionals;
* if -P, unit=1 (print it in full, no KMG suffixes) */
make_human_readable_str(df_disp_hr, 0, !!(opt & OPT_POSIX))
);
#else
+1 -1
View File
@@ -7,7 +7,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config DIRNAME
//config: bool "dirname (329 bytes)"
//config: bool "dirname (611 bytes)"
//config: default y
//config: help
//config: dirname is used to strip a non-directory suffix from
+2 -2
View File
@@ -12,14 +12,14 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config DOS2UNIX
//config: bool "dos2unix (5.2 kb)"
//config: bool "dos2unix (5.5 kb)"
//config: default y
//config: help
//config: dos2unix is used to convert a text file from DOS format to
//config: UNIX format, and vice versa.
//config:
//config:config UNIX2DOS
//config: bool "unix2dos (5.2 kb)"
//config: bool "unix2dos (5.5 kb)"
//config: default y
//config: help
//config: unix2dos is used to convert a text file from UNIX format to
+1 -1
View File
@@ -19,7 +19,7 @@
* 4) Fixed busybox bug #1284 involving long overflow with human_readable.
*/
//config:config DU
//config: bool "du (6.3 kb)"
//config: bool "du (6.5 kb)"
//config: default y
//config: help
//config: du is used to report the amount of disk space used
+3 -1
View File
@@ -19,7 +19,7 @@
* The previous version did not allow 4-digit octals.
*/
//config:config ECHO
//config: bool "echo (1.8 kb)"
//config: bool "echo (2 kb)"
//config: default y
//config: help
//config: echo prints a specified string to stdout.
@@ -321,6 +321,8 @@ int echo_main(int argc, char **argv)
if (*arg == '0' && (unsigned char)(arg[1] - '0') < 8) {
arg++;
}
//FIXME? we also accept non-0 starting sequences (see echo-prints-slash_41 test)
// echo -ne '-\41-' prints "-!-". bash 5.0.17 does not (prints "-\41-").
/* bb_process_escape_sequence can handle nul correctly */
c = bb_process_escape_sequence( (void*) &arg);
}
+2 -2
View File
@@ -24,7 +24,7 @@
* - use xfunc_error_retval
*/
//config:config ENV
//config: bool "env (4 kb)"
//config: bool "env (4.3 kb)"
//config: default y
//config: help
//config: env is used to set an environment variable and run
@@ -100,7 +100,7 @@ int env_main(int argc UNUSED_PARAM, char **argv)
}
}
fflush_stdout_and_exit(EXIT_SUCCESS);
fflush_stdout_and_exit_SUCCESS();
}
/*
+3 -3
View File
@@ -21,13 +21,13 @@
* Caveat: this versions of expand and unexpand don't accept tab lists.
*/
//config:config EXPAND
//config: bool "expand (5.1 kb)"
//config: bool "expand (5.3 kb)"
//config: default y
//config: help
//config: By default, convert all tabs to spaces.
//config:
//config:config UNEXPAND
//config: bool "unexpand (5.3 kb)"
//config: bool "unexpand (5.5 kb)"
//config: default y
//config: help
//config: By default, convert only leading sequences of blanks to tabs.
@@ -192,7 +192,7 @@ int expand_main(int argc UNUSED_PARAM, char **argv)
FILE *file;
unsigned tab_size;
unsigned opt;
int exit_status = EXIT_SUCCESS;
exitcode_t exit_status = EXIT_SUCCESS;
init_unicode();
+1 -1
View File
@@ -23,7 +23,7 @@
* provided they all associate ((x op x) op x).
*/
//config:config EXPR
//config: bool "expr (6.6 kb)"
//config: bool "expr (6.8 kb)"
//config: default y
//config: help
//config: expr is used to calculate numbers and print the result
+37 -38
View File
@@ -4,7 +4,7 @@
* Licensed under GPLv2, see file LICENSE in this source tree.
*/
//config:config FACTOR
//config: bool "factor (2.7 kb)"
//config: bool "factor (3.2 kb)"
//config: default y
//config: help
//config: factor factorizes integers
@@ -48,38 +48,40 @@ typedef unsigned long half_t;
* Larger wheels improve sieving only slightly, but quickly grow in size
* (adding just one prime, 13, results in 5766 element sieve).
*/
#define R(a,b,c,d,e,f,g,h,i,j,A,B,C,D,E,F,G,H,I,J) \
(((uint64_t)(a<<0) | (b<<3) | (c<<6) | (d<<9) | (e<<12) | (f<<15) | (g<<18) | (h<<21) | (i<<24) | (j<<27)) << 1) | \
(((uint64_t)(A<<0) | (B<<3) | (C<<6) | (D<<9) | (E<<12) | (F<<15) | (G<<18) | (H<<21) | (I<<24) | (J<<27)) << 31)
#define P(a,b,c,d,e,f,g,h,i,j,A,B,C,D,E,F,G,H,I,J) \
#define R(a,b,c,d,e,f,g,h,i,j,A,B,C,D,E,F,G,H,I,J,x) \
(((uint64_t)(a<<0) | (b<<3) | (c<<6) | (d<<9) | (e<<12) | (f<<15) | (g<<18) | (h<<21) | (i<<24) | (j<<27)) << 1) | \
(((uint64_t)(A<<0) | (B<<3) | (C<<6) | (D<<9) | (E<<12) | (F<<15) | (G<<18) | (H<<21) | (I<<24) | (J<<27)) << 31) | \
((uint64_t)x << 61)
#define P(a,b,c,d,e,f,g,h,i,j,A,B,C,D,E,F,G,H,I,J,x) \
R( (a/2),(b/2),(c/2),(d/2),(e/2),(f/2),(g/2),(h/2),(i/2),(j/2), \
(A/2),(B/2),(C/2),(D/2),(E/2),(F/2),(G/2),(H/2),(I/2),(J/2) )
(A/2),(B/2),(C/2),(D/2),(E/2),(F/2),(G/2),(H/2),(I/2),(J/2), \
(x/2) \
)
static const uint64_t packed_wheel[] = {
/*1, 2, 2, 4, 2,*/
P( 4, 2, 4, 6, 2, 6, 4, 2, 4, 6, 6, 2, 6, 4, 2, 6, 4, 6, 8, 4), //01
P( 2, 4, 2, 4,14, 4, 6, 2,10, 2, 6, 6, 4, 2, 4, 6, 2,10, 2, 4), //02
P( 2,12,10, 2, 4, 2, 4, 6, 2, 6, 4, 6, 6, 6, 2, 6, 4, 2, 6, 4), //03
P( 6, 8, 4, 2, 4, 6, 8, 6,10, 2, 4, 6, 2, 6, 6, 4, 2, 4, 6, 2), //04
P( 6, 4, 2, 6,10, 2,10, 2, 4, 2, 4, 6, 8, 4, 2, 4,12, 2, 6, 4), //05
P( 2, 6, 4, 6,12, 2, 4, 2, 4, 8, 6, 4, 6, 2, 4, 6, 2, 6,10, 2), //06
P( 4, 6, 2, 6, 4, 2, 4, 2,10, 2,10, 2, 4, 6, 6, 2, 6, 6, 4, 6), //07
P( 6, 2, 6, 4, 2, 6, 4, 6, 8, 4, 2, 6, 4, 8, 6, 4, 6, 2, 4, 6), //08
P( 8, 6, 4, 2,10, 2, 6, 4, 2, 4, 2,10, 2,10, 2, 4, 2, 4, 8, 6), //09
P( 4, 2, 4, 6, 6, 2, 6, 4, 8, 4, 6, 8, 4, 2, 4, 2, 4, 8, 6, 4), //10
P( 6, 6, 6, 2, 6, 6, 4, 2, 4, 6, 2, 6, 4, 2, 4, 2,10, 2,10, 2), //11
P( 6, 4, 6, 2, 6, 4, 2, 4, 6, 6, 8, 4, 2, 6,10, 8, 4, 2, 4, 2), //12
P( 4, 8,10, 6, 2, 4, 8, 6, 6, 4, 2, 4, 6, 2, 6, 4, 6, 2,10, 2), //13
P(10, 2, 4, 2, 4, 6, 2, 6, 4, 2, 4, 6, 6, 2, 6, 6, 6, 4, 6, 8), //14
P( 4, 2, 4, 2, 4, 8, 6, 4, 8, 4, 6, 2, 6, 6, 4, 2, 4, 6, 8, 4), //15
P( 2, 4, 2,10, 2,10, 2, 4, 2, 4, 6, 2,10, 2, 4, 6, 8, 6, 4, 2), //16
P( 6, 4, 6, 8, 4, 6, 2, 4, 8, 6, 4, 6, 2, 4, 6, 2, 6, 6, 4, 6), //17
P( 6, 2, 6, 6, 4, 2,10, 2,10, 2, 4, 2, 4, 6, 2, 6, 4, 2,10, 6), //18
P( 2, 6, 4, 2, 6, 4, 6, 8, 4, 2, 4, 2,12, 6, 4, 6, 2, 4, 6, 2), //19
P(12, 4, 2, 4, 8, 6, 4, 2, 4, 2,10, 2,10, 6, 2, 4, 6, 2, 6, 4), //20
P( 2, 4, 6, 6, 2, 6, 4, 2,10, 6, 8, 6, 4, 2, 4, 8, 6, 4, 6, 2), //21
P( 4, 6, 2, 6, 6, 6, 4, 6, 2, 6, 4, 2, 4, 2,10,12, 2, 4, 2,10), //22
P( 2, 6, 4, 2, 4, 6, 6, 2,10, 2, 6, 4,14, 4, 2, 4, 2, 4, 8, 6), //23
P( 4, 6, 2, 4, 6, 2, 6, 6, 4, 2, 4, 6, 2, 6, 4, 2, 4,12, 2,12), //24
/* 1, 2, */
P( 2, 4, 2, 4, 2, 4, 6, 2, 6, 4, 2, 4, 6, 6, 2, 6, 4, 2, 6, 4, 6),
P( 8, 4, 2, 4, 2, 4,14, 4, 6, 2,10, 2, 6, 6, 4, 2, 4, 6, 2,10, 2),
P( 4, 2,12,10, 2, 4, 2, 4, 6, 2, 6, 4, 6, 6, 6, 2, 6, 4, 2, 6, 4),
P( 6, 8, 4, 2, 4, 6, 8, 6,10, 2, 4, 6, 2, 6, 6, 4, 2, 4, 6, 2, 6),
P( 4, 2, 6,10, 2,10, 2, 4, 2, 4, 6, 8, 4, 2, 4,12, 2, 6, 4, 2, 6),
P( 4, 6,12, 2, 4, 2, 4, 8, 6, 4, 6, 2, 4, 6, 2, 6,10, 2, 4, 6, 2),
P( 6, 4, 2, 4, 2,10, 2,10, 2, 4, 6, 6, 2, 6, 6, 4, 6, 6, 2, 6, 4),
P( 2, 6, 4, 6, 8, 4, 2, 6, 4, 8, 6, 4, 6, 2, 4, 6, 8, 6, 4, 2,10),
P( 2, 6, 4, 2, 4, 2,10, 2,10, 2, 4, 2, 4, 8, 6, 4, 2, 4, 6, 6, 2),
P( 6, 4, 8, 4, 6, 8, 4, 2, 4, 2, 4, 8, 6, 4, 6, 6, 6, 2, 6, 6, 4),
P( 2, 4, 6, 2, 6, 4, 2, 4, 2,10, 2,10, 2, 6, 4, 6, 2, 6, 4, 2, 4),
P( 6, 6, 8, 4, 2, 6,10, 8, 4, 2, 4, 2, 4, 8,10, 6, 2, 4, 8, 6, 6),
P( 4, 2, 4, 6, 2, 6, 4, 6, 2,10, 2,10, 2, 4, 2, 4, 6, 2, 6, 4, 2),
P( 4, 6, 6, 2, 6, 6, 6, 4, 6, 8, 4, 2, 4, 2, 4, 8, 6, 4, 8, 4, 6),
P( 2, 6, 6, 4, 2, 4, 6, 8, 4, 2, 4, 2,10, 2,10, 2, 4, 2, 4, 6, 2),
P(10, 2, 4, 6, 8, 6, 4, 2, 6, 4, 6, 8, 4, 6, 2, 4, 8, 6, 4, 6, 2),
P( 4, 6, 2, 6, 6, 4, 6, 6, 2, 6, 6, 4, 2,10, 2,10, 2, 4, 2, 4, 6),
P( 2, 6, 4, 2,10, 6, 2, 6, 4, 2, 6, 4, 6, 8, 4, 2, 4, 2,12, 6, 4),
P( 6, 2, 4, 6, 2,12, 4, 2, 4, 8, 6, 4, 2, 4, 2,10, 2,10, 6, 2, 4),
P( 6, 2, 6, 4, 2, 4, 6, 6, 2, 6, 4, 2,10, 6, 8, 6, 4, 2, 4, 8, 6),
P( 4, 6, 2, 4, 6, 2, 6, 6, 6, 4, 6, 2, 6, 4, 2, 4, 2,10,12, 2, 4),
P( 2,10, 2, 6, 4, 2, 4, 6, 6, 2,10, 2, 6, 4,14, 4, 2, 4, 2, 4, 8),
P( 6, 4, 6, 2, 4, 6, 2, 6, 6, 4, 2, 4, 6, 2, 6, 4, 2, 4,12, 2,12),
};
#undef P
#undef R
@@ -93,8 +95,8 @@ static const uint64_t packed_wheel[] = {
* function old new delta
* wheel_tab - 485 +485
* 3-bit-packed insanity:
* packed_wheel - 192 +192
* factor_main 108 171 +63
* packed_wheel - 184 +184
* factor_main 108 163 +55
*/
static void unpack_wheel(void)
{
@@ -104,10 +106,7 @@ static void unpack_wheel(void)
setup_common_bufsiz();
wheel_tab[0] = 1;
wheel_tab[1] = 2;
wheel_tab[2] = 2;
wheel_tab[3] = 4;
wheel_tab[4] = 2;
p = &wheel_tab[5];
p = &wheel_tab[2];
for (i = 0; i < ARRAY_SIZE(packed_wheel); i++) {
uint64_t v = packed_wheel[i];
while ((v & 0xe) != 0) {
@@ -137,7 +136,7 @@ static void factorize(wide_t N);
static half_t isqrt_odd(wide_t N)
{
half_t s = isqrt(N);
half_t s = isqrt_ull(N);
/* s^2 is <= N, (s+1)^2 > N */
/* If s^2 in fact is EQUAL to N, it's very lucky.
+1 -1
View File
@@ -7,7 +7,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config FALSE
//config: bool "false (tiny)"
//config: bool "false (314 bytes)"
//config: default y
//config: help
//config: false returns an exit code of FALSE (1).
+2 -2
View File
@@ -11,7 +11,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config FOLD
//config: bool "fold (4.6 kb)"
//config: bool "fold (4.8 kb)"
//config: default y
//config: help
//config: Wrap text to fit a specific width.
@@ -77,7 +77,7 @@ int fold_main(int argc UNUSED_PARAM, char **argv)
char *line_out = NULL;
const char *w_opt = "80";
unsigned width;
smallint exitcode = EXIT_SUCCESS;
exitcode_t exitcode = EXIT_SUCCESS;
init_unicode();
+4 -4
View File
@@ -7,7 +7,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config HEAD
//config: bool "head (3.8 kb)"
//config: bool "head (4 kb)"
//config: default y
//config: help
//config: head is used to print the first specified number of lines
@@ -76,7 +76,7 @@ print_except_N_last_bytes(FILE *fp, unsigned count)
{
unsigned char *circle = xmalloc(++count);
unsigned head = 0;
for(;;) {
for (;;) {
int c;
c = getc(fp);
if (c == EOF)
@@ -105,7 +105,7 @@ print_except_N_last_lines(FILE *fp, unsigned count)
{
char **circle = xzalloc((++count) * sizeof(circle[0]));
unsigned head = 0;
for(;;) {
for (;;) {
char *c;
c = xmalloc_fgets(fp);
if (!c)
@@ -127,7 +127,7 @@ print_except_N_last_lines(FILE *fp, unsigned count)
}
ret:
head = 0;
for(;;) {
for (;;) {
free(circle[head++]);
if (head == count)
break;
+1 -1
View File
@@ -7,7 +7,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config HOSTID
//config: bool "hostid (286 bytes)"
//config: bool "hostid (566 bytes)"
//config: default y
//config: help
//config: hostid prints the numeric identifier (in hexadecimal) for
+4 -3
View File
@@ -13,13 +13,13 @@
* Added -G option Tito Ragusa (C) 2008 for SUSv3.
*/
//config:config ID
//config: bool "id (7 kb)"
//config: bool "id (7.1 kb)"
//config: default y
//config: help
//config: id displays the current user and group ID names.
//config:
//config:config GROUPS
//config: bool "groups (6.7 kb)"
//config: bool "groups (6.8 kb)"
//config: default y
//config: help
//config: Print the group names associated with current user id.
@@ -156,7 +156,7 @@ int id_main(int argc UNUSED_PARAM, char **argv)
const char *prefix;
const char *username;
#if ENABLE_SELINUX
security_context_t scontext = NULL;
char *scontext = NULL;
#endif
if (ENABLE_GROUPS && (!ENABLE_ID || applet_name[0] == 'g')) {
@@ -230,6 +230,7 @@ int id_main(int argc UNUSED_PARAM, char **argv)
prefix = ",";
}
} else if (n < 0) { /* error in get_groups() */
bb_putchar('\n');
if (ENABLE_DESKTOP)
bb_simple_error_msg_and_die("can't get groups");
return EXIT_FAILURE;
+11 -11
View File
@@ -50,11 +50,11 @@ if test $FLAG_USER_EXISTS = "yes"; then
exit 1
fi
adduser -s /bin/true -g "" -H -D "$TEST_USER" || exit 1
$BUSYBOX adduser -s /bin/true -g "" -H -D "$TEST_USER" || exit 1
chown $TEST_USER.$TEST_USER $BUSYBOX
chown $TEST_USER:$TEST_USER $BUSYBOX
chmod u+s $BUSYBOX 2>&1 /dev/null
chown $TEST_USER.$TEST_USER $ID
chown $TEST_USER:$TEST_USER $ID
chmod u+s $ID 2>&1 /dev/null
echo "test 3 setuid, existing user: id [options] no username"
@@ -90,9 +90,9 @@ do
done
done
chown $TEST_USER.$TEST_USER $BUSYBOX
chown $TEST_USER:$TEST_USER $BUSYBOX
chmod g+s $BUSYBOX 2>&1 /dev/null
chown $TEST_USER.$TEST_USER $ID
chown $TEST_USER:$TEST_USER $ID
chmod g+s $ID 2>&1 /dev/null
echo "test 5 setgid, existing user: id [options] no username"
@@ -128,9 +128,9 @@ do
done
done
chown $TEST_USER.$TEST_USER $BUSYBOX
chown $TEST_USER:$TEST_USER $BUSYBOX
chmod u+s,g+s $BUSYBOX 2>&1 /dev/null
chown $TEST_USER.$TEST_USER $ID
chown $TEST_USER:$TEST_USER $ID
chmod u+s,g+s $ID 2>&1 /dev/null
echo "test 7 setuid, setgid, existing user: id [options] no username"
@@ -200,8 +200,8 @@ do
done
done
chown .root $BUSYBOX 2>&1 /dev/null
chown .root $ID 2>&1 /dev/null
chown :root $BUSYBOX 2>&1 /dev/null
chown :root $ID 2>&1 /dev/null
chmod g+s $BUSYBOX 2>&1 /dev/null
chmod g+s $ID 2>&1 /dev/null
@@ -238,7 +238,7 @@ do
done
done
chown root.root $BUSYBOX 2>&1 /dev/null
chown root.root $ID 2>&1 /dev/null
chown root:root $BUSYBOX 2>&1 /dev/null
chown root:root $ID 2>&1 /dev/null
rm -f $ID
rm -f foo bar
+11 -9
View File
@@ -73,7 +73,7 @@ static const char install_longopts[] ALIGN1 =
static void setdefaultfilecon(const char *path)
{
struct stat s;
security_context_t scontext = NULL;
char *scontext = NULL;
if (!is_selinux_enabled()) {
return;
@@ -119,7 +119,7 @@ int install_main(int argc, char **argv)
int ret = EXIT_SUCCESS;
int isdir;
#if ENABLE_SELINUX
security_context_t scontext;
char *scontext;
bool use_default_selinux_context = 1;
#endif
enum {
@@ -244,6 +244,15 @@ int install_main(int argc, char **argv)
}
}
/* Set the user and group id */
/* (must be before chmod, or else chown may clear suid/gid bits) */
if ((opts & (OPT_OWNER|OPT_GROUP))
&& lchown(dest, uid, gid) == -1
) {
bb_perror_msg("can't change %s of %s", "ownership", dest);
ret = EXIT_FAILURE;
}
/* Set the file mode (always, not only with -m).
* GNU coreutils 6.10 is not affected by umask. */
if (chmod(dest, mode) == -1) {
@@ -254,13 +263,6 @@ int install_main(int argc, char **argv)
if (use_default_selinux_context)
setdefaultfilecon(dest);
#endif
/* Set the user and group id */
if ((opts & (OPT_OWNER|OPT_GROUP))
&& lchown(dest, uid, gid) == -1
) {
bb_perror_msg("can't change %s of %s", "ownership", dest);
ret = EXIT_FAILURE;
}
next:
if (ENABLE_FEATURE_CLEAN_UP && isdir)
free(dest);
+546
View File
@@ -0,0 +1,546 @@
/* vi: set sw=4 ts=4: */
/*
* join -- equality join on two files
*
* Written by Morgan Bartlett
* Copyright (C) 2025 Morgan Bartlett
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config JOIN
//config: bool "join (6.6 kb)"
//config: default y
//config: help
//config: Equality join on two files
//applet:IF_JOIN(APPLET_NOEXEC(join, join, BB_DIR_USR_BIN, BB_SUID_DROP, join))
//kbuild:lib-$(CONFIG_JOIN) += join.o
//usage:#define join_trivial_usage
//usage: "[-a 1|2 | -v 1|2] [-e STR] [-o LIST] [-t SEP_CHAR] [-1 NUM] [-2 NUM] FILE1 FILE2"
//usage:#define join_full_usage "\n\n"
//usage: "Join FILE1 and FILE2, writing to stdout\n"
//usage: "\n -a 1|2 Also write unpaired lines from FILE1/2"
//usage: "\n -v 1|2 Only write unpaired lines from FILE1/2"
//usage: "\n -e STR Replace empty fields with STR"
//usage: "\n -o LIST Write the fields in LIST"
//usage: "\n -t CHAR Use a different field separator"
//usage: "\n -1 NUM Join on field NUM from FILE1"
//usage: "\n -2 NUM Join on field NUM from FILE2"
//usage: "\n"
//usage: "\nLIST is a space or comma separated list of 1/2.FIELD or 0 (the join field)"
#include "libbb.h"
#include "unicode.h"
#include "common_bufsiz.h"
/* This is a NOEXEC applet. Be very careful! */
typedef struct {
char *line;
char **fields;
int fieldcount;
} LINE;
typedef struct {
FILE *fp;
int idx; /* index of join field in fields array */
const char *field; /* pointer to lines[0].fields[idx] or "" */
LINE *lines;
LINE pushback;
int linecount; /* number of lines currently cached */
int linecap; /* current capacity of lines array */
} FDAT;
/* "globals" can be made local to main(), but then passing them
down the callchains as parameters requires ~90 bytes of code (on x86).
*/
struct globals {
int *format; // = NULL;
const char *empty_str;
/* \0 can't be separator, 0 means: "whitespace+" pattern */
char sep; // = 0;
} FIX_ALIASING;
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
setup_common_bufsiz(); \
/* we have to zero it out because of NOEXEC */ \
memset(&G, 0, sizeof(G)); \
} while (0)
/* split s by sep, and put the results into *curr */
static void field_split(char *s, LINE *curr)
{
/* compare awk_split from editors/awk.c */
int n;
char *ps = s;
char *s1 = s;
char **sl;
size_t sn;
/* in worst case, every character is a separator */
curr->fields = sl = xzalloc(sizeof(char*) * (strlen(s) + 2));
curr->line = s;
n = 0;
if (G.sep != '\0') { /* single-character split */
while ((s1 = strchr(ps, G.sep)) != NULL) {
sl[n] = ps;
*s1 = '\0';
ps = s1 + 1;
n++;
}
/* Add the last field */
sl[n] = ps;
n++;
curr->fieldcount = n;
return;
}
/* default split: skip the initial whitespace and then any run
of non-whitespace characters is a field */
while (*s) {
/* blanks are space and tab in the POSIX locale */
while (*s == ' ' || *s == '\t')
s++;
if (!*s)
break;
s1 = strpbrk(s, " \t");
if (s1 == NULL) {
/* last field */
sn = strlen(s);
} else {
sn = s1 - s;
*s1 = '\0';
}
sl[n] = s;
n++;
s += sn + 1;
}
curr->fieldcount = n;
}
static inline void freefields(LINE *lp)
{
free(lp->line);
free(lp->fields);
lp->line = NULL;
lp->fields = NULL;
}
static void freelines(FDAT *f)
{
for (int n = 0; n < f->linecount; n++) {
freefields(f->lines + n);
}
f->linecount = 0;
f->field = "";
}
static void readfields(FDAT *f)
{
LINE curr = { .line = NULL, .fields = NULL, .fieldcount = 0 };
char *line;
const char *field2;
bool first = TRUE;
freelines(f);
while (true) {
if (first && f->pushback.fields) {
/* first check for a pushed back line */
curr = f->pushback;
f->pushback = (LINE) { .line = NULL, .fields = NULL, .fieldcount = 0 };
} else {
/* read a line and split */
line = xmalloc_fgetline(f->fp);
if (line == NULL) {
return;
}
field_split(line, &curr);
}
if (f->idx >= curr.fieldcount)
field2 = "";
else
field2 = curr.fields[f->idx];
/* Ensure strcmp() matches on first pass through loop */
if (first)
f->field = field2;
if (strcmp(f->field, field2) == 0) {
/* add to the stack */
if (f->linecount == f->linecap) {
f->linecap = f->linecap ? f->linecap * 2 : 8;
f->lines = xrealloc(f->lines, sizeof(LINE) * f->linecap);
}
f->lines[f->linecount++] = curr;
} else {
f->pushback = curr;
return;
}
first = FALSE;
}
}
static inline const char *fieldorempty(const char *field)
{
if (*field == '\0')
return G.empty_str;
return field;
}
static void printfields(FDAT *f1, FDAT *f2)
{
const char *field = (f1 == NULL) ? f2->field : f1->field;
int linef1;
int linef2;
int fn;
int format_fl;
int format_idx;
int *formatcurr;
bool first;
char sep;
LINE *l1;
LINE *l2;
sep = (G.sep == '\0') ? ' ' : G.sep;
for (linef1 = 0; linef1 < (f1 ? f1->linecount : 1); linef1++) {
l1 = f1 ? &f1->lines[linef1] : NULL;
for (linef2 = 0; linef2 < (f2 ? f2->linecount : 1); linef2++) {
l2 = f2 ? &f2->lines[linef2] : NULL;
if (G.format) {
/*
Format is a sort of null-terminated array:
They are indexed by [n] for file number and [n + 1] for field number.
If file number is 0 then that is the null-terminator.
If file number is neither 1 nor 2 then we have the join field.
*/
first = true;
formatcurr = G.format;
while (formatcurr[0]) {
if (first)
first = false;
else
bb_putchar(sep);
format_fl = formatcurr[0];
format_idx = formatcurr[1];
if (format_fl == 1) {
if (l1 != NULL && l1->fieldcount > format_idx)
fputs_stdout(fieldorempty(l1->fields[format_idx]));
else
fputs_stdout(G.empty_str);
} else if (format_fl == 2) {
if (l2 != NULL && l2->fieldcount > format_idx)
fputs_stdout(fieldorempty(l2->fields[format_idx]));
else
fputs_stdout(G.empty_str);
} else
fputs_stdout(fieldorempty(field));
formatcurr += 2;
}
} else {
fputs_stdout(fieldorempty(field));
fn = 0;
if (l1 != NULL)
while (l1->fields[fn]) {
if (fn != f1->idx) {
bb_putchar(sep);
fputs_stdout(fieldorempty(l1->fields[fn]));
}
fn++;
}
fn = 0;
if (l2 != NULL)
while (l2->fields[fn]) {
if (fn != f2->idx) {
bb_putchar(sep);
fputs_stdout(fieldorempty(l2->fields[fn]));
}
fn++;
}
}
bb_putchar('\n');
}
}
}
static void parsejformat(const char *format_str)
{
int *format;
int field_idx;
char scache[20] = { 0 };
int n = 0;
const char *s1 = format_str;
size_t sn;
/* The most formats we can have is if the format_str is noted as 0,0,0,0
which ends up being (strlen + 1) / 2
and then we need to have two for each entry plus one for the terminator.
( (strlen+1) / 2 * 2 is optimized out in the alloc) */
G.format = format = xzalloc(sizeof(format[0]) * ((strlen(format_str) + 1) + 1));
/* default split: skip the initial whitespace and then any run
of non-whitespace characters is a field */
while (*format_str) {
/* blanks are space and tab in the POSIX locale */
while (*format_str == ' ' || *format_str == '\t' || *format_str == ',')
format_str++;
if (!*format_str)
break;
s1 = strpbrk(format_str, " \t,");
if (s1 == NULL)
/* last field */
sn = strlen(format_str);
else
sn = s1 - format_str;
if (sn == 1 && *format_str == '0') {
format[n * 2] = 3;
} else if (sn >= 3 && (*format_str == '1' || *format_str == '2') && format_str[1] == '.') {
if (sn > 21) /* res_str > 19 */
bb_simple_error_msg_and_die("field specifier too large");
memcpy(scache, format_str + 2, sn - 2);
scache[sn - 2] = '\0';
field_idx = xatoi_positive(scache);
if (--field_idx < 0)
bb_simple_error_msg_and_die("field number can't be 0");
format[n * 2] = *format_str - '0';
format[n * 2 + 1] = field_idx;
} else {
bb_simple_error_msg_and_die("field specifier must be 0, 1.x or 2.x");
}
n++;
format_str += sn;
}
}
int join_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int join_main(int argc UNUSED_PARAM, char **argv)
{
struct {
llist_t *unpaired_list; // = NULL;
const char *format_str; // = NULL;
bool print1unpaired; // = false;
bool print2unpaired; // = false;
bool printpaired;
FDAT f1; // = { };
FDAT f2; // = { };
} L;
#define unpaired_list L.unpaired_list
#define format_str L.format_str
#define print1unpaired L.print1unpaired
#define print2unpaired L.print2unpaired
#define printpaired L.printpaired
#define f1 L.f1
#define f2 L.f2
char *separator;
uint32_t opts;
/* Must match getopt32 call */
enum {
FLAG_UNPAIRED_ADD = (1 << 0),
FLAG_UNPAIRED_ONLY = (1 << 1),
FLAG_EMPTY_STRING = (1 << 2),
FLAG_LIST_OUTPUT = (1 << 3),
FLAG_SEP_USED = (1 << 4),
FLAG_FIELD_1 = (1 << 5),
FLAG_FIELD_2 = (1 << 6),
};
INIT_G();
G.empty_str = "";
memset(&L, 0, sizeof(L));
init_unicode();
opts = getopt32(argv,
"^a:*v:*"
"e:"
"o:"
"t:"
"1:+2:+"
"\0""=2:a--v:v--a",
&unpaired_list,
&unpaired_list,
&G.empty_str,
&format_str,
&separator,
&f1.idx,
&f2.idx);
argv += optind;
printpaired = !(opts & FLAG_UNPAIRED_ONLY);
if (opts & (FLAG_UNPAIRED_ADD|FLAG_UNPAIRED_ONLY)) {
char *unpaired_str;
while ((unpaired_str = llist_pop(&unpaired_list)) != NULL) {
if (*unpaired_str == '1')
print1unpaired = true;
else if (*unpaired_str == '2')
print2unpaired = true;
else
bb_show_usage();
if (unpaired_str[1])
bb_show_usage();
}
}
if (((opts & FLAG_FIELD_1) && --f1.idx < 0)
|| ((opts & FLAG_FIELD_2) && --f2.idx < 0)
) {
bb_simple_error_msg_and_die("field 0 doesn't exist");
}
if (opts & FLAG_SEP_USED) {
if (separator[0] && separator[1])
bb_simple_error_msg_and_die("separators are single characters");
G.sep = *separator;
}
if (opts & FLAG_LIST_OUTPUT)
parsejformat(format_str);
f1.fp = xfopen_stdin(argv[0]);
f2.fp = xfopen_stdin(argv[1]);
if (f1.fp == f2.fp)
bb_simple_error_msg_and_die("can't combine stdin with itself");
/*
Outline of the program:
- Read a line set from each file into cache
- While there are cached current lines from both files:
- If the two indexing fields are the same:
- If no unpaired_only options:
- Print joined line set formatted with fields
- Read line sets from both files
- Elseif indexing1 < indexing2 then
- If print1unpaired:
- Print line set from file 1
- Read another line set from file 1
- Elseif indexing1 > indexing2 then
- If print2unpaired:
- Print line set from file 2
- Read another line set from file 2
- If there are cached lines from file 1 AND print1unpaired:
- Print the rest of the lines from file 1
- If there are cached lines from file 2 AND print2unpaired:
- Print the rest of the lines from file 2
*/
/*
Notes for POSIX:
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/join.html
Multiple instances of the same key are meant to give combinatorial results.
E.g:
file1:
a 1
a 2
file2:
a A
a B
a C
result:
a 1 A
a 1 B
a 1 C
a 2 A
a 2 B
a 2 C
This is done in this implementation by reading all the lines that have the same key
and then iterating through the combinations when printing them.
(test with `./busybox join <(printf 'a 1\na 2\n';) <(printf 'a A\na B\na C\n')`)
*/
readfields(&f1);
readfields(&f2);
while (f1.linecount != 0 && f2.linecount != 0) {
int res = strcmp(f1.field, f2.field);
if (res == 0) {
if (printpaired)
printfields(&f1, &f2);
readfields(&f1);
readfields(&f2);
} else if (res < 0) {
if (print1unpaired)
printfields(&f1, NULL);
readfields(&f1);
} else {
if (print2unpaired)
printfields(NULL, &f2);
readfields(&f2);
}
}
if (print1unpaired) {
while (f1.linecount != 0) {
printfields(&f1, NULL);
readfields(&f1);
}
}
if (print2unpaired) {
while (f2.linecount != 0) {
printfields(NULL, &f2);
readfields(&f2);
}
}
#if ENABLE_FEATURE_CLEAN_UP
if (f1.linecap) {
freelines(&f1);
free(f1.lines);
}
if (f2.linecap) {
freelines(&f2);
free(f2.lines);
}
free(G.format);
fclose_if_not_stdin(f1.fp);
fclose_if_not_stdin(f2.fp);
#endif
fflush_stdout_and_exit_SUCCESS();
}
+1 -1
View File
@@ -26,7 +26,7 @@ mode_t FAST_FUNC getopt_mk_fifo_nod(char **argv)
mode_t mode = 0666;
char *smode = NULL;
#if ENABLE_SELINUX
security_context_t scontext;
char *scontext;
#endif
int opt;
opt = getopt32(argv, "m:" IF_SELINUX("Z:"), &smode IF_SELINUX(,&scontext));
+1 -1
View File
@@ -6,7 +6,7 @@
* Licensed under GPLv2, see file LICENSE in this source tree.
*/
//config:config LINK
//config: bool "link (3.2 kb)"
//config: bool "link (3.5 kb)"
//config: default y
//config: help
//config: link creates hard links between files.
+2 -2
View File
@@ -7,7 +7,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config LN
//config: bool "ln (4.9 kb)"
//config: bool "ln (5.1 kb)"
//config: default y
//config: help
//config: ln is used to create hard or soft links between files.
@@ -52,7 +52,7 @@
int ln_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int ln_main(int argc, char **argv)
{
int status = EXIT_SUCCESS;
exitcode_t status = EXIT_SUCCESS;
int opts;
char *last;
char *src_name;
+1 -1
View File
@@ -16,7 +16,7 @@
* a diagnostic message and an error return.
*/
//config:config LOGNAME
//config: bool "logname (1.1 kb)"
//config: bool "logname (1.4 kb)"
//config: default y
//config: help
//config: logname is used to print the current user's login name.
+191 -96
View File
@@ -126,6 +126,8 @@
//usage: "\n -F Append indicator (one of */=@|) to names"
//usage: )
//usage: "\n -l Long format"
////usage: "\n -g Long format without group column"
////TODO: support -G too ("suppress owner column", GNUism)
//usage: "\n -i List inode numbers"
//usage: "\n -n List numeric UIDs and GIDs instead of names"
//usage: "\n -s List allocated blocks"
@@ -159,6 +161,8 @@
//usage: IF_FEATURE_LS_WIDTH(
//usage: "\n -w N Format N columns wide"
//usage: )
////usage: "\n -Q Double-quote names"
////usage: "\n -q Replace unprintable chars with '?'"
//usage: IF_FEATURE_LS_COLOR(
//usage: "\n --color[={always,never,auto}]"
//usage: )
@@ -196,27 +200,47 @@ SPLIT_SUBDIR = 2,
/* -Cadi1l Std options, busybox always supports */
/* -gnsxA Std options, busybox always supports */
/* -Q GNU option, busybox always supports */
/* -k Std option, busybox always supports (by ignoring) */
/* It means "for -s, show sizes in kbytes" */
/* Seems to only affect "POSIXLY_CORRECT=1 ls -sk" */
/* since otherwise -s shows kbytes anyway */
/* -Q GNU option, busybox always supports: */
/* -Q, --quote-name */
/* enclose entry names in double quotes */
/* -LHRctur Std options, busybox optionally supports */
/* -Fp Std options, busybox optionally supports */
/* -SXvhTw GNU options, busybox optionally supports */
/* -T WIDTH Ignored (we don't use tabs on output) */
/* -Z SELinux mandated option, busybox optionally supports */
/* -q Std option, busybox always supports: */
/* https://pubs.opengroup.org/onlinepubs/9699919799/utilities/ls.html: */
/* Force each instance of non-printable filename characters and */
/* <tab> characters to be written as the <question-mark> ('?') */
/* character. Implementations may provide this option by default */
/* if the output is to a terminal device. */
/* -k Std option, busybox always supports (by ignoring) */
/* It means "for -s, show sizes in kbytes" */
/* Seems to only affect "POSIXLY_CORRECT=1 ls -sk" */
/* since otherwise -s shows kbytes anyway */
#define ls_options \
"Cadi1lgnsxAk" /* 12 opts, total 12 */ \
IF_FEATURE_LS_FILETYPES("Fp") /* 2, 14 */ \
IF_FEATURE_LS_RECURSIVE("R") /* 1, 15 */ \
IF_SELINUX("Z") /* 1, 16 */ \
"Q" /* 1, 17 */ \
IF_FEATURE_LS_TIMESTAMPS("ctu") /* 3, 20 */ \
IF_FEATURE_LS_SORTFILES("SXrv") /* 4, 24 */ \
IF_FEATURE_LS_FOLLOWLINKS("LH") /* 2, 26 */ \
IF_FEATURE_HUMAN_READABLE("h") /* 1, 27 */ \
IF_FEATURE_LS_WIDTH("T:w:") /* 2, 29 */
"Cadi1lgnsxA" /* 11 opts, total 11 */ \
IF_FEATURE_LS_FILETYPES("Fp") /* 2, 13 */ \
IF_FEATURE_LS_RECURSIVE("R") /* 1, 14 */ \
IF_SELINUX("Z") /* 1, 15 */ \
"Q" /* 1, 16 */ \
IF_FEATURE_LS_TIMESTAMPS("ctu") /* 3, 19 */ \
IF_FEATURE_LS_SORTFILES("SXrv") /* 4, 23 */ \
IF_FEATURE_LS_FOLLOWLINKS("LH") /* 2, 25 */ \
IF_FEATURE_HUMAN_READABLE("h") /* 1, 26 */ \
IF_FEATURE_LS_WIDTH("T:w:") /* 2, 28 */ \
IF_LONG_OPTS("\xff") /* 1, 29 */ \
IF_LONG_OPTS("\xfe") /* 1, 30 */ \
IF_LONG_OPTS("\xfd::") /* 1, 31 */ \
"qk" /* 2, 33 */
#if ENABLE_LONG_OPTS
static const char ls_longopts[] ALIGN1 =
"full-time\0" No_argument "\xff"
"group-directories-first\0" No_argument "\xfe"
IF_FEATURE_LS_COLOR("color\0" Optional_argument "\xfd")
;
#endif
enum {
OPT_C = (1 << 0),
@@ -230,29 +254,31 @@ enum {
OPT_s = (1 << 8),
OPT_x = (1 << 9),
OPT_A = (1 << 10),
//OPT_k = (1 << 11),
OPTBIT_F = 12,
OPTBIT_p, /* 13 */
OPTBIT_F = 11,
OPTBIT_p, /* 12 */
OPTBIT_R = OPTBIT_F + 2 * ENABLE_FEATURE_LS_FILETYPES,
OPTBIT_Z = OPTBIT_R + 1 * ENABLE_FEATURE_LS_RECURSIVE,
OPTBIT_Q = OPTBIT_Z + 1 * ENABLE_SELINUX,
OPTBIT_c, /* 17 */
OPTBIT_t, /* 18 */
OPTBIT_u, /* 19 */
OPTBIT_c, /* 16 */
OPTBIT_t, /* 17 */
OPTBIT_u, /* 18 */
OPTBIT_S = OPTBIT_c + 3 * ENABLE_FEATURE_LS_TIMESTAMPS,
OPTBIT_X, /* 21 */
OPTBIT_r, /* 22 */
OPTBIT_v, /* 23 */
OPTBIT_X, /* 20 */
OPTBIT_r, /* 21 */
OPTBIT_v, /* 22 */
OPTBIT_L = OPTBIT_S + 4 * ENABLE_FEATURE_LS_SORTFILES,
OPTBIT_H, /* 25 */
OPTBIT_H, /* 24 */
OPTBIT_h = OPTBIT_L + 2 * ENABLE_FEATURE_LS_FOLLOWLINKS,
OPTBIT_T = OPTBIT_h + 1 * ENABLE_FEATURE_HUMAN_READABLE,
OPTBIT_w, /* 28 */
OPTBIT_w, /* 27 */
OPTBIT_full_time = OPTBIT_T + 2 * ENABLE_FEATURE_LS_WIDTH,
OPTBIT_dirs_first,
OPTBIT_color, /* 31 */
/* with long opts, we use all 32 bits */
OPTBIT_color, /* 30 */
OPTBIT_q = OPTBIT_color + 1, /* 31 */
OPTBIT_k = OPTBIT_q + 1, /* 32 */
/* with all options enabled, we use all 32 bits and even one extra bit! */
/* this works because -k is ignored, and getopt32 allows such "ignore" options past 31th bit */
OPT_F = (1 << OPTBIT_F) * ENABLE_FEATURE_LS_FILETYPES,
OPT_p = (1 << OPTBIT_p) * ENABLE_FEATURE_LS_FILETYPES,
@@ -274,6 +300,8 @@ enum {
OPT_full_time = (1 << OPTBIT_full_time ) * ENABLE_LONG_OPTS,
OPT_dirs_first = (1 << OPTBIT_dirs_first) * ENABLE_LONG_OPTS,
OPT_color = (1 << OPTBIT_color ) * ENABLE_FEATURE_LS_COLOR,
OPT_q = (1 << OPTBIT_q),
//-k is ignored: OPT_k = (1 << OPTBIT_k),
};
/*
@@ -283,7 +311,7 @@ struct dnode {
const char *name; /* usually basename, but think "ls -l dir/file" */
const char *fullname; /* full name (usable for stat etc) */
struct dnode *dn_next; /* for linked list */
IF_SELINUX(security_context_t sid;)
IF_SELINUX(char *sid;)
smallint fname_allocated;
/* Used to avoid re-doing [l]stat at printout stage
@@ -327,6 +355,7 @@ struct globals {
#endif
smallint exit_code;
smallint show_dirname;
smallint tty_out;
#if ENABLE_FEATURE_LS_WIDTH
unsigned terminal_width;
# define G_terminal_width (G.terminal_width)
@@ -343,16 +372,21 @@ struct globals {
setup_common_bufsiz(); \
/* we have to zero it out because of NOEXEC */ \
memset(&G, 0, sizeof(G)); \
IF_FEATURE_LS_WIDTH(G_terminal_width = TERMINAL_WIDTH;) \
IF_FEATURE_LS_WIDTH(G_terminal_width = ~0U;) \
IF_FEATURE_LS_TIMESTAMPS(time(&G.current_time_t);) \
} while (0)
#define ESC "\033"
static int G_isatty(void)
{
if (!G.tty_out) /* not known yet? */
G.tty_out = isatty(STDOUT_FILENO) + 1;
return (G.tty_out == 2);
}
/*** Output code ***/
/* FYI type values: 1:fifo 2:char 4:dir 6:blk 8:file 10:link 12:socket
* (various wacky OSes: 13:Sun door 14:BSD whiteout 5:XENIX named file
* 3/7:multiplexed char/block device)
@@ -415,28 +449,6 @@ static char append_char(mode_t mode)
}
#endif
static unsigned calc_name_len(const char *name)
{
unsigned len;
uni_stat_t uni_stat;
// TODO: quote tab as \t, etc, if -Q
name = printable_string2(&uni_stat, name);
if (!(option_mask32 & OPT_Q)) {
return uni_stat.unicode_width;
}
len = 2 + uni_stat.unicode_width;
while (*name) {
if (*name == '"' || *name == '\\') {
len++;
}
name++;
}
return len;
}
/* Return the number of used columns.
* Note that only columnar output uses return value.
* -l and -1 modes don't care.
@@ -444,27 +456,86 @@ static unsigned calc_name_len(const char *name)
* ls -b (--escape) = octal escapes (although it doesn't look like working)
* ls -N (--literal) = not escape at all
*/
static unsigned calc_name_len(const char *name)
{
unsigned len;
uni_stat_t uni_stat;
if (!(option_mask32 & (OPT_q|OPT_Q)))
return strlen(name);
if (!(option_mask32 & OPT_Q)) {
/* the most likely branch: "ls" to tty (it auto-enables -q behavior) */
printable_string2(&uni_stat, name);
return uni_stat.unicode_width;
}
len = 2 + strlen(name);
while (*name) {
unsigned char ch = (unsigned char)*name;
if (ch < ' ' || ch > 0x7e) {
ch -= 7;
if (ch <= 6) {
/* quote chars 7..13 as \a,b,t,n,v,f,r */
goto two;
}
/* other chars <32 or >126 as \ooo octal */
len += 3;
goto next;
}
if (*name == '"' || *name == '\\') {
two:
len++;
}
next:
name++;
}
return len;
}
static unsigned print_name(const char *name)
{
unsigned len;
uni_stat_t uni_stat;
// TODO: quote tab as \t, etc, if -Q
name = printable_string2(&uni_stat, name);
if (!(option_mask32 & (OPT_q|OPT_Q))) {
fputs_stdout(name);
return strlen(name);
}
if (!(option_mask32 & OPT_Q)) {
/* the most likely branch: "ls" to tty (it auto-enables -q behavior) */
name = printable_string2(&uni_stat, name);
fputs_stdout(name);
return uni_stat.unicode_width;
}
len = 2 + uni_stat.unicode_width;
len = 2 + strlen(name);
putchar('"');
while (*name) {
if (*name == '"' || *name == '\\') {
unsigned char ch = (unsigned char)*name;
if (ch < ' ' || ch > 0x7e) {
putchar('\\');
ch -= 7;
if (ch <= 6) {
/* quote chars 7..13 as \a,b,t,n,v,f,r */
ch = c_escape_conv_str07[1 + 3 * ch];
goto two;
}
/* other chars <32 or >126 as \ooo octal */
ch = (unsigned char)*name;
putchar('0' + (ch>>6));
putchar('0' + ((ch>>3) & 7));
ch = '0' + (ch & 7);
len += 3;
goto put_ch;
}
if (ch == '"' || ch == '\\') {
putchar('\\');
two:
len++;
}
putchar(*name);
put_ch:
putchar(ch);
name++;
}
putchar('"');
@@ -498,9 +569,16 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
if (opt & OPT_i) /* show inode# */
column += printf("%7llu ", (long long) dn->dn_ino);
//TODO: -h should affect -s too:
if (opt & OPT_s) /* show allocated blocks */
column += printf("%6"OFF_FMT"u ", (off_t) (dn->dn_blocks >> 1));
if (opt & OPT_s) { /* show allocated blocks */
if (opt & OPT_h) {
column += printf("%"HUMAN_READABLE_MAX_WIDTH_STR"s ",
/* print size, show one fractional, use suffixes */
make_human_readable_str((off_t)dn->dn_blocks << 9, 1, 0)
);
} else {
column += printf("%6"OFF_FMT"u ", (off_t)(dn->dn_blocks >> 1));
}
}
if (opt & OPT_l) {
/* long listing: show mode */
char modestr[12];
@@ -519,10 +597,10 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
#if ENABLE_FEATURE_LS_USERNAME
else {
if (opt & OPT_g) {
column += printf("%-8.8s ",
column += printf("%-8s ",
get_cached_groupname(dn->dn_gid));
} else {
column += printf("%-8.8s %-8.8s ",
column += printf("%-8s %-8s ",
get_cached_username(dn->dn_uid),
get_cached_groupname(dn->dn_gid));
}
@@ -639,7 +717,7 @@ static void display_files(struct dnode **dn, unsigned nfiles)
unsigned i, ncols, nrows, row, nc;
unsigned column;
unsigned nexttab;
unsigned column_width = 0; /* used only by coulmnal output */
unsigned column_width = 0; /* used only by columnar output */
if (option_mask32 & (OPT_l|OPT_1)) {
ncols = 1;
@@ -684,6 +762,11 @@ static void display_files(struct dnode **dn, unsigned nfiles)
}
nexttab = column + column_width;
column += display_single(dn[i]);
} else {
/* if -w999999999, ncols can be very large */
//bb_error_msg(" col:%u ncol:%u i:%i", nc, ncols, i); sleep1();
/* without "break", we loop millions of times here */
break;
}
}
putchar('\n');
@@ -1083,25 +1166,11 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
/* need to initialize since --color has _an optional_ argument */
const char *color_opt = color_str; /* "always" */
#endif
#if ENABLE_LONG_OPTS
static const char ls_longopts[] ALIGN1 =
"full-time\0" No_argument "\xff"
"group-directories-first\0" No_argument "\xfe"
IF_FEATURE_LS_COLOR("color\0" Optional_argument "\xfd")
;
#endif
INIT_G();
init_unicode();
#if ENABLE_FEATURE_LS_WIDTH
/* obtain the terminal width */
G_terminal_width = get_terminal_width(STDIN_FILENO);
/* go one less... */
G_terminal_width--;
#endif
/* process options */
opt = getopt32long(argv, "^"
ls_options
@@ -1137,6 +1206,29 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
exit(0);
#endif
/* ftpd secret backdoor? */
if (ENABLE_FTPD && applet_name[0] == 'f') {
/* dirs first are much nicer */
opt = option_mask32 |= OPT_dirs_first;
/* don't show SEcontext */
IF_SELINUX(opt = option_mask32 &= ~OPT_Z;)
/* do not query stdout about size and tty-ness */
IF_FEATURE_LS_WIDTH(G_terminal_width = INT_MAX;)
G.tty_out = 1; /* not a tty */
goto skip_if_ftpd;
}
#if ENABLE_FEATURE_LS_WIDTH
if ((int)G_terminal_width < 0) {
/* obtain the terminal width */
G_terminal_width = get_terminal_width(STDIN_FILENO);
/* go one less... */
G_terminal_width--;
}
if (G_terminal_width == 0) /* -w0 */
G_terminal_width = INT_MAX; /* "infinite" */
#endif
#if ENABLE_SELINUX
if (opt & OPT_Z) {
if (!is_selinux_enabled())
@@ -1150,7 +1242,7 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
char *p = getenv("LS_COLORS");
/* LS_COLORS is unset, or (not empty && not "none") ? */
if (!p || (p[0] && strcmp(p, "none") != 0)) {
if (isatty(STDOUT_FILENO)) {
if (G_isatty()) {
/* check isatty() last because it's expensive (syscall) */
G_show_color = 1;
}
@@ -1159,23 +1251,28 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
if (opt & OPT_color) {
if (color_opt[0] == 'n')
G_show_color = 0;
else switch (index_in_substrings(color_str, color_opt)) {
case 3:
case 4:
case 5:
if (!is_TERM_dumb() && isatty(STDOUT_FILENO)) {
case 0:
case 1:
case 2:
G_show_color = 1;
else if (!G_show_color) {
/* if() is not needed, but avoids extra isatty() if G_show_color is already set */
/* Check --color=COLOR_OPT and maybe set show_color=1 */
switch (index_in_substrings(color_str, color_opt)) {
case 3: // auto
case 4: // tty
case 5: // if-tty
if (!is_TERM_dumb() && G_isatty()) {
case 0: // always
case 1: // yes
case 2: // force
G_show_color = 1;
}
}
}
}
#endif
skip_if_ftpd:
/* sort out which command line options take precedence */
if (ENABLE_FEATURE_LS_RECURSIVE && (opt & OPT_d))
option_mask32 &= ~OPT_R; /* no recurse if listing only dir */
opt = option_mask32 &= ~OPT_R; /* no recurse if listing only dir */
if (!(opt & OPT_l)) { /* not -l? */
if (ENABLE_FEATURE_LS_TIMESTAMPS && ENABLE_FEATURE_LS_SORTFILES) {
/* when to sort by time? -t[cu] sorts by time even with -l */
@@ -1183,19 +1280,17 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
/* without -l, bare -c or -u enable sort too */
/* (with -l, bare -c or -u just select which time to show) */
if (opt & (OPT_c|OPT_u)) {
option_mask32 |= OPT_t;
opt = option_mask32 |= OPT_t;
}
}
}
/* choose a display format if one was not already specified by an option */
if (!(option_mask32 & (OPT_l|OPT_1|OPT_x|OPT_C)))
option_mask32 |= (isatty(STDOUT_FILENO) ? OPT_C : OPT_1);
if (!(opt & (OPT_l|OPT_1|OPT_x|OPT_C)))
opt = option_mask32 |= (G_isatty() ? OPT_C : OPT_1);
if (ENABLE_FTPD && applet_name[0] == 'f') {
/* ftpd secret backdoor. dirs first are much nicer */
option_mask32 |= OPT_dirs_first;
}
if (!(opt & OPT_q) && G_isatty())
opt = option_mask32 |= OPT_q;
argv += optind;
if (!argv[0])
+80 -42
View File
@@ -6,42 +6,48 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config MD5SUM
//config: bool "md5sum (6.5 kb)"
//config: bool "md5sum (6.7 kb)"
//config: default y
//config: help
//config: Compute and check MD5 message digest
//config:
//config:config SHA1SUM
//config: bool "sha1sum (5.9 kb)"
//config: bool "sha1sum (6.7 kb)"
//config: default y
//config: help
//config: Compute and check SHA1 message digest
//config:
//config:config SHA256SUM
//config: bool "sha256sum (7 kb)"
//config: bool "sha256sum (8.2 kb)"
//config: default y
//config: help
//config: Compute and check SHA256 message digest
//config:
//config:config SHA384SUM
//config: bool "sha384sum (7.3 kb)"
//config: default y
//config: help
//config: Compute and check SHA384 message digest
//config:
//config:config SHA512SUM
//config: bool "sha512sum (7.4 kb)"
//config: bool "sha512sum (7.3 kb)"
//config: default y
//config: help
//config: Compute and check SHA512 message digest
//config:
//config:config SHA3SUM
//config: bool "sha3sum (6.1 kb)"
//config: bool "sha3sum (6.3 kb)"
//config: default y
//config: help
//config: Compute and check SHA3 message digest
//config:
//config:comment "Common options for md5sum, sha1sum, sha256sum, sha512sum, sha3sum"
//config: depends on MD5SUM || SHA1SUM || SHA256SUM || SHA512SUM || SHA3SUM
//config:comment "Common options for md5sum, sha1sum, sha256sum, ..., sha3sum"
//config: depends on MD5SUM || SHA1SUM || SHA256SUM || SHA384SUM || SHA512SUM || SHA3SUM
//config:
//config:config FEATURE_MD5_SHA1_SUM_CHECK
//config: bool "Enable -c, -s and -w options"
//config: default y
//config: depends on MD5SUM || SHA1SUM || SHA256SUM || SHA512SUM || SHA3SUM
//config: depends on MD5SUM || SHA1SUM || SHA256SUM || SHA384SUM || SHA512SUM || SHA3SUM
//config: help
//config: Enabling the -c options allows files to be checked
//config: against pre-calculated hash values.
@@ -51,11 +57,13 @@
//applet:IF_SHA1SUM(APPLET_NOEXEC(sha1sum, md5_sha1_sum, BB_DIR_USR_BIN, BB_SUID_DROP, sha1sum))
//applet:IF_SHA3SUM(APPLET_NOEXEC(sha3sum, md5_sha1_sum, BB_DIR_USR_BIN, BB_SUID_DROP, sha3sum))
//applet:IF_SHA256SUM(APPLET_NOEXEC(sha256sum, md5_sha1_sum, BB_DIR_USR_BIN, BB_SUID_DROP, sha256sum))
//applet:IF_SHA384SUM(APPLET_NOEXEC(sha384sum, md5_sha1_sum, BB_DIR_USR_BIN, BB_SUID_DROP, sha384sum))
//applet:IF_SHA512SUM(APPLET_NOEXEC(sha512sum, md5_sha1_sum, BB_DIR_USR_BIN, BB_SUID_DROP, sha512sum))
//kbuild:lib-$(CONFIG_MD5SUM) += md5_sha1_sum.o
//kbuild:lib-$(CONFIG_SHA1SUM) += md5_sha1_sum.o
//kbuild:lib-$(CONFIG_SHA256SUM) += md5_sha1_sum.o
//kbuild:lib-$(CONFIG_SHA384SUM) += md5_sha1_sum.o
//kbuild:lib-$(CONFIG_SHA512SUM) += md5_sha1_sum.o
//kbuild:lib-$(CONFIG_SHA3SUM) += md5_sha1_sum.o
@@ -99,6 +107,16 @@
//usage: "\n -w Warn about improperly formatted checksum lines"
//usage: )
//usage:
//usage:#define sha384sum_trivial_usage
//usage: IF_FEATURE_MD5_SHA1_SUM_CHECK("[-c[sw]] ")"[FILE]..."
//usage:#define sha384sum_full_usage "\n\n"
//usage: "Print" IF_FEATURE_MD5_SHA1_SUM_CHECK(" or check") " SHA384 checksums"
//usage: IF_FEATURE_MD5_SHA1_SUM_CHECK( "\n"
//usage: "\n -c Check sums against list in FILEs"
//usage: "\n -s Don't output anything, status code shows success"
//usage: "\n -w Warn about improperly formatted checksum lines"
//usage: )
//usage:
//usage:#define sha512sum_trivial_usage
//usage: IF_FEATURE_MD5_SHA1_SUM_CHECK("[-c[sw]] ")"[FILE]..."
//usage:#define sha512sum_full_usage "\n\n"
@@ -130,16 +148,18 @@
enum {
/* 4th letter of applet_name is... */
HASH_MD5 = 's', /* "md5>s<um" */
HASH_SHA1 = '1',
HASH_MD5 = 's', /* "md5>s<um" */
HASH_SHA1 = '1',
HASH_SHA256 = '2',
HASH_SHA3 = '3',
HASH_SHA3 = '3',
HASH_SHA512 = '5',
/* unfortunately, sha384sum has the same '3' as sha3 */
};
#define FLAG_SILENT 1
#define FLAG_CHECK 2
#define FLAG_WARN 4
#define FLAG_BINARY 8
/* This might be useful elsewhere */
static unsigned char *hash_bin_to_hex(unsigned char *hash_value,
@@ -151,15 +171,18 @@ static unsigned char *hash_bin_to_hex(unsigned char *hash_value,
return (unsigned char *)hex_value;
}
#define BUFSZ (CONFIG_FEATURE_COPYBUF_KB < 4 ? 4096 : CONFIG_FEATURE_COPYBUF_KB * 1024)
#if !ENABLE_SHA3SUM
# define hash_file(f,w) hash_file(f)
# define hash_file(b,f,w) hash_file(b,f)
#endif
static uint8_t *hash_file(const char *filename, unsigned sha3_width)
static uint8_t *hash_file(unsigned char *in_buf, const char *filename, unsigned sha3_width)
{
int src_fd, hash_len, count;
int src_fd, count;
union _ctx_ {
sha3_ctx_t sha3;
sha512_ctx_t sha512;
sha384_ctx_t sha384;
sha256_ctx_t sha256;
sha1_ctx_t sha1;
md5_ctx_t md5;
@@ -181,25 +204,31 @@ static uint8_t *hash_file(const char *filename, unsigned sha3_width)
md5_begin(&context.md5);
update = (void*)md5_hash;
final = (void*)md5_end;
hash_len = 16;
}
else if (ENABLE_SHA1SUM && hash_algo == HASH_SHA1) {
sha1_begin(&context.sha1);
update = (void*)sha1_hash;
final = (void*)sha1_end;
hash_len = 20;
}
else if (ENABLE_SHA256SUM && hash_algo == HASH_SHA256) {
sha256_begin(&context.sha256);
update = (void*)sha256_hash;
final = (void*)sha256_end;
hash_len = 32;
}
else if (ENABLE_SHA384SUM
&& (ENABLE_SHA3SUM
? (applet_name[4] == '8') /* check for "sha384", but do not match "sha3" */
: (hash_algo == '3') /* applet_name = "sha3sum" is not possible */
)
) {
sha384_begin(&context.sha384);
update = (void*)sha384_hash;
final = (void*)sha384_end;
}
else if (ENABLE_SHA512SUM && hash_algo == HASH_SHA512) {
sha512_begin(&context.sha512);
update = (void*)sha512_hash;
final = (void*)sha512_end;
hash_len = 64;
}
#if ENABLE_SHA3SUM
else if (ENABLE_SHA3SUM && hash_algo == HASH_SHA3) {
@@ -217,9 +246,7 @@ static uint8_t *hash_file(const char *filename, unsigned sha3_width)
) {
bb_error_msg_and_die("bad -a%u", sha3_width);
}
sha3_width /= 4;
context.sha3.input_block_bytes = 1600/8 - sha3_width;
hash_len = sha3_width/2;
context.sha3.input_block_bytes = 1600/8 - sha3_width/4;
}
#endif
else {
@@ -227,18 +254,16 @@ static uint8_t *hash_file(const char *filename, unsigned sha3_width)
}
{
RESERVE_CONFIG_UBUFFER(in_buf, 4096);
while ((count = safe_read(src_fd, in_buf, 4096)) > 0) {
while ((count = safe_read(src_fd, in_buf, BUFSZ)) > 0) {
update(&context, in_buf, count);
}
hash_value = NULL;
if (count < 0)
bb_perror_msg("can't read '%s'", filename);
else /* count == 0 */ {
final(&context, in_buf);
unsigned hash_len = final(&context, in_buf);
hash_value = hash_bin_to_hex(in_buf, hash_len);
}
RELEASE_CONFIG_BUFFER(in_buf);
}
if (src_fd != STDIN_FILENO) {
@@ -251,24 +276,30 @@ static uint8_t *hash_file(const char *filename, unsigned sha3_width)
int md5_sha1_sum_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv)
{
unsigned char *in_buf;
int return_value = EXIT_SUCCESS;
unsigned flags;
#if ENABLE_SHA3SUM
unsigned sha3_width = 224;
#endif
const char *fmt = "%s %s\n";
if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK) {
/* -b "binary", -t "text" are ignored (shaNNNsum compat) */
/* -t per se is a no-op (it means "text mode").
* -b sets the '*' binary mode indicator in the output.
* -t unsets -b (-bt is the same as -t, which is the same as no option) */
/* -s and -w require -c */
#if ENABLE_SHA3SUM
if (applet_name[3] == HASH_SHA3)
flags = getopt32(argv, "^" "scwbta:+" "\0" "s?c:w?c", &sha3_width);
if (applet_name[3] == HASH_SHA3 && (!ENABLE_SHA384SUM || applet_name[4] != '8'))
flags = getopt32(argv, "^" "scwbta:+" "\0" "t-b:s?c:w?c", &sha3_width);
else
#endif
flags = getopt32(argv, "^" "scwbt" "\0" "s?c:w?c");
flags = getopt32(argv, "^" "scwbt" "\0" "t-b:s?c:w?c");
if (flags & FLAG_BINARY)
fmt = "%s *%s\n";
} else {
#if ENABLE_SHA3SUM
if (applet_name[3] == HASH_SHA3)
if (applet_name[3] == HASH_SHA3 && (!ENABLE_SHA384SUM || applet_name[4] != '8'))
getopt32(argv, "a:+", &sha3_width);
else
#endif
@@ -279,6 +310,12 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv)
if (!*argv)
*--argv = (char*)"-";
/* The buffer is not alloc/freed for each input file:
* for big values of COPYBUF_KB, this helps to keep its pages
* pre-faulted and possibly even fully cached on local CPU.
*/
in_buf = xmalloc(BUFSZ);
do {
if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK && (flags & FLAG_CHECK)) {
FILE *pre_computed_stream;
@@ -293,12 +330,8 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv)
char *filename_ptr;
count_total++;
filename_ptr = strstr(line, " ");
/* handle format for binary checksums */
if (filename_ptr == NULL) {
filename_ptr = strstr(line, " *");
}
if (filename_ptr == NULL) {
filename_ptr = strchr(line, ' ');
if (!filename_ptr) {
if (flags & FLAG_WARN) {
bb_simple_error_msg("invalid format");
}
@@ -307,12 +340,17 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv)
free(line);
continue;
}
*filename_ptr = '\0';
filename_ptr += 2;
*filename_ptr++ = '\0';
/* coreutils 9.1 allows "HASH FILENAME" format,
* with only one space. Skip the 'correct'
* " " or " *" delimiter if it is there:
*/
if (*filename_ptr == ' ' || *filename_ptr == '*')
filename_ptr++;
hash_value = hash_file(filename_ptr, sha3_width);
hash_value = hash_file(in_buf, filename_ptr, sha3_width);
if (hash_value && (strcmp((char*)hash_value, line) == 0)) {
if (hash_value && (strcasecmp((char*)hash_value, line) == 0)) {
if (!(flags & FLAG_SILENT))
printf("%s: OK\n", filename_ptr);
} else {
@@ -339,11 +377,11 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv)
}
fclose_if_not_stdin(pre_computed_stream);
} else {
uint8_t *hash_value = hash_file(*argv, sha3_width);
uint8_t *hash_value = hash_file(in_buf, *argv, sha3_width);
if (hash_value == NULL) {
return_value = EXIT_FAILURE;
} else {
printf("%s %s\n", hash_value, *argv);
printf(fmt, hash_value, *argv);
free(hash_value);
}
}
+2 -2
View File
@@ -14,7 +14,7 @@
/* Nov 28, 2006 Yoshinori Sato <ysato@users.sourceforge.jp>: Add SELinux Support.
*/
//config:config MKDIR
//config: bool "mkdir (4.5 kb)"
//config: bool "mkdir (4.7 kb)"
//config: default y
//config: help
//config: mkdir is used to create directories with the specified names.
@@ -57,7 +57,7 @@ int mkdir_main(int argc UNUSED_PARAM, char **argv)
unsigned opt;
char *smode;
#if ENABLE_SELINUX
security_context_t scontext;
char *scontext;
#endif
opt = getopt32long(argv, "m:pv" IF_SELINUX("Z:"),
+1 -1
View File
@@ -7,7 +7,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config MKFIFO
//config: bool "mkfifo (3.8 kb)"
//config: bool "mkfifo (4 kb)"
//config: default y
//config: help
//config: mkfifo is used to create FIFOs (named pipes).
+1 -1
View File
@@ -7,7 +7,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config MKNOD
//config: bool "mknod (4.5 kb)"
//config: bool "mknod (4.6 kb)"
//config: default y
//config: help
//config: mknod is used to create FIFOs or block/character special
+1 -1
View File
@@ -29,7 +29,7 @@
* -p; else /tmp [deprecated]
*/
//config:config MKTEMP
//config: bool "mktemp (4.2 kb)"
//config: bool "mktemp (4.5 kb)"
//config: default y
//config: help
//config: mktemp is used to create unique temporary files
+2 -2
View File
@@ -71,9 +71,9 @@ int mv_main(int argc, char **argv)
"no-target-directory\0" No_argument "T"
"target-directory\0" Required_argument "t"
IF_FEATURE_VERBOSE(
"verbose\0" No_argument "v",
&last
"verbose\0" No_argument "v"
)
, &last
);
argc -= optind;
argv += optind;
+2 -2
View File
@@ -7,7 +7,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config NICE
//config: bool "nice (2.1 kb)"
//config: bool "nice (2.3 kb)"
//config: default y
//config: help
//config: nice runs a program with modified scheduling priority.
@@ -33,7 +33,7 @@ int nice_main(int argc UNUSED_PARAM, char **argv)
if (!*++argv) { /* No args, so (GNU) output current nice value. */
printf("%d\n", old_priority);
fflush_stdout_and_exit(EXIT_SUCCESS);
fflush_stdout_and_exit_SUCCESS();
}
adjustment = 10; /* Set default adjustment. */
+1 -1
View File
@@ -5,7 +5,7 @@
* Licensed under GPLv2, see file LICENSE in this source tree.
*/
//config:config NL
//config: bool "nl (4.6 kb)"
//config: bool "nl (4.9 kb)"
//config: default y
//config: help
//config: nl is used to number lines of files.
+1 -1
View File
@@ -11,7 +11,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config NOHUP
//config: bool "nohup (2 kb)"
//config: bool "nohup (2.2 kb)"
//config: default y
//config: help
//config: run a command immune to hangups, with output to a non-tty.
+9 -11
View File
@@ -4,7 +4,7 @@
* Licensed under GPLv2, see LICENSE in this source tree
*/
//config:config NPROC
//config: bool "nproc (3.7 kb)"
//config: bool "nproc (3.9 kb)"
//config: default y
//config: help
//config: Print number of CPUs
@@ -23,13 +23,11 @@
//usage: "\n --ignore=N Exclude N CPUs"
//usage: )
#include <sched.h>
#include "libbb.h"
int nproc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int nproc_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
{
unsigned long mask[1024];
int count = 0;
#if ENABLE_LONG_OPTS
int ignore = 0;
@@ -52,16 +50,16 @@ int nproc_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
}
} else
#endif
if (sched_getaffinity(0, sizeof(mask), (void*)mask) == 0) {
{
int i;
for (i = 0; i < ARRAY_SIZE(mask); i++) {
unsigned long m = mask[i];
while (m) {
if (m & 1)
count++;
m >>= 1;
}
unsigned sz = 2 * 1024;
unsigned long *mask = get_malloc_cpu_affinity(0, &sz);
sz /= sizeof(long);
for (i = 0; i < sz; i++) {
if (mask[i] != 0) /* most mask[i] are usually 0 */
count += bb_popcnt_long(mask[i]);
}
IF_FEATURE_CLEAN_UP(free(mask);)
}
IF_LONG_OPTS(count -= ignore;)
+50 -25
View File
@@ -22,7 +22,9 @@
//usage:#if !ENABLE_DESKTOP
//usage:#define od_trivial_usage
//usage: "[-aBbcDdeFfHhIiLlOovXx] [FILE]"
//usage: "[-abcdeFfhiloxsv] [FILE]"
// We also support -BDOHXIL, but they are not documented in coreutils 9.1
// manpage/help, so don't show them either.
//usage:#define od_full_usage "\n\n"
//usage: "Print FILE (or stdin) unambiguously, as octal bytes by default"
//usage:#endif
@@ -144,29 +146,50 @@ odoffset(dumper_t *dumper, int argc, char ***argvp)
}
}
static const char *const add_strings[] = {
"16/1 \"%3_u \" \"\\n\"", /* a */
"8/2 \" %06o \" \"\\n\"", /* B, o */
"16/1 \"%03o \" \"\\n\"", /* b */
"16/1 \"%3_c \" \"\\n\"", /* c */
"8/2 \" %05u \" \"\\n\"", /* d */
"4/4 \" %010u \" \"\\n\"", /* D */
"2/8 \" %21.14e \" \"\\n\"", /* e (undocumented in od), F */
"4/4 \" %14.7e \" \"\\n\"", /* f */
"4/4 \" %08x \" \"\\n\"", /* H, X */
"8/2 \" %04x \" \"\\n\"", /* h, x */
"4/4 \" %11d \" \"\\n\"", /* I, L, l */
"8/2 \" %6d \" \"\\n\"", /* i */
"4/4 \" %011o \" \"\\n\"", /* O */
// bb_dump_add():
// A format string contains format units separated by [optional] whitespace.
// A format unit contains up to three items: an iteration count, a byte count,
// and a format.
// The iteration count is an optional integer (default 1).
// Each format is applied iteration count times.
// The byte count is an optional integer. It defines the number
// of bytes to be interpreted by each iteration of the format.
// If an iteration count and/or a byte count is specified, a slash must be
// placed after the iteration count and/or before the byte count
// to disambiguate them.
// The printf-style format is required and must be surrounded by " "s.
// (Below, each string contains two format units)
static const char *const add_strings[] ALIGN_PTR = {
"16/1 \" %3_u\"" "\"\n\"", /* 0: a */
"8/2 \" %06o\"" "\"\n\"", /* 1: B (undocumented in od), o */
"16/1 \" %03o\"" "\"\n\"", /* 2: b */
"16/1 \" %3_c\"" "\"\n\"", /* 3: c */
"8/2 \" %5u\"" "\"\n\"", /* 4: d */
"4/4 \" %10u\"" "\"\n\"", /* 5: D */
"2/8 \" %24.14e\"" "\"\n\"", /* 6: e (undocumented in od), F */
"4/4 \" %15.7e\"" "\"\n\"", /* 7: f */
"4/4 \" %08x\"" "\"\n\"", /* 8: H, X */
"8/2 \" %04x\"" "\"\n\"", /* 9: h, x */
"4/4 \" %11d\"" "\"\n\"", /* 10: i */
"4/4 \" %011o\"" "\"\n\"", /* 11: O */
"8/2 \" %6d\"" "\"\n\"", /* 12: s */
/* -I,L,l: depend on word width of the arch (what is "long"?) */
#if ULONG_MAX > 0xffffffff
"2/8 \" %20lld\"" "\"\n\"", /* 13: I, L, l */
#define L_ 13
#else
/* 32-bit arch: -I,L,l are the same as -i */
#define L_ 10
#endif
};
static const char od_opts[] ALIGN1 = "aBbcDdeFfHhIiLlOoXxv";
static const char od_opts[] ALIGN1 = "aBbcDdeFfHhIiLlOoXxsv";
static const char od_o2si[] ALIGN1 = {
0, 1, 2, 3, 5,
4, 6, 6, 7, 8,
9, 0xa, 0xb, 0xa, 0xa,
0xb, 1, 8, 9,
0, 1, 2, 3, 5, /* aBbcD */
4, 6, 6, 7, 8, /* deFfH */
9, L_, 10, L_, L_, /* hIiLl */
11, 1, 8, 9, 12 /* OoXxs */
};
int od_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
@@ -184,19 +207,21 @@ int od_main(int argc, char **argv)
if (first) {
first = 0;
bb_dump_add(dumper, "\"%07.7_Ao\n\"");
bb_dump_add(dumper, "\"%07.7_ao \"");
bb_dump_add(dumper, "\"%07.7_ao\"");
} else {
bb_dump_add(dumper, "\" \"");
bb_dump_add(dumper, "\" \"");
}
bb_dump_add(dumper, add_strings[(int)od_o2si[(p - od_opts)]]);
} else { /* P, p, s, w, or other unhandled */
} else { /* P, p, w, or other unhandled */
bb_show_usage();
}
}
if (!dumper->fshead) {
bb_dump_add(dumper, "\"%07.7_Ao\n\"");
bb_dump_add(dumper, "\"%07.7_ao \" 8/2 \"%06o \" \"\\n\"");
bb_dump_add(dumper, "\"%07.7_ao\"");
bb_dump_add(dumper, add_strings[1]); /* -o format is default */
}
dumper->od_eofstring = "\n";
argc -= optind;
argv += optind;
@@ -205,7 +230,7 @@ int od_main(int argc, char **argv)
return bb_dump_dump(dumper, argv);
}
#endif /* ENABLE_DESKTOP */
#endif /* !ENABLE_DESKTOP */
/*-
* Copyright (c) 1990 The Regents of the University of California.
+41 -22
View File
@@ -27,6 +27,8 @@
//usage:#if ENABLE_DESKTOP
//usage:#define od_trivial_usage
//usage: "[-abcdfhilovxs] [-t TYPE] [-A RADIX] [-N SIZE] [-j SKIP] [-S MINSTR] [-w WIDTH] [FILE]..."
// We also support -BDOHXIL, but they are not documented in coreutils 9.1
// manpage/help, so don't show them either.
// We don't support:
// ... [FILE] [[+]OFFSET[.][b]]
// Support is buggy for:
@@ -43,26 +45,33 @@ enum {
OPT_b = 1 << 3,
OPT_c = 1 << 4,
OPT_d = 1 << 5,
OPT_f = 1 << 6,
OPT_h = 1 << 7,
OPT_i = 1 << 8,
OPT_j = 1 << 9,
OPT_l = 1 << 10,
OPT_o = 1 << 11,
OPT_t = 1 << 12,
OPT_D = 1 << 6, /* undocumented in coreutils 9.1 */
OPT_f = 1 << 7,
OPT_h = 1 << 8,
OPT_H = 1 << 9, /* undocumented in coreutils 9.1 */
OPT_i = 1 << 10,
OPT_I = 1 << 11, /* undocumented in coreutils 9.1 */
OPT_j = 1 << 12,
OPT_l = 1 << 13,
OPT_L = 1 << 14, /* undocumented in coreutils 9.1 */
OPT_o = 1 << 15,
OPT_O = 1 << 16, /* undocumented in coreutils 9.1 */
OPT_B = 1 << 17, /* undocumented synonym to -o */
OPT_t = 1 << 18,
/* When zero and two or more consecutive blocks are equal, format
only the first block and output an asterisk alone on the following
line to indicate that identical blocks have been elided: */
OPT_v = 1 << 13,
OPT_x = 1 << 14,
OPT_s = 1 << 15,
OPT_S = 1 << 16,
OPT_w = 1 << 17,
OPT_traditional = (1 << 18) * ENABLE_LONG_OPTS,
OPT_v = 1 << 19,
OPT_x = 1 << 20,
OPT_X = 1 << 21, /* undocumented in coreutils 9.1 */
OPT_s = 1 << 22,
OPT_S = 1 << 23,
OPT_w = 1 << 24,
OPT_traditional = (1 << 25) * ENABLE_LONG_OPTS,
};
#define OD_GETOPT32() getopt32long(argv, \
"A:N:abcdfhij:lot:*vxsS:w:+:", od_longopts, \
"A:N:abcdDfhHiIj:lLoOBt:*vxXsS:w:+:", od_longopts, \
/* -w with optional param */ \
/* -S was -s and also had optional parameter */ \
/* but in coreutils 6.3 it was renamed and now has */ \
@@ -1146,7 +1155,7 @@ dump_strings(off_t address, off_t end_offset)
leading '+' return nonzero and set *OFFSET to the offset it denotes. */
static int
parse_old_offset(const char *s, off_t *offset)
parse_old_offset(char *s, off_t *offset)
{
static const struct suffix_mult Bb[] ALIGN_SUFFIX = {
{ "B", 1024 },
@@ -1172,7 +1181,8 @@ parse_old_offset(const char *s, off_t *offset)
radix = 16;
*offset = xstrtooff_sfx(s, radix, Bb);
if (p) p[0] = '.';
if (p)
p[0] = '.'; /* undo cheating */
return (*offset >= 0);
}
@@ -1225,7 +1235,7 @@ int od_main(int argc UNUSED_PARAM, char **argv)
static const uint8_t doxn_address_pad_len_char[] ALIGN1 = {
'7', '7', '6', /* '?' */
};
char *p;
const char *p;
int pos;
p = strchr(doxn, str_A[0]);
if (!p)
@@ -1239,20 +1249,29 @@ int od_main(int argc UNUSED_PARAM, char **argv)
if (opt & OPT_N) {
max_bytes_to_format = xstrtooff_sfx(str_N, 0, bkm_suffixes);
}
if (opt & OPT_a) decode_format_string("a");
if (opt & OPT_b) decode_format_string("oC");
if (opt & OPT_c) decode_format_string("c");
if (opt & OPT_d) decode_format_string("u2");
if (opt & OPT_D) decode_format_string("uI");
if (opt & OPT_f) decode_format_string("fF");
if (opt & OPT_h) decode_format_string("x2");
if (opt & OPT_i) decode_format_string("d2");
if (opt & (OPT_h|OPT_x)) decode_format_string("x2");
if (opt & (OPT_H|OPT_X)) decode_format_string("xI");
/* -I,L,l: depend on word width of the arch (what is "long"?) */
#if ULONG_MAX > 0xffffffff
if (opt & OPT_i) decode_format_string("dI");
if (opt & (OPT_I|OPT_l|OPT_L)) decode_format_string("dL");
#else
/* 32-bit arch: -I,L,l are the same as -i */
if (opt & (OPT_i|OPT_I|OPT_l|OPT_L)) decode_format_string("dI");
#endif
if (opt & OPT_j) n_bytes_to_skip = xstrtooff_sfx(str_j, 0, bkm_suffixes);
if (opt & OPT_l) decode_format_string("d4");
if (opt & OPT_o) decode_format_string("o2");
if (opt & (OPT_o|OPT_B)) decode_format_string("o2");
if (opt & OPT_O) decode_format_string("oI");
while (lst_t) {
decode_format_string(llist_pop(&lst_t));
}
if (opt & OPT_x) decode_format_string("x2");
if (opt & OPT_s) decode_format_string("d2");
if (opt & OPT_S) {
G.string_min = xstrtou_sfx(str_S, 0, bkm_suffixes);
+24 -12
View File
@@ -7,7 +7,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config PASTE
//config: bool "paste (4.9 kb)"
//config: bool "paste (5.1 kb)"
//config: default y
//config: help
//config: paste is used to paste lines of different files together
@@ -34,27 +34,38 @@
static void paste_files(FILE** files, int file_cnt, char* delims, int del_cnt)
{
char *line;
char **line = xmalloc(file_cnt * sizeof(char *));
char delim;
int active_files = file_cnt;
int i;
while (active_files > 0) {
int del_idx = 0;
int got_line = FALSE;
for (i = 0; i < file_cnt; ++i) {
if (files[i] == NULL)
continue;
if (files[i]) {
line[i] = xmalloc_fgetline(files[i]);
if (!line[i]) {
fclose_if_not_stdin(files[i]);
files[i] = NULL;
--active_files;
} else {
got_line = TRUE;
}
} else {
line[i] = NULL;
}
}
line = xmalloc_fgetline(files[i]);
if (!line) {
fclose_if_not_stdin(files[i]);
files[i] = NULL;
--active_files;
continue;
if (!got_line)
break;
for (i = 0; i < file_cnt; ++i) {
if (line[i]) {
fputs_stdout(line[i]);
free(line[i]);
}
fputs_stdout(line);
free(line);
delim = '\n';
if (i != file_cnt - 1) {
delim = delims[del_idx++];
@@ -65,6 +76,7 @@ static void paste_files(FILE** files, int file_cnt, char* delims, int del_cnt)
fputc(delim, stdout);
}
}
free(line);
}
static void paste_files_separate(FILE** files, char* delims, int del_cnt)
+1 -1
View File
@@ -8,7 +8,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config PRINTENV
//config: bool "printenv (1.3 kb)"
//config: bool "printenv (1.6 kb)"
//config: default y
//config: help
//config: printenv is used to print all or part of environment.
+15 -15
View File
@@ -38,7 +38,7 @@
/* 19990508 Busy Boxed! Dave Cinege */
//config:config PRINTF
//config: bool "printf (3.8 kb)"
//config: bool "printf (4.1 kb)"
//config: default y
//config: help
//config: printf is used to format and print specified strings.
@@ -354,7 +354,8 @@ static char **print_formatted(char *f, char **argv, int *conv_err)
/* Add "ll" if integer modifier, then print */
{
static const char format_chars[] ALIGN1 = "diouxXfeEgGcs";
char *p = strchr(format_chars, *f);
char *p = (char*)strchr(format_chars, *f);
const char *arg = "0";
/* needed - try "printf %" without it */
if (p == NULL || *f == '\0') {
bb_error_msg("%s: invalid format", direc_start);
@@ -373,15 +374,14 @@ static char **print_formatted(char *f, char **argv, int *conv_err)
direc_length += 2;
direc_start = p;
} else {
if (p - format_chars >= 11) /* %c or %s? */
++arg; /* "" */
p = NULL;
}
if (*argv) {
print_direc(direc_start, direc_length, field_width,
precision, *argv++);
} else {
print_direc(direc_start, direc_length, field_width,
precision, "");
}
if (*argv)
arg = *argv++;
print_direc(direc_start, direc_length, field_width,
precision, arg);
*conv_err |= errno;
free(p);
}
@@ -425,10 +425,10 @@ int printf_main(int argc UNUSED_PARAM, char **argv)
/* bash builtin errors out on "printf '-%s-\n' foo",
* coreutils-6.9 works. Both work with "printf -- '-%s-\n' foo".
* We will mimic coreutils. */
if (argv[1] && argv[1][0] == '-' && argv[1][1] == '-' && !argv[1][2])
argv++;
if (!argv[1]) {
if (ENABLE_ASH_PRINTF
argv = skip_dash_dash(argv);
if (!argv[0]) {
if ((ENABLE_ASH_PRINTF || ENABLE_HUSH_PRINTF)
&& applet_name[0] != 'p'
) {
bb_simple_error_msg("usage: printf FORMAT [ARGUMENT...]");
@@ -437,8 +437,8 @@ int printf_main(int argc UNUSED_PARAM, char **argv)
bb_show_usage();
}
format = argv[1];
argv2 = argv + 2;
format = argv[0];
argv2 = argv + 1;
conv_err = 0;
do {
+1 -1
View File
@@ -7,7 +7,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config PWD
//config: bool "pwd (3.7 kb)"
//config: bool "pwd (4 kb)"
//config: default y
//config: help
//config: pwd is used to print the current directory.
+16 -22
View File
@@ -7,7 +7,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config READLINK
//config: bool "readlink (4 kb)"
//config: bool "readlink (4.8 kb)"
//config: default y
//config: help
//config: This program reads a symbolic link and returns the name
@@ -25,12 +25,14 @@
//kbuild:lib-$(CONFIG_READLINK) += readlink.o
//usage:#define readlink_trivial_usage
//usage: IF_FEATURE_READLINK_FOLLOW("[-fnv] ") "FILE"
//usage: IF_FEATURE_READLINK_FOLLOW("[-fnv] ")
//usage: IF_NOT_FEATURE_READLINK_FOLLOW("[-n] ")
//usage: "FILE"
//usage:#define readlink_full_usage "\n\n"
//usage: "Display the value of a symlink"
//usage: IF_FEATURE_READLINK_FOLLOW( "\n"
//usage: "\n -f Canonicalize by following all symlinks"
//usage: "Display the value of a symlink" "\n"
//usage: "\n -n Don't add newline"
//usage: IF_FEATURE_READLINK_FOLLOW(
//usage: "\n -f Canonicalize by following all symlinks"
//usage: "\n -v Verbose"
//usage: )
@@ -66,35 +68,27 @@ int readlink_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int readlink_main(int argc UNUSED_PARAM, char **argv)
{
char *buf;
char *fname;
unsigned opt;
IF_FEATURE_READLINK_FOLLOW(
unsigned opt;
/* We need exactly one non-option argument. */
opt = getopt32(argv, "^" "fnvsq" "\0" "=1");
fname = argv[optind];
)
IF_NOT_FEATURE_READLINK_FOLLOW(
const unsigned opt = 0;
if (argc != 2) bb_show_usage();
fname = argv[1];
)
/* -n must use bit 0 (see printf below) */
opt = getopt32(argv, "^" "n" IF_FEATURE_READLINK_FOLLOW("fvsq")
"\0" "=1");
/* compat: coreutils readlink reports errors silently via exit code */
if (!(opt & 4)) /* not -v */
logmode = LOGMODE_NONE;
/* NOFORK: only one alloc is allowed; must free */
if (opt & 1) { /* -f */
buf = xmalloc_realpath_coreutils(fname);
if (opt & 2) { /* -f */
buf = xmalloc_realpath_coreutils(argv[optind]);
} else {
buf = xmalloc_readlink_or_warn(fname);
buf = xmalloc_readlink_or_warn(argv[optind]);
}
if (!buf)
return EXIT_FAILURE;
printf((opt & 2) ? "%s" : "%s\n", buf);
printf("%s%s", buf, &"\n"[opt & 1]);
free(buf);
fflush_stdout_and_exit(EXIT_SUCCESS);
fflush_stdout_and_exit_SUCCESS();
}
+1 -1
View File
@@ -8,7 +8,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config REALPATH
//config: bool "realpath (1.6 kb)"
//config: bool "realpath (2.5 kb)"
//config: default y
//config: help
//config: Return the canonicalized absolute pathname.
Loaded 100 of 805 files, more files were not shown because too many files have changed in this diff. Show more