Commit Graph

17795 Commits (9f262698cc7e6a8b5621f018645f3c1fa06b226f)

Author SHA1 Message Date
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