aboutsummaryrefslogtreecommitdiff
path: root/shell (follow)
Commit message (Collapse)AuthorAgeFilesLines
* platform.h: UNINITIALIZED_VAR() macro for suppressing gcc warningsDenys Vlasenko8 days1-7/+7
| | | | | | | | | | | | With gcc-15.0.1: function old new delta tftpd_main 603 617 +14 expand_one_var 1923 1929 +6 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 20/0) Total: 20 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: heed warnings about strchr() returning const char*Denys Vlasenko9 days1-3/+3
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell: correctly count backslashes in read built-inRon Yorston2026-08-095-1/+9
| | | | | | | | | | | | | | When the read built-in's '-n' option is used to limit the number of characters read, backslashes should only be counted if the '-r' option is also suppiled. This matches how bash behaves. function old new delta shell_builtin_read 1360 1358 -2 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-2) Total: -2 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell: read: if poll() fails, attempt to process any data collected so farDenys Vlasenko2026-08-091-2/+1
| | | | | | | | | | This was already done on read() failure, why not on poll()? Making it consistent. function old new delta shell_builtin_read 1318 1308 -10 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: fix out-of-bounds read in ifsbreakup()Sanghyun Park2026-07-061-9/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ifsfree() does not only release allocated ifsregion nodes; it also clears the global IFS region state used by ifsbreakup(). If argstr() raises an error while expanding an argument, ash longjmps out of expandarg() before that cleanup runs, leaving stale IFS split offsets behind. A later expansion can reuse the stack for a shorter string. ifsbreakup() then sees the stale IFS state, trusts the old offsets, and can walk past the current stack block before dereferencing p. Follow dash's root-cause fix: when an expansion-related handler catches EXERROR and continues, restore the handler and call ifsfree(). Apply the cleanup to redirectsafe(), expandstr(), and evaltree(). Upstream commit: Date: Mon Dec 5 23:02:01 2022 +0800 expand: Add ifsfree to expand to fix a logic error that causes a buffer over-read On Mon, Jun 20, 2022 at 02:27:10PM -0400, Alex Gorinson wrote: > Due to a logic error in the ifsbreakup function in expand.c if a > heredoc and normal command is run one after the other by means of a > semi-colon, when the second command drops into ifsbreakup the command > will be evaluated with the ifslastp/ifsfirst struct that was set when > the here doc was evaluated. This results in a buffer over-read that > can leak the program's heap, stack, and arena addresses which can be > used to beat ASLR. > > Steps to Reproduce: > First bug: > cmd args: ~/exampleDir/example> dash > $ M='AAAAAAAAAAAAAAAAA' <note: 17 A's> > $ q00(){ > $ <<000;echo > $ ${D?$M$M$M$M$M$M} <note: 6 $M's> > $ 000 > $ } > $ q00 <note: After the q00 is typed in, the leak > should be echo'd out; this works with ash, busybox ash, and dash and > with all option args.> > > Patch: > Adding the following to expand.c will fix both bugs in one go. > (Thank you to Harald van Dijk and Michael Greenberg for doing the > heavy lifting for this patch!) > ========================== > --- a/src/expand.c > +++ b/src/expand.c > @@ -859,6 +859,7 @@ > if (discard) > return -1; > > +ifsfree(); > sh_error("Bad substitution"); > } > > @@ -1739,6 +1740,7 @@ > } else > msg = umsg; > } > +ifsfree(); > sh_error("%.*s: %s%s", end - var - 1, var, msg, tail); > } > ========================== Thanks for the report! I think it's better to add the ifsfree() call to the exception handling path as other sh_error calls may trigger this too. function old new delta restore_handler_expandarg - 33 +33 evaltree 725 711 -14 static.redirectsafe 141 124 -17 expandstr 262 242 -20 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/3 up/down: 36/-45) Total: -18 bytes Signed-off-by: Sanghyun Park <sanghyun.park.cnu@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: placate warning: 'print_pfx_escaped_nl' defined but not usedDenys Vlasenko2026-05-141-0/+2
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: fix build for !HUSH_CASE configDenys Vlasenko2026-04-291-4/+4
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: fix here strings causing segfault in function invocationRon Yorston2026-03-091-0/+1
| | | | | | | | | | | | | The size of the NFROMSTR struct wasn't initialised in the nodesize array, so we got: $ ./busybox sh $ f() { cat <<< hello; } $ f Segmentation fault (core dumped) ./busybox sh Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: fix help builtin and tab completion of builtinsRon Yorston via busybox2026-02-281-2/+2
| | | | | | | | | | | | | | | | | Commit 56143ea63 (ash: code shrink: eliminate pstrcmp1()) changed the layout of struct builtincmd so the name member points to the start of the name, not the flag in the first element of the string. This broke the help builtin and tab completion of builtins. Remove the unnecessary '+ 1' in ash_command_name() and helpcmd(). ash_command_name 92 91 -1 helpcmd 106 102 -4 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-5) Total: -5 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* *: placate warnings where strchr/strstr returns constant pointerDenys Vlasenko2026-02-151-7/+7
| | | | | | | | | Newer glibc is now smarter and can propagate const-ness from those! function old new delta readtoken1 3111 3108 -3 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* *: use is_prefixed_with() where appropriateDenys Vlasenko2026-02-071-1/+1
| | | | | | | | | | | function old new delta resume_main 560 556 -4 uuidcache_check_device 107 101 -6 ntp_init 1005 997 -8 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-18) Total: -18 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* *: use xasprintf_inplace() in more placesDenys Vlasenko2026-02-061-4/+1
| | | | | | | | | | | | function old new delta .rodata 107009 107018 +9 parse_stream 3075 3069 -6 buffer_print 612 603 -9 expand_args 159 144 -15 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/3 up/down: 9/-30) Total: -21 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: fix \ooo octal printout in DEBUG codeDenys Vlasenko2026-01-281-16/+12
| | | | | | | function old new delta ash_main 1624 1645 +21 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: code shrink: eliminate pstrcmp1()Denys Vlasenko2026-01-281-66/+63
| | | | | | | | | | | | | | | function old new delta find_command 961 963 +2 evalcommand 1631 1633 +2 hashcmd 299 300 +1 describe_command 320 321 +1 clearcmdentry 93 94 +1 cdcmd 695 696 +1 pstrcmp1 16 - -16 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 6/0 up/down: 8/-16) Total: -8 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: remove non-standard chdir builtinDenys Vlasenko2026-01-281-17/+14
| | | | | | | | | | function old new delta .rodata 106853 106846 -7 builtintab 352 344 -8 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-15) Total: -15 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: get rid of a static in cmdlookup()/delete_cmd_entry()Denys Vlasenko2026-01-281-26/+38
| | | | | | | | | | | | | | | | | | function old new delta cmdlookup_pp - 120 +120 find_command 953 961 +8 unsetcmd 74 76 +2 hashcmd 297 299 +2 lastcmdentry 4 - -4 delete_cmd_entry 47 43 -4 cmdlookup 132 - -132 ------------------------------------------------------------------------------ (add/remove: 1/2 grow/shrink: 3/1 up/down: 132/-140) Total: -8 bytes text data bss dec hex filename 47470 8 149 47627 ba0b shell/ash.o.orig 47466 8 145 47619 ba03 shell/ash.o Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: group command hashing/searching code together, no code changesDenys Vlasenko2026-01-281-346/+351
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: move casematch() directly to its only caller, no code changesDenys Vlasenko2026-01-271-31/+36
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: reorder functions to reduce forward declarations, no code changesDenys Vlasenko2026-01-271-165/+156
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: JOBSTOPPED can only be set if job control is compiled in - ↵Denys Vlasenko2026-01-271-2/+13
| | | | | | | | | | | | | | | | conditionalize code which depends on it With !ASH_JOB_CONTROL: function old new delta cmdloop 363 351 -12 exitcmd 47 31 -16 .rodata 106422 106398 -24 stoppedjobs 58 - -58 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 0/3 up/down: 0/-110) Total: -110 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: reorder functions to reduce forward declarations, no code changesDenys Vlasenko2026-01-271-450/+453
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: move applet handling out of tryexec() - making it similar to dashDenys Vlasenko2026-01-271-62/+61
| | | | | | | | | | function old new delta tryexec - 60 +60 shellexec 476 349 -127 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/1 up/down: 60/-127) Total: -67 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: unset traps before entering NOEXEC programs after [v]forkDenys Vlasenko2026-01-271-7/+89
| | | | | | | | | | | | | | | | If we don't do that, if INT trap was set, ^C will set a flag "run trap later" and _return_, which is not expected by the NOFORK! function old new delta clear_traps - 107 +107 evalcommand 1617 1631 +14 shellexec 471 476 +5 setsignal 333 327 -6 forkchild 620 480 -140 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 2/2 up/down: 126/-146) Total: -20 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: code shrinkDenys Vlasenko2026-01-241-0/+4
| | | | | | | | | | function old new delta fg_bgcmd 294 296 +2 killpg 43 - -43 ------------------------------------------------------------------------------ (add/remove: 0/2 grow/shrink: 1/0 up/down: 2/-43) Total: -41 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash,hush: allow 0x in arith (bash supports it for 0x$v case when v='')Denys Vlasenko2026-01-241-5/+13
| | | | | | | function old new delta parse_with_base 174 196 +22 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: change procargs() to match recent dash changeDenys Vlasenko2025-09-231-7/+3
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: changes to comments and whitespace, no code changesDenys Vlasenko2025-09-031-8/+8
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: implement <<<here_string syntaxDenys Vlasenko2025-09-023-26/+129
| | | | | | | | | | | | | | function old new delta write2pipe - 133 +133 .rodata 105992 106009 +17 readtoken1 3101 3111 +10 cmdtxt 631 641 +10 nodesize 27 28 +1 redirect 961 916 -45 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 4/1 up/down: 171/-45) Total: 126 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: fix several syntax corner cases with function definitionsDenys Vlasenko2025-08-189-2/+37
| | | | | | | | | | function old new delta parse_stream 3063 3075 +12 done_word 777 784 +7 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 19/0) Total: 19 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: shrink "function" codeDenys Vlasenko2025-08-181-11/+11
| | | | | | | | | | | function old new delta done_word 766 777 +11 static.reserved_match 16 12 -4 reserved_list 240 168 -72 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/2 up/down: 11/-76) Total: -65 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: do not SEGV on if { echo foo; } then { echo bar; } fiDenys Vlasenko2025-08-181-5/+4
| | | | | | | | | | | | For some reason, it was only happening in interactive use function old new delta initialize_context 39 54 +15 parse_stream 3077 3063 -14 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 15/-14) Total: 1 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: disentangle keyword detection, no logic changesDenys Vlasenko2025-08-181-25/+27
| | | | | | | function old new delta done_word 790 766 -24 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: make "function" keyword support optionalDenys Vlasenko2025-08-171-11/+22
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: with --login, errors /etc/profile in must not exit shellDenys Vlasenko2025-08-171-3/+8
| | | | | | | | | | | function old new delta die_if_script 28 34 +6 hush_main 1146 1150 +4 run_list 1031 1028 -3 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/1 up/down: 10/-3) Total: 7 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: recognize "function FUNC { cmd; }" syntaxDenys Vlasenko2025-08-171-43/+103
| | | | | | | | | | | | | | function old new delta reserved_list - 240 +240 parse_stream 2923 3077 +154 done_word 771 790 +19 .rodata 105975 105992 +17 static.reserved_match 12 16 +4 static.reserved_list 168 - -168 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 4/0 up/down: 434/-168) Total: 266 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: remove always-true conditionalDenys Vlasenko2025-08-171-1/+0
| | | | | | | function old new delta parse_stream 2940 2923 -17 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: fix infinite loop expanding alias a="nice&&a"Denys Vlasenko2025-08-171-6/+45
| | | | | | | | | | | function old new delta parse_stream 2857 2940 +83 i_peek 55 69 +14 i_free_alias_buffer 33 37 +4 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 101/0) Total: 101 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: comment fixesDenys Vlasenko2025-08-171-2/+1
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: make "alias" print aliases in properly escaped formDenys Vlasenko2025-08-171-31/+21
| | | | | | | | | | | | | | | function old new delta print_pfx_escaped_nl - 83 +83 builtin_alias 216 218 +2 .rodata 105985 105975 -10 parse_stream 2873 2857 -16 builtin_set 301 259 -42 builtin_readonly 107 59 -48 builtin_export 145 93 -52 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/5 up/down: 85/-168) Total: -83 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: fix nested alias expansionDenys Vlasenko2025-08-171-5/+10
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: optional alias supportDenys Vlasenko2025-08-171-44/+388
| | | | | | | | | | | | | | | | | | | | | | | | | | | | function old new delta parse_stream 2540 2873 +333 i_getch 85 410 +325 builtin_alias - 216 +216 builtin_unalias - 185 +185 .rodata 105806 105985 +179 word_matches_alias - 82 +82 find_alias_slot - 77 +77 end_of_alias_name - 69 +69 builtin_type 128 179 +51 i_free_alias_buffer - 33 +33 enable_all_aliases - 29 +29 bltins1 396 420 +24 o_reset_to_empty_unquoted - 21 +21 run_pipe 1554 1566 +12 i_peek 57 55 -2 parse_redirect 351 346 -5 redirect_opt_num 63 53 -10 encode_then_append_var_plusminus 552 532 -20 done_word 796 771 -25 i_getch_interactive 308 - -308 ------------------------------------------------------------------------------ (add/remove: 8/1 grow/shrink: 6/5 up/down: 1636/-370) Total: 1266 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: optimization in set_local_var()Denys Vlasenko2025-08-161-6/+6
| | | | | | | function old new delta set_local_var 416 409 -7 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: implement <<<here_string syntaxDenys Vlasenko2025-08-153-41/+137
| | | | | | | | | | | | | function old new delta setup_heredoc 299 351 +52 parse_stream 2514 2540 +26 parse_redirect 335 351 +16 redir_table 40 48 +8 static.setup_redirects 394 400 +6 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 5/0 up/down: 108/0) Total: 108 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: allow faster parsing for "./:@" charactersDenys Vlasenko2025-08-141-2/+7
| | | | | | | function old new delta parse_stream 2513 2514 +1 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: shrink syntax error handlingDenys Vlasenko2025-08-141-28/+52
| | | | | | | | | | | | | Was trying to add code to reject more invalid "case" syntaxes, but it's not that easy function old new delta done_word 795 796 +1 parse_stream 2529 2513 -16 .rodata 105825 105806 -19 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/2 up/down: 1/-35) Total: -34 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: undo incorrect change which allows a'b'=c to be assignmentDenys Vlasenko2025-08-145-22/+20
| | | | | | While at it, remove now-unused WORD_IS_KEYWORD Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: explain "empty quoted str marker" trickDenys Vlasenko2025-08-141-5/+11
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: improve code readability, no logic changesDenys Vlasenko2025-08-141-22/+25
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: move tickquote1.tests to hush-bugs/ - it's a known bugDenys Vlasenko2025-08-142-0/+0
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: remove the is_blank danceDenys Vlasenko2025-08-145-76/+75
| | | | | | | function old new delta parse_stream 2566 2524 -42 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>