100 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
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
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
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
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
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
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
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
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