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