Commit Graph

17716 Commits (e1279858394a6079be6816cbedaa3f10e74057cc)

Author SHA1 Message Date
Denys Vlasenko e127985839 shell/math: fix ?: to not evaluate not-taken branches
This fixes ash-arith-arith-ternary1/2.tests

function                                             old     new   delta
evaluate_string                                     1271    1432    +161
arith_apply                                          968    1000     +32
arith                                                 22      36     +14
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 207/0)             Total: 207 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-16 19:51:01 +02:00
Denys Vlasenko f8263528cd shell/math: simplify handling of unary plus
function                                             old     new   delta
evaluate_string                                     1257    1271     +14
arith_apply                                          977     968      -9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 14/-9)               Total: 5 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-15 17:16:46 +02:00
Denys Vlasenko 38f423cc9c shell/math: explain the logic, small tweak to make code smaller
function                                             old     new   delta
evaluate_string                                     1258    1257      -1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-15 16:46:31 +02:00
Denys Vlasenko ea6dcbe283 shell/math: fix order of expansion of variables to numbers
This fixes arith-assign-in-varexp1.tests

function                                             old     new   delta
evaluate_string                                     1132    1258    +126
arith_lookup_val                                     143       -    -143
arith_apply                                         1132     977    -155
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/1 up/down: 126/-298)         Total: -172 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-15 13:56:12 +02:00
Denys Vlasenko 22cb0d573a shell: document another arithmetic discrepancy with bash
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-15 12:44:43 +02:00
Denys Vlasenko 648f506949 libbb: code shrink: introduce and use [_]exit_FAILURE()
function                                             old     new   delta
exit_FAILURE                                           -       7      +7
_exit_FAILURE                                          -       7      +7
run                                                  198     199      +1
restore_state_and_exit                               114     115      +1
xbsd_write_bootstrap                                 399     397      -2
vfork_compressor                                     209     207      -2
sig_handler                                           12      10      -2
serial_ctl                                           154     152      -2
parse_args                                          1169    1167      -2
onintr                                                21      19      -2
make_new_session                                     493     491      -2
login_main                                           988     986      -2
gotsig                                                35      33      -2
do_iplink                                           1315    1313      -2
addgroup_main                                        397     395      -2
inetd_main                                          1911    1908      -3
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 2/12 up/down: 16/-25)            Total: -9 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-15 11:55:56 +02:00
Denys Vlasenko 61a4959251 shell/math: remove special code to handle a?b?c:d:e, it works without it now
The "hack" to virtually parenthesize ? EXPR : made this unnecessary.
The expression is effectively a?(b?(c):d):e and thus b?c:d is evaluated
before continuing with the second :

function                                             old     new   delta
evaluate_string                                     1148    1132     -16

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-15 11:22:13 +02:00
Denys Vlasenko 5f56a03882 shell/math: fix parsing of ?: and explain why it's parsed that way
This fixes arith-precedence1.tests.

This breaks arith-ternary2.tests again (we now evaluate variables
on not-taken branches). We need a better logic here anyway:
not only bare variables should not evaluate when not-taken:
	1 ? eval_me : do_not_eval
but any (arbitrarily complex) expressions shouldn't
evaluate as well!
	1 ? var_is_set=1 : ((var_is_not_set=2,var2*=4))

function                                             old     new   delta
evaluate_string                                     1097    1148     +51

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-15 10:14:43 +02:00
Denys Vlasenko 3829d8b675 shell/math: simpler insertion of "fake" last RPAREN
Skip one pass through token table, since we know the result.

function                                             old     new   delta
evaluate_string                                     1095    1097      +2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-15 09:19:48 +02:00
Denys Vlasenko 2ff01bb699 shell: sync ash/hush test scripts
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-14 15:19:02 +02:00
Denys Vlasenko 66139330fc shell/math: trivial code shrink
function                                             old     new   delta
arith_apply                                         1143    1132     -11

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-14 13:59:11 +02:00
Denys Vlasenko 3df885abe3 shell/math: fix the order of variable resolution in binops
function                                             old     new   delta
arith_apply                                         1134    1143      +9

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-14 11:33:59 +02:00
Denys Vlasenko 5febdb1223 shell/math: remove now-unused second_val
function                                             old     new   delta
arith_apply                                         1137    1134      -3
evaluate_string                                     1101    1095      -6
arith_lookup_val                                     150     143      -7
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-16)             Total: -16 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-14 11:10:45 +02:00
Denys Vlasenko 46dccd2ec0 shell/math: fix nested ?: and do not parse variables in not-taken branch
Fixes arith-ternary1.tests and arith-ternary_nested.tests

function                                             old     new   delta
evaluate_string                                     1043    1101     +58
arith_apply                                         1087    1137     +50
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 108/0)             Total: 108 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-14 11:07:30 +02:00
Denys Vlasenko a02450ff0b shell/math: remove a redundant check
function                                             old     new   delta
arith_apply                                         1134    1087     -47

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-14 01:05:40 +02:00
Denys Vlasenko 8acbf31708 shell/math: document ternary ?: op's weirdness, add code comments
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-14 00:41:18 +02:00
Denys Vlasenko 373f64eef3 syslogd: daemonize _after_ init (so that init errors are visible, if they occur)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-13 16:25:13 +02:00
Denys Vlasenko 02378ce20c syslogd: decrease stack usage, ~50 bytes
function                                             old     new   delta
syslogd_init                                           -    1007   +1007
syslogd_main                                        1619     636    -983
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/1 up/down: 1007/-983)          Total: 24 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-13 16:24:56 +02:00
Denys Vlasenko c1d7507a4d shell/math: fix one name check, other minor cleanups
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-13 16:15:18 +02:00
Denys Vlasenko 8ccb3f7b13 shell: add a few yet-failing arithmentic tests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-13 15:21:22 +02:00
Denys Vlasenko a4f30f3c70 shell/math: reduce stack usage
function                                             old     new   delta
arith_apply                                         1123    1134     +11
arith_lookup_val                                     140     145      +5
evaluate_string                                     1053    1047      -6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 16/-6)              Total: 10 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-13 13:55:13 +02:00
Denys Vlasenko d417193cf3 shell: avoid segfault on ${0::0/0~09J}. Closes 15216
function                                             old     new   delta
evaluate_string                                     1011    1053     +42

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-12 17:48:47 +02:00
Denys Vlasenko bab8828b0d hush: fix expansion of space in "a=${a:+$a }c" construct
function                                             old     new   delta
encode_then_append_var_plusminus                     554     552      -2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-12 16:39:32 +02:00
Denys Vlasenko 8f0e4c42c6 udhcpd: optional BOOTP support
from Adam Goldman <adamg@pobox.com>

This patch makes udhcpd respond correctly to queries from BOOTP clients.

It contains the following changes:

The end field, or DHCP_END option, is required in DHCP requests but
optional in BOOTP requests. However, we still send an end
field in all replies, because some BOOTP clients expect one in replies
even if they didn't send one in the request.

Requests without a DHCP_MESSAGE_TYPE are recognized as BOOTP requests
and handled appropriately, instead of being discarded. We still require
an RFC 1048 options field, but we allow it to be empty.

Since a BOOTP client will keep using the assigned IP forever, we only
send a BOOTP reply if a static lease exists for that client.

BOOTP replies shouldn't contain DHCP_* options, so we omit them if there
was no DHCP_MESSAGE_TYPE in the request. Options other than DHCP_*
options are still sent.

The options field of a BOOTP reply must be exactly 64 bytes. If we
construct a reply with more than 64 bytes of options, we give up and log
an error instead of sending it. udhcp_send_raw_packet already pads the
options field to 64 bytes if it is too short.

This implementation has been tested against an HP PA-RISC client.

function                                             old     new   delta
.rodata                                           105247  105321     +74
udhcpd_main                                         1520    1591     +71
send_offer                                           419     470     +51
init_packet                                           81      97     +16
udhcp_init_header                                     75      88     +13
udhcp_scan_options                                   192     203     +11
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 6/0 up/down: 236/0)             Total: 236 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-12 13:22:47 +02:00
Denys Vlasenko 4bd70463c7 libbb: pass "" rather than NULL as format string in _nomsg functions
function                                             old     new   delta
bb_perror_nomsg_and_die                                9      10      +1
bb_perror_nomsg                                        9      10      +1
bb_verror_msg                                        480     469     -11
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 2/-11)              Total: -9 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-12 10:19:29 +02:00
Denys Vlasenko 2ca39ffd44 awk: fix subst code to handle "start of word" pattern correctly (needs REG_STARTEND)
function                                             old     new   delta
awk_sub                                              637     714     +77

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-08 10:42:39 +02:00
Denys Vlasenko 113685fbcd awk: fix SEGV on read error in -f PROGFILE
function                                             old     new   delta
awk_main                                             829     843     +14

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-07 10:54:34 +02:00
Denys Vlasenko f4789164e0 awk: code shrink
function                                             old     new   delta
awk_sub                                              544     548      +4
exec_builtin                                        1136    1130      -6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 4/-6)               Total: -2 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-06 12:48:11 +02:00
Denys Vlasenko 5f84c56336 awk: fix backslash handling in sub() builtins
function                                             old     new   delta
awk_sub                                              559     544     -15

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-03 00:42:10 +02:00
Denys Vlasenko 0256e00a9d awk: fix precedence of = relative to ==
Discovered while adding code to disallow assignments to non-lvalues

function                                             old     new   delta
parse_expr                                           936     991     +55
.rodata                                           105243  105247      +4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 59/0)               Total: 59 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-30 16:44:04 +02:00
Denys Vlasenko fe0b798548 tunctl: code shrink
function                                             old     new   delta
.rodata                                           105246  105243      -3
tunctl_main                                          349     344      -5
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-8)               Total: -8 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-29 14:47:10 +02:00
Denys Vlasenko 721bf6eaf4 awk: printf(INVALID_FMT) prints it verbatim
function                                             old     new   delta
awk_printf                                           628     640     +12

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-29 10:55:40 +02:00
Denys Vlasenko 4d7339204f awk: shrink - use setvar_sn() to set variables from non-NUL terminated strings
function                                             old     new   delta
setvar_sn                                              -      39     +39
exec_builtin                                        1145    1136      -9
awk_getline                                          591     559     -32
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/2 up/down: 39/-41)             Total: -2 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-28 18:08:06 +02:00
Denys Vlasenko 05e60007d4 awk: code shrink
function                                             old     new   delta
awk_getline                                          620     591     -29

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-28 17:51:59 +02:00
Denys Vlasenko b76b420b5d awk: fix closing of non-opened file
function                                             old     new   delta
setvar_ERRNO                                           -      53     +53
.rodata                                           105252  105246      -6
awk_getline                                          639     620     -19
evaluate                                            3402    3377     -25
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/3 up/down: 53/-50)              Total: 3 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-28 17:25:56 +02:00
Denys Vlasenko 9790eb73c8 libbb/dump: code shrink
function                                             old     new   delta
.rodata                                           105252  105246      -6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-28 13:32:07 +02:00
Denys Vlasenko 21dce1c3c3 awk: do not read ARGIND, only set it (gawk compat)
function                                             old     new   delta
next_input_file                                      216     243     +27
evaluate                                            3396    3402      +6
awk_main                                             826     829      +3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 36/0)               Total: 36 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-27 19:11:28 +02:00
Denys Vlasenko 5c8a9dfd97 awk: remove a local variable "caching" a struct member
Since we take its address, the variable lives on stack (not a GPR).
Thus, nothing is improved by caching it.

function                                             old     new   delta
awk_getline                                          642     639      -3

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-27 18:21:38 +02:00
Denys Vlasenko 528808bcd2 awk: get rid of one indirection level for iF (input file structure)
function                                             old     new   delta
try_to_assign                                          -      91     +91
next_input_file                                      214     216      +2
awk_main                                             827     826      -1
evaluate                                            3403    3396      -7
is_assignment                                         91       -     -91
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 1/2 up/down: 93/-99)             Total: -6 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-27 18:05:42 +02:00
Denys Vlasenko 84ff1825dd awk: fix splitting with default FS
function                                             old     new   delta
awk_split                                            543     544      +1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-27 16:17:38 +02:00
Denys Vlasenko 9225f9684f libbb/dump: make xxd_displayoff member conditional on xxd
With xxd not selected:

function                                             old     new   delta
display                                             1459    1444     -15

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-27 14:52:17 +02:00
Denys Vlasenko 6d9427420b od: -l,I,L indeed depend on sizeof(long), fix this
function                                             old     new   delta
.rodata                                           105255  105252      -3
od_main                                             1917    1901     -16
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-19)             Total: -19 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-26 20:17:04 +02:00
Denys Vlasenko 5dcc443dba awk: fix use-after-realloc (CVE-2021-42380), closes 15601
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-26 19:36:58 +02:00
Denys Vlasenko d7814f5727 hexdump: code shrink
function                                             old     new   delta
add_format                                             -      50     +50
add_first                                             10       -     -10
hexdump_main                                         401     366     -35
.rodata                                           105306  105255     -51
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 0/2 up/down: 50/-96)            Total: -46 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-26 16:43:40 +02:00
Denys Vlasenko 283cba78f2 hexdump, xxd: shrink strings
function                                             old     new   delta
add_first                                             12      10      -2
.rodata                                           105321  105306     -15
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-17)             Total: -17 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-26 14:46:29 +02:00
Denys Vlasenko 34751d8bf9 libbb/dump: correct handling of 1-byte signed int format
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-26 14:10:38 +02:00
Denys Vlasenko 8fab211141 libbb/dump: use fputs_stdout where appropriate
function                                             old     new   delta
display                                             1485    1483      -2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-26 13:39:33 +02:00
Denys Vlasenko de851bc9b2 od, hexdump: byte 0x11 is "dc1" not "dcl"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-26 13:33:08 +02:00
Denys Vlasenko 25a10ffe1f od: actually remove -IL from --help, as comment says
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-26 13:01:41 +02:00
Denys Vlasenko 60d4d55b87 od: support -DOHXIL
function                                             old     new   delta
od_main                                             1866    1917     +51
.rodata                                           105306  105321     +15
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 66/0)               Total: 66 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-26 12:56:17 +02:00