From vda.linux at googlemail.com Sat Apr 1 09:11:20 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Sat, 1 Apr 2023 11:11:20 +0200 Subject: [git commit] ash: code shrink Message-ID: <20230401091341.DD1AC8345F@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=00fc1368437f66c6e67ed45a17326e5f2573ea65 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta describe_command 323 320 -3 dotcmd 324 309 -15 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-18) Total: -18 bytes Signed-off-by: Denys Vlasenko --- shell/ash.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/shell/ash.c b/shell/ash.c index 45e552217..2ec7cfb0e 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -8729,8 +8729,6 @@ describe_command(char *command, const char *path, int describe_command_verbose) const struct alias *ap; #endif - path = path ? path : pathval(); - if (describe_command_verbose) { out1str(command); } @@ -8755,6 +8753,7 @@ describe_command(char *command, const char *path, int describe_command_verbose) } #endif /* Brute force */ + path = path ? path : pathval(); find_command(command, &entry, DO_ABS, path); switch (entry.cmdtype) { @@ -13624,7 +13623,7 @@ static char * find_dot_file(char *basename) { char *fullname; - const char *path = pathval(); + const char *path; struct stat statb; int len; @@ -13632,6 +13631,7 @@ find_dot_file(char *basename) if (strchr(basename, '/')) return basename; + path = pathval(); while ((len = padvance(&path, basename)) >= 0) { fullname = stackblock(); if ((!pathopt || *pathopt == 'f') From vda.linux at googlemail.com Sat Apr 1 20:16:32 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Sat, 1 Apr 2023 22:16:32 +0200 Subject: [git commit] hush: add TODO comment Message-ID: <20230401201645.D73C783694@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=1409432d072e62c3838ef2e86b0d97637201dbd5 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master Signed-off-by: Denys Vlasenko --- shell/hush.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/shell/hush.c b/shell/hush.c index e6be70078..e42de8762 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -11276,6 +11276,9 @@ static int FAST_FUNC builtin_local(char **argv) bb_error_msg("%s: not in a function", argv[0]); return EXIT_FAILURE; /* bash compat */ } +//TODO? ash and bash support "local -" special form, +//which saves/restores $- around function call (including async returns, such as ^C) +//(IOW: it makes "set +/-..." effects local) argv++; /* Since all builtins run in a nested variable level, * need to use level - 1 here. Or else the variable will be removed at once From vda.linux at googlemail.com Sat Apr 1 20:52:08 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Sat, 1 Apr 2023 22:52:08 +0200 Subject: [git commit] hush: speed up "big heredoc" code Message-ID: <20230401205315.3B471836B9@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=fd5fb2d2b59640910addf5c946a39d4cc5c09003 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta hush_main 1810 1815 +5 .rodata 102723 102721 -2 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 5/-2) Total: 3 bytes Signed-off-by: Denys Vlasenko --- shell/hush.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/shell/hush.c b/shell/hush.c index e42de8762..170edf415 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -10260,6 +10260,20 @@ int hush_main(int argc, char **argv) INIT_G(); if (EXIT_SUCCESS != 0) /* if EXIT_SUCCESS == 0, it is already done */ G.last_exitcode = EXIT_SUCCESS; +#if !BB_MMU + /* "Big heredoc" support via "sh -< STRING" invocation. + * Check it first (do not bother to run the usual init code, + * it is not needed for this case). + */ + if (argv[1] + && argv[1][0] == '-' && argv[1][1] == '<' /*&& !argv[1][2]*/ + /*&& argv[2] && !argv[3] - we don't check some conditions */ + ) { + full_write1_str(argv[2]); + _exit(0); + } + G.argv0_for_re_execing = argv[0]; +#endif #if ENABLE_HUSH_TRAP # if ENABLE_HUSH_FUNCTIONS G.return_exitcode = -1; @@ -10270,9 +10284,6 @@ int hush_main(int argc, char **argv) #if ENABLE_HUSH_FAST G.count_SIGCHLD++; /* ensure it is != G.handled_SIGCHLD */ #endif -#if !BB_MMU - G.argv0_for_re_execing = argv[0]; -#endif cached_getpid = getpid(); /* for tcsetpgrp() during init */ G.root_pid = cached_getpid; /* for $PID (NOMMU can override via -$HEXPID:HEXPPID:...) */ @@ -10388,7 +10399,7 @@ int hush_main(int argc, char **argv) int opt = getopt(argc, argv, "+" /* stop at 1st non-option */ "cexinsl" #if !BB_MMU - "<:$:R:V:" + "$:R:V:" # if ENABLE_HUSH_FUNCTIONS "F:" # endif @@ -10438,9 +10449,6 @@ int hush_main(int argc, char **argv) flags |= OPT_login; break; #if !BB_MMU - case '<': /* "big heredoc" support */ - full_write1_str(optarg); - _exit(0); case '$': { unsigned long long empty_trap_mask; From vda.linux at googlemail.com Sat Apr 1 21:17:53 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Sat, 1 Apr 2023 23:17:53 +0200 Subject: [git commit] hush (NOMMU): fix LINENO in execed children Message-ID: <20230401211836.0A04C836D9@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=6748e6494c223b779a204b370e395f82c8e5247f branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta hush_main 1815 1851 +36 re_execute_shell 601 635 +34 .rodata 102721 102726 +5 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 75/0) Total: 75 bytes Signed-off-by: Denys Vlasenko --- shell/hush.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/shell/hush.c b/shell/hush.c index 170edf415..a938cc790 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -7468,6 +7468,9 @@ static void re_execute_shell(char ***to_free, const char *s, if (!cur->flg_export || cur->flg_read_only) cnt += 2; } +# if ENABLE_HUSH_LINENO_VAR + cnt += 2; +# endif # if ENABLE_HUSH_FUNCTIONS for (funcp = G.top_func; funcp; funcp = funcp->next) cnt += 3; @@ -7489,6 +7492,10 @@ static void re_execute_shell(char ***to_free, const char *s, *pp++ = cur->varstr; } } +# if ENABLE_HUSH_LINENO_VAR + *pp++ = (char *) "-L"; + *pp++ = utoa(G.execute_lineno); +# endif # if ENABLE_HUSH_FUNCTIONS for (funcp = G.top_func; funcp; funcp = funcp->next) { *pp++ = (char *) "-F"; @@ -10400,6 +10407,9 @@ int hush_main(int argc, char **argv) "cexinsl" #if !BB_MMU "$:R:V:" +# if ENABLE_HUSH_LINENO_VAR + "L:" +# endif # if ENABLE_HUSH_FUNCTIONS "F:" # endif @@ -10498,6 +10508,11 @@ int hush_main(int argc, char **argv) case 'V': set_local_var(xstrdup(optarg), opt == 'R' ? SETFLAG_MAKE_RO : 0); break; +# if ENABLE_HUSH_LINENO_VAR + case 'L': + G.parse_lineno = xatou(optarg); + break; +# endif # if ENABLE_HUSH_FUNCTIONS case 'F': { struct function *funcp = new_function(optarg); From vda.linux at googlemail.com Mon Apr 3 12:01:36 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Mon, 3 Apr 2023 14:01:36 +0200 Subject: [git commit] ash: fix broken new mail detection Message-ID: <20230403120242.02801837A8@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=2860b2530e7391b52fc6f0d500981e78a4618551 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master Mea culpa, in "Do not allocate stack string in padvance" commit (I left an extraneous "break" statement). function old new delta cmdloop 329 398 +69 Signed-off-by: Denys Vlasenko --- shell/ash.c | 1 - 1 file changed, 1 deletion(-) diff --git a/shell/ash.c b/shell/ash.c index 2ec7cfb0e..55c0acc16 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -11288,7 +11288,6 @@ chkmail(void) if (!len) break; p = stackblock(); - break; if (*p == '\0') continue; for (q = p; *q; q++) From vda.linux at googlemail.com Mon Apr 3 12:41:01 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Mon, 3 Apr 2023 14:41:01 +0200 Subject: [git commit] ash: fix still-broken new mail detection Message-ID: <20230403124128.9C55E837B6@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=7ababc3e3cd44cb51ad1b0183f7fe30df0fb3cbf branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master padvance() exit condition is return value < 0, not == 0. After MAIL changing twice, the logic erroneously concluded that "you have new mail". Signed-off-by: Denys Vlasenko --- shell/ash.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/shell/ash.c b/shell/ash.c index 55c0acc16..f057b8963 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -11265,8 +11265,8 @@ static smallint mail_var_path_changed; /* * Print appropriate message(s) if mail has arrived. * If mail_var_path_changed is set, - * then the value of MAIL has mail_var_path_changed, - * so we just update the values. + * then the value of MAIL has changed, + * so we just update the hash value. */ static void chkmail(void) @@ -11285,7 +11285,7 @@ chkmail(void) int len; len = padvance_magic(&mpath, nullstr, 2); - if (!len) + if (len < 0) break; p = stackblock(); if (*p == '\0') @@ -11306,8 +11306,8 @@ chkmail(void) if (!mail_var_path_changed && mailtime_hash != new_hash) { if (mailtime_hash != 0) out2str("you have mail\n"); - mailtime_hash = new_hash; } + mailtime_hash = new_hash; mail_var_path_changed = 0; popstackmark(&smark); } From vda.linux at googlemail.com Mon Apr 3 13:01:00 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Mon, 3 Apr 2023 15:01:00 +0200 Subject: [git commit] ash: get rid of separate mail_var_path_changed flag variable Message-ID: <20230403130317.59583837BD@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=94780e3e8e926e7e9f384c4b70310b3e7e79abce branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master We can just clear mailtime_hash to zero and have the same effect. function old new delta changemail 8 11 +3 mail_var_path_changed 1 - -1 cmdloop 398 382 -16 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 1/1 up/down: 3/-17) Total: -14 bytes text data bss dec hex filename 1054786 559 5020 1060365 102e0d busybox_old 1054773 559 5020 1060352 102e00 busybox_unstripped Signed-off-by: Denys Vlasenko --- shell/ash.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/shell/ash.c b/shell/ash.c index f057b8963..bd3afc0c8 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -2110,10 +2110,7 @@ change_lc_ctype(const char *value) } #endif #if ENABLE_ASH_MAIL -static void chkmail(void); static void changemail(const char *var_value) FAST_FUNC; -#else -# define chkmail() ((void)0) #endif static void changepath(const char *) FAST_FUNC; #if ENABLE_ASH_RANDOM_SUPPORT @@ -11258,13 +11255,12 @@ setinputstring(char *string) #if ENABLE_ASH_MAIL /* Hash of mtimes of mailboxes */ +/* Cleared to 0 if MAIL or MAILPATH is changed */ static unsigned mailtime_hash; -/* Set if MAIL or MAILPATH is changed. */ -static smallint mail_var_path_changed; /* * Print appropriate message(s) if mail has arrived. - * If mail_var_path_changed is set, + * If mailtime_hash is zero, * then the value of MAIL has changed, * so we just update the hash value. */ @@ -11303,21 +11299,24 @@ chkmail(void) /* Very simplistic "hash": just a sum of all mtimes */ new_hash += (unsigned)statb.st_mtime; } - if (!mail_var_path_changed && mailtime_hash != new_hash) { + if (mailtime_hash != new_hash) { if (mailtime_hash != 0) out2str("you have mail\n"); + mailtime_hash = new_hash; } - mailtime_hash = new_hash; - mail_var_path_changed = 0; popstackmark(&smark); } static void FAST_FUNC changemail(const char *val UNUSED_PARAM) { - mail_var_path_changed = 1; + mailtime_hash = 0; } +#else + +# define chkmail() ((void)0) + #endif /* ASH_MAIL */ From vda.linux at googlemail.com Mon Apr 3 13:19:13 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Mon, 3 Apr 2023 15:19:13 +0200 Subject: [git commit] ash: code shrink - reuse is_prefixed_with() from libbb Message-ID: <20230403132048.57AA2837D1@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=a33d19eba8c614d113378ed07bbec0ce06227028 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta changepath 67 68 +1 legal_pathopt 70 66 -4 prefix 34 13 -21 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/2 up/down: 1/-25) Total: -24 bytes Signed-off-by: Denys Vlasenko --- shell/ash.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/shell/ash.c b/shell/ash.c index bd3afc0c8..cb674e69c 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -1852,16 +1852,18 @@ _STPUTC(int c, char *p) /* * prefix -- see if pfx is a prefix of string. */ -static char * +static ALWAYS_INLINE char * prefix(const char *string, const char *pfx) { + return is_prefixed_with(string, pfx); +#if 0 /* dash implementation: */ while (*pfx) { if (*pfx++ != *string++) return NULL; } return (char *) string; +#endif } - /* * Check for a valid number. This should be elsewhere. */ From vda.linux at googlemail.com Mon Apr 3 15:30:03 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Mon, 3 Apr 2023 17:30:03 +0200 Subject: [git commit] ash: code shrink: do not take address of prefix(), allowing it to inline Message-ID: <20230403153343.40719837D7@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=46e92e1e568021ecdfa30bfea0efabe72b85633b branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta getjob 281 285 +4 prefix 13 - -13 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 1/0 up/down: 4/-13) Total: -9 bytes Signed-off-by: Denys Vlasenko --- shell/ash.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/shell/ash.c b/shell/ash.c index cb674e69c..d4ee4c93e 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -3962,7 +3962,6 @@ getjob(const char *name, int getctl) unsigned num; int c; const char *p; - char *(*match)(const char *, const char *); jp = curjob; p = name; @@ -4003,15 +4002,12 @@ getjob(const char *name, int getctl) } } - match = prefix; - if (*p == '?') { - match = strstr; - p++; - } - found = NULL; while (jp) { - if (match(jp->ps[0].ps_cmd, p)) { + if (*p == '?' + ? strstr(jp->ps[0].ps_cmd, p + 1) + : prefix(jp->ps[0].ps_cmd, p) + ) { if (found) goto err; found = jp; From vda.linux at googlemail.com Mon Apr 3 17:29:57 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Mon, 3 Apr 2023 19:29:57 +0200 Subject: [git commit] hush: printf builtin with no arguments should not exit Message-ID: <20230403173229.F1FBE837E0@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=ff8fde111e11e973b269467dd86f235a27f653df branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master Signed-off-by: Denys Vlasenko --- coreutils/printf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coreutils/printf.c b/coreutils/printf.c index 2e672d15f..b89df67f9 100644 --- a/coreutils/printf.c +++ b/coreutils/printf.c @@ -428,7 +428,7 @@ int printf_main(int argc UNUSED_PARAM, char **argv) if (argv[1] && argv[1][0] == '-' && argv[1][1] == '-' && !argv[1][2]) argv++; if (!argv[1]) { - if (ENABLE_ASH_PRINTF + if ((ENABLE_ASH_PRINTF || ENABLE_HUSH_PRINTF) && applet_name[0] != 'p' ) { bb_simple_error_msg("usage: printf FORMAT [ARGUMENT...]"); From vda.linux at googlemail.com Mon Apr 3 17:54:42 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Mon, 3 Apr 2023 19:54:42 +0200 Subject: [git commit] ash: sleep builtin with no arguments should not exit Message-ID: <20230403175531.7A18E8380B@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=05f2bedaebd694605abd1f199fc25d93ad73840b branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta sleep_main 116 143 +27 .rodata 105245 105268 +23 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 50/0) Total: 50 bytes Signed-off-by: Denys Vlasenko --- coreutils/sleep.c | 15 ++++++++++++++- procps/kill.c | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/coreutils/sleep.c b/coreutils/sleep.c index 442841210..667db558d 100644 --- a/coreutils/sleep.c +++ b/coreutils/sleep.c @@ -65,15 +65,28 @@ int sleep_main(int argc UNUSED_PARAM, char **argv) { duration_t duration; + /* Note: sleep_main may be directly called from ash as a builtin. + * This brings some complications: + * + we can't use xfunc here + * + we can't use bb_show_usage + * + applet_name can be the name of the shell + */ ++argv; - if (!*argv) + if (!*argv) { + /* Without this, bare "sleep" in ash shows _ash_ --help */ + if (ENABLE_ASH_SLEEP && applet_name[0] != 's') { + bb_simple_error_msg("sleep: missing operand"); + return EXIT_FAILURE; + } bb_show_usage(); + } /* GNU sleep accepts "inf", "INF", "infinity" and "INFINITY" */ if (strncasecmp(argv[0], "inf", 3) == 0) for (;;) sleep(INT_MAX); +//FIXME: in ash, "sleep 123qwerty" as a builtin aborts the shell #if ENABLE_FEATURE_FANCY_SLEEP duration = 0; do { diff --git a/procps/kill.c b/procps/kill.c index 8f10e21ab..208efebde 100644 --- a/procps/kill.c +++ b/procps/kill.c @@ -85,8 +85,8 @@ * This brings some complications: * * + we can't use xfunc here - * + we can't use applet_name * + we can't use bb_show_usage + * + applet_name can be the name of the shell * (doesn't apply for killall[5], still should be careful b/c NOFORK) * * kill %n gets translated into kill ' -' by shell (note space!) From vda.linux at googlemail.com Thu Apr 6 19:20:28 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Thu, 6 Apr 2023 21:20:28 +0200 Subject: [git commit] libbb: consolidate NOMMU fix of restoring high bit in argv[0][0] Message-ID: <20230406192217.E77B5839FA@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=a26711a2d1464167be4ebc990fe21a3809a2da34 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta fork_or_rexec 46 56 +10 bootchartd_main 1087 1079 -8 cpio_main 674 661 -13 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/2 up/down: 10/-21) Total: -11 bytes Signed-off-by: Denys Vlasenko --- archival/cpio.c | 1 - include/libbb.h | 2 +- init/bootchartd.c | 2 -- libbb/vfork_daemon_rexec.c | 10 ++++++---- networking/httpd.c | 2 +- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/archival/cpio.c b/archival/cpio.c index 7149782d7..839a15621 100644 --- a/archival/cpio.c +++ b/archival/cpio.c @@ -504,7 +504,6 @@ int cpio_main(int argc UNUSED_PARAM, char **argv) goto dump; } /* parent */ - USE_FOR_NOMMU(argv[-optind][0] &= 0x7f); /* undo fork_or_rexec() damage */ xchdir(*argv++); close(pp.wr); xmove_fd(pp.rd, STDIN_FILENO); diff --git a/include/libbb.h b/include/libbb.h index cca33a177..6191debb1 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -1319,7 +1319,7 @@ enum { # define bb_daemonize(flags) bb_daemonize_or_rexec(flags, bogus) #else extern bool re_execed; - /* Note: re_exec() and fork_or_rexec() do argv[0][0] |= 0x80 on NOMMU! + /* Note: re_exec() sets argv[0][0] |= 0x80 on NOMMU! * _Parent_ needs to undo it if it doesn't want to have argv[0] mangled. */ void re_exec(char **argv) NORETURN FAST_FUNC; diff --git a/init/bootchartd.c b/init/bootchartd.c index ae1ee9d9a..0929890a3 100644 --- a/init/bootchartd.c +++ b/init/bootchartd.c @@ -435,8 +435,6 @@ int bootchartd_main(int argc UNUSED_PARAM, char **argv) /* parent */ - USE_FOR_NOMMU(argv[0][0] &= 0x7f); /* undo fork_or_rexec() damage */ - if (DO_SIGNAL_SYNC) { /* Wait for logger child to set handlers, then unpause it. * Otherwise with short-lived PROG (e.g. "bootchartd start true") diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c index 79141936a..a570ddbf2 100644 --- a/libbb/vfork_daemon_rexec.c +++ b/libbb/vfork_daemon_rexec.c @@ -268,10 +268,12 @@ pid_t FAST_FUNC fork_or_rexec(char **argv) /* fflush_all(); ? - so far all callers had no buffered output to flush */ pid = xvfork(); - if (pid) /* parent */ - return pid; - /* child - re-exec ourself */ - re_exec(argv); + if (pid == 0) /* child - re-exec ourself */ + re_exec(argv); /* NORETURN */ + + /* parent */ + argv[0][0] &= 0x7f; /* undo re_rexec() damage */ + return pid; } #endif diff --git a/networking/httpd.c b/networking/httpd.c index 252ad6c2d..ddcb03bca 100644 --- a/networking/httpd.c +++ b/networking/httpd.c @@ -2713,8 +2713,8 @@ static void mini_httpd_nommu(int server_socket, int argc, char **argv) /* Run a copy of ourself in inetd mode */ re_exec(argv_copy); } - argv_copy[0][0] &= 0x7f; /* parent, or vfork failed */ + argv_copy[0][0] &= 0x7f; /* undo re_rexec() damage */ close(n); } /* while (1) */ /* never reached */ From bugzilla at busybox.net Fri Apr 7 18:53:02 2023 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Fri, 07 Apr 2023 18:53:02 +0000 Subject: [Bug 15521] New: findfs cannot find fat32 filesystems by UUID in certain configurations Message-ID: https://bugs.busybox.net/show_bug.cgi?id=15521 Bug ID: 15521 Summary: findfs cannot find fat32 filesystems by UUID in certain configurations Product: Busybox Version: 1.35.x Hardware: All OS: Linux Status: NEW Severity: major Priority: P5 Component: Standard Compliance Assignee: unassigned at busybox.net Reporter: andrea.biardi at viavisolutions.com CC: busybox-cvs at busybox.net Target Milestone: --- Created attachment 9576 --> https://bugs.busybox.net/attachment.cgi?id=9576&action=edit patch (vanilla busybox 1.35 sources) findfs relies on the assumption that if cluster_count is within the limits of a FAT16 filesystem, the filesystem *must* be FAT16 (util-linux/volume_id/fat.c, volume_id_probe_vfat). This fails for me in two situations: - On "standard" disks, with a fat32 filesystem in a relatively small partition (say, 10M). - On disks with 4KB logical sectors, even for larger filesystems (in my case, a 512M EFI ESP partition formatted with busybox mkdosfs); this is because on this kind of device you don't need as many clusters (the sector being 8 times larger than usual). This is a simple script that reproduces this behavior (all busybox binaries): #! /bin/sh for size in 10M 100M 5G; do echo echo "testing with size=$size" sfdisk --quiet --wipe=always --wipe-partitions=always /dev/sda << EOF label: dos 1: type=0b, size=$size EOF mkdosfs /dev/sda1 # unlike util-linux, this always makes a fat32 filesystem uuid=$(lsblk -nr -o UUID /dev/sda1) echo "uuid is $uuid" dev=$(findfs UUID=$uuid) echo "dev is $dev" # fals in the 10M case done I'm not an expert in the various versions of BPB/EBPB of FAT, but I'm assuming that if there is a clear FAT32 signature it should be honored regardless of the value of cluster_count. Attached is a trivial patch for consideration. -- You are receiving this mail because: You are on the CC list for the bug. From bugzilla at busybox.net Fri Apr 7 19:19:26 2023 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Fri, 07 Apr 2023 19:19:26 +0000 Subject: [Bug 15526] New: mkdosfs produces identical serial numbers if called in quick succession Message-ID: https://bugs.busybox.net/show_bug.cgi?id=15526 Bug ID: 15526 Summary: mkdosfs produces identical serial numbers if called in quick succession Product: Busybox Version: 1.35.x Hardware: All OS: Linux Status: NEW Severity: normal Priority: P5 Component: Other Assignee: unassigned at busybox.net Reporter: andrea.biardi at viavisolutions.com CC: busybox-cvs at busybox.net Target Milestone: --- Created attachment 9581 --> https://bugs.busybox.net/attachment.cgi?id=9581&action=edit patch (vanilla busybox 1.35 source) I'm using busybox to automate the creation of a virtual machine; part of this requires me to script something like this: #! /bin/sh sfdisk --quiet --wipe=always --wipe-partitions=always /dev/sda << EOF label: dos 1: type=0b, size=500M 2: type=0b, size=500M 3: type=0b, size=500M 4: type=0b, size=500M EOF mkdosfs /dev/sda1 mkdosfs /dev/sda2 mkdosfs /dev/sda3 mkdosfs /dev/sda4 lsblk -npr -o NAME,TYPE,UUID /dev/sda On a "modern" machine, the problem is that without a small (>= 1s) delay between the invocations of mkdosfs, all filesystems end up with the same serial number, which is undesirable (especially if those UUIDs end up in an /etc/fstab). Attached is a patch for consideration that attempts to use /dev/random first, falling back to the time-based mechanism in case /dev/random isn't accessible. -- You are receiving this mail because: You are on the CC list for the bug. From vda.linux at googlemail.com Mon Apr 10 12:33:20 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Mon, 10 Apr 2023 14:33:20 +0200 Subject: [git commit] seq: accept negative parameters Message-ID: <20230410123522.C942083C1B@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=9bc2b6e88474a8ebb50c94f29320d343bd374928 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta seq_main 429 476 +47 packed_usage 34557 34538 -19 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 47/-19) Total: 28 bytes Signed-off-by: Denys Vlasenko --- coreutils/seq.c | 23 +++++++++++++++++++++-- testsuite/seq.tests | 3 +++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/coreutils/seq.c b/coreutils/seq.c index beb339d1e..c0e2d1e06 100644 --- a/coreutils/seq.c +++ b/coreutils/seq.c @@ -22,7 +22,7 @@ //usage:#define seq_full_usage "\n\n" //usage: "Print numbers from FIRST to LAST, in steps of INC.\n" //usage: "FIRST, INC default to 1.\n" -//usage: "\n -w Pad to last with leading zeros" +//usage: "\n -w Pad with leading zeros" //usage: "\n -s SEP String separator" #include "libbb.h" @@ -41,6 +41,7 @@ int seq_main(int argc, char **argv) unsigned width; unsigned frac_part; const char *sep, *opt_s = "\n"; + char *saved; unsigned opt; #if ENABLE_LOCALE_SUPPORT @@ -49,7 +50,25 @@ int seq_main(int argc, char **argv) setlocale(LC_NUMERIC, "C"); #endif - opt = getopt32(argv, "+ws:", &opt_s); + /* Cater for negative arguments: if we see one, truncate argv[] on it */ + n = 0; + for (;;) { + char c; + saved = argv[++n]; + if (!saved) + break; + if (saved[0] != '-') + break; + c = saved[1]; + if (c == '.' || (c >= '0' && c <= '9')) { + argv[n] = NULL; + break; + } + } + opt = getopt32(argv, "+ws:", &opt_s); /* "+": stop at first non-option */ + /* Restore possibly truncated argv[] */ + argv[n] = saved; + argc -= optind; argv += optind; first = increment = 1; diff --git a/testsuite/seq.tests b/testsuite/seq.tests index 1e1116c7d..d414169c9 100755 --- a/testsuite/seq.tests +++ b/testsuite/seq.tests @@ -43,4 +43,7 @@ testing "seq count down by 3 with padding" "seq -w 8 -3 04" "08\n05\n" "" "" testing "seq count by .3 with padding 1" "seq -w 09 .3 11" "09.0\n09.3\n09.6\n09.9\n10.2\n10.5\n10.8\n" "" "" testing "seq count by .3 with padding 2" "seq -w 03 .3 0004" "0003.0\n0003.3\n0003.6\n0003.9\n" "" "" +testing "seq from -4 count down by 2" "seq -4 -2 -8" "-4\n-6\n-8\n" "" "" +testing "seq from -.0 count down by .25" "seq -.0 -.25 -.9" "-0.00\n-0.25\n-0.50\n-0.75\n" "" "" + exit $FAILCOUNT From vda.linux at googlemail.com Mon Apr 10 12:47:38 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Mon, 10 Apr 2023 14:47:38 +0200 Subject: [git commit] mkfs_vfat: do not generate same volume_id when run in rapid succession Message-ID: <20230410124914.E54CC83C3A@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=611729eff386234b09d40780cdcc21fe72f6f8b8 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta mkfs_vfat_main 1502 1523 +21 Signed-off-by: Denys Vlasenko --- util-linux/mkfs_vfat.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/util-linux/mkfs_vfat.c b/util-linux/mkfs_vfat.c index 821371953..d2db78e1d 100644 --- a/util-linux/mkfs_vfat.c +++ b/util-linux/mkfs_vfat.c @@ -267,8 +267,9 @@ int mkfs_vfat_main(int argc UNUSED_PARAM, char **argv) // cache device name device_name = argv[0]; - // default volume ID = creation time - volume_id = time(NULL); + // default volume ID: somewhat random (not crypto-strong) + // (mix in pid to avoid same IDs when run in rapid succession) + volume_id = time(NULL) ^ getpid(); // truncate to exactly 11 chars, pad with spaces sprintf(volume_label11, "%-11.11s", arg_volume_label); From vda.linux at googlemail.com Mon Apr 10 14:30:27 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Mon, 10 Apr 2023 16:30:27 +0200 Subject: [git commit] ash: fix sleep built-in not running INT trap immediately on ^C Message-ID: <20230410143102.D31A783C5D@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=7362d2979434c565ae70b0ccf9d4b09d7597fb48 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta sleep_for_duration 169 149 -20 Signed-off-by: Denys Vlasenko --- libbb/duration.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/libbb/duration.c b/libbb/duration.c index 793d02f42..0024f1a66 100644 --- a/libbb/duration.c +++ b/libbb/duration.c @@ -76,16 +76,14 @@ void FAST_FUNC sleep_for_duration(duration_t duration) ts.tv_sec = duration; ts.tv_nsec = (duration - ts.tv_sec) * 1000000000; } - /* NB: if ENABLE_ASH_SLEEP, we end up here if "sleep N" - * is run in ash. ^C will still work, because ash's signal handler - * does not return (it longjumps), the below loop - * will not continue looping. - * (This wouldn't work in hush) + /* NB: ENABLE_ASH_SLEEP requires that we do NOT loop on EINTR here: + * otherwise, traps won't execute until we finish looping. */ - do { - errno = 0; - nanosleep(&ts, &ts); - } while (errno == EINTR); + //do { + // errno = 0; + // nanosleep(&ts, &ts); + //} while (errno == EINTR); + nanosleep(&ts, &ts); } #else duration_t FAST_FUNC parse_duration_str(char *str) From vda.linux at googlemail.com Mon Apr 10 15:26:04 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Mon, 10 Apr 2023 17:26:04 +0200 Subject: [git commit] seedrng: fix for glibc <= 2.24 not providing getrandom() Message-ID: <20230410152633.AD85583C74@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=200a9669fbf6f06894e4243cccc9fc11a1a6073a branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master Signed-off-by: Denys Vlasenko --- miscutils/seedrng.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/miscutils/seedrng.c b/miscutils/seedrng.c index 967741dc7..7cc855141 100644 --- a/miscutils/seedrng.c +++ b/miscutils/seedrng.c @@ -45,6 +45,20 @@ #include #include +/* Fix up glibc <= 2.24 not having getrandom() */ +#if defined(__GLIBC__) && __GLIBC__ == 2 && __GLIBC_MINOR__ <= 24 +#include +# define getrandom(...) bb_getrandom(__VA_ARGS__) +static ssize_t getrandom(void *buffer, size_t length, unsigned flags) +{ +# if defined(__NR_getrandom) + return syscall(__NR_getrandom, buffer, length, flags); +# else + return ENOSYS; +# endif +} +#endif + #ifndef GRND_INSECURE #define GRND_INSECURE 0x0004 /* Apparently some headers don't ship with this yet. */ #endif From vda.linux at googlemail.com Mon Apr 10 14:56:55 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Mon, 10 Apr 2023 16:56:55 +0200 Subject: [git commit] appletlib: fix "warning: unused variable applet_no" Message-ID: <20230410152633.A48D783C73@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=85e4805ae94ce653d8088d6575dc01114cd00bcf branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master Signed-off-by: Tomas Paukrt Signed-off-by: Denys Vlasenko --- libbb/appletlib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libbb/appletlib.c b/libbb/appletlib.c index d5335d353..d9cc48423 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c @@ -918,7 +918,7 @@ int busybox_main(int argc UNUSED_PARAM, char **argv) # endif # if NUM_APPLETS > 0 -void FAST_FUNC show_usage_if_dash_dash_help(int applet_no, char **argv) +void FAST_FUNC show_usage_if_dash_dash_help(int applet_no UNUSED_PARAM, char **argv) { /* Special case. POSIX says "test --help" * should be no different from e.g. "test --foo". From vda.linux at googlemail.com Tue Apr 11 11:56:12 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Tue, 11 Apr 2023 13:56:12 +0200 Subject: [git commit] seedrng: fix for glibc <= 2.24 not providing random header Message-ID: <20230411115857.EAFC983F67@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=cb57abb46f06f4ede8d9ccbdaac67377fdf416cf branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master - dropped the wrong define (not sure why it was there) - not available if glibc <= 2.24 - GRND_NONBLOCK not defined if not included - ret < 0 && errno == ENOSYS has to be true to get creditable set Signed-off-by: Thomas Devoogdt Signed-off-by: Denys Vlasenko --- miscutils/seedrng.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/miscutils/seedrng.c b/miscutils/seedrng.c index 7cc855141..3bf6e2ea7 100644 --- a/miscutils/seedrng.c +++ b/miscutils/seedrng.c @@ -42,25 +42,31 @@ #include "libbb.h" #include -#include #include /* Fix up glibc <= 2.24 not having getrandom() */ #if defined(__GLIBC__) && __GLIBC__ == 2 && __GLIBC_MINOR__ <= 24 #include -# define getrandom(...) bb_getrandom(__VA_ARGS__) static ssize_t getrandom(void *buffer, size_t length, unsigned flags) { # if defined(__NR_getrandom) return syscall(__NR_getrandom, buffer, length, flags); # else - return ENOSYS; + errno = ENOSYS; + return -1; # endif } +#else +#include +#endif + +/* Apparently some headers don't ship with this yet. */ +#ifndef GRND_NONBLOCK +#define GRND_NONBLOCK 0x0001 #endif #ifndef GRND_INSECURE -#define GRND_INSECURE 0x0004 /* Apparently some headers don't ship with this yet. */ +#define GRND_INSECURE 0x0004 #endif #define DEFAULT_SEED_DIR "/var/lib/seedrng" From vda.linux at googlemail.com Tue Apr 11 18:29:59 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Tue, 11 Apr 2023 20:29:59 +0200 Subject: [git commit] seq: fix yet another case of negative parameters not working Message-ID: <20230411183107.F173883FD2@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=478b5ac2bcdb5014d8e6a6e8d7647b4c599cc1a7 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master Signed-off-by: Denys Vlasenko --- coreutils/seq.c | 8 ++++++-- testsuite/seq.tests | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/coreutils/seq.c b/coreutils/seq.c index c0e2d1e06..77a8aba8a 100644 --- a/coreutils/seq.c +++ b/coreutils/seq.c @@ -57,8 +57,12 @@ int seq_main(int argc, char **argv) saved = argv[++n]; if (!saved) break; - if (saved[0] != '-') - break; + if (saved[0] != '-') { + // break; // "seq -s : -1 1" won't be treated correctly + continue; + } +// "seq -s -1 1 9" is not treated correctly, but such usage +// (delimiter string which looks like negative number) is very unlikely c = saved[1]; if (c == '.' || (c >= '0' && c <= '9')) { argv[n] = NULL; diff --git a/testsuite/seq.tests b/testsuite/seq.tests index d414169c9..d0da8c119 100755 --- a/testsuite/seq.tests +++ b/testsuite/seq.tests @@ -45,5 +45,6 @@ testing "seq count by .3 with padding 2" "seq -w 03 .3 0004" "0003.0\n0003.3\n00 testing "seq from -4 count down by 2" "seq -4 -2 -8" "-4\n-6\n-8\n" "" "" testing "seq from -.0 count down by .25" "seq -.0 -.25 -.9" "-0.00\n-0.25\n-0.50\n-0.75\n" "" "" +testing "seq -s : with negative start" "seq -s : -1 1" "-1:0:1\n" "" "" exit $FAILCOUNT From vda.linux at googlemail.com Wed Apr 12 10:23:36 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Wed, 12 Apr 2023 12:23:36 +0200 Subject: [git commit] sleep: fix error exit when called as "sh" builtin Message-ID: <20230412102421.F1AC983FDF@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=550e6d8fbd05ea0ab60ff3e542327efb4e9cc254 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master Signed-off-by: Denys Vlasenko --- coreutils/sleep.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/coreutils/sleep.c b/coreutils/sleep.c index 667db558d..a0cee5a4a 100644 --- a/coreutils/sleep.c +++ b/coreutils/sleep.c @@ -74,7 +74,8 @@ int sleep_main(int argc UNUSED_PARAM, char **argv) ++argv; if (!*argv) { /* Without this, bare "sleep" in ash shows _ash_ --help */ - if (ENABLE_ASH_SLEEP && applet_name[0] != 's') { + /* (ash can be the "sh" applet as well, so check 2nd char) */ + if (ENABLE_ASH_SLEEP && applet_name[1] != 'l') { bb_simple_error_msg("sleep: missing operand"); return EXIT_FAILURE; } From vda.linux at googlemail.com Wed Apr 12 11:49:14 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Wed, 12 Apr 2023 13:49:14 +0200 Subject: [git commit] lineedit: fix crash when icanon set with -echo Message-ID: <20230412114927.CFF9F83FFC@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=853cfe927fd656a2688ac2bfc81c69e1004c44df branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master When icanon is set with -echo (e.g. ssh from an emacs shell) then S.state will remain null but later it will be deferenced causing ash to crash. Fix: additional check on state. Signed-off-by: Akos Somfai Signed-off-by: Denys Vlasenko --- libbb/lineedit.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 625884adf..bdae10914 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -254,7 +254,7 @@ static NOINLINE const char *get_homedir_or_NULL(void) const char *home; # if ENABLE_SHELL_ASH || ENABLE_SHELL_HUSH - home = state->sh_get_var ? state->sh_get_var("HOME") : getenv("HOME"); + home = state && state->sh_get_var ? state->sh_get_var("HOME") : getenv("HOME"); # else home = getenv("HOME"); # endif @@ -2038,7 +2038,7 @@ static void parse_and_put_prompt(const char *prmt_ptr) if (!cwd_buf) { const char *home; # if EDITING_HAS_sh_get_var - cwd_buf = state->sh_get_var + cwd_buf = state && state->sh_get_var ? xstrdup(state->sh_get_var("PWD")) : xrealloc_getcwd_or_warn(NULL); # else From vda.linux at googlemail.com Wed Apr 12 12:47:24 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Wed, 12 Apr 2023 14:47:24 +0200 Subject: [git commit] shuf: add (disabled) code to support very long numbers in -i LO-HI Message-ID: <20230412124838.4199C84015@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=238dab322a630b493843a6bdf3203e93db87469a branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master Signed-off-by: Denys Vlasenko --- coreutils/shuf.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 58 insertions(+), 6 deletions(-) diff --git a/coreutils/shuf.c b/coreutils/shuf.c index 337366b45..fe0358e07 100644 --- a/coreutils/shuf.c +++ b/coreutils/shuf.c @@ -66,6 +66,12 @@ static void shuffle_lines(char **lines, unsigned numlines, unsigned outlines) } } +/* We can handle insanity like this: + * shuf -i 3333333333333333333333333333333333333333333333333333333333333123456789001-3333333333333333333333333333333333333333333333333333333333333123456789019 + * but do we want to have +200 bytes of code (~40% code growth)? + */ +#define COMMON_PREFIX_HACK 0 + int shuf_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int shuf_main(int argc, char **argv) { @@ -76,6 +82,11 @@ int shuf_main(int argc, char **argv) unsigned numlines, outlines; unsigned i; char eol; +#if COMMON_PREFIX_HACK + unsigned pfx_len = 0; + unsigned padding_width = padding_width; + const char *pfx = pfx; +#endif opts = getopt32(argv, "^" OPT_STR @@ -104,10 +115,46 @@ int shuf_main(int argc, char **argv) if (!dash) { bb_error_msg_and_die("bad range '%s'", opt_i_str); } - *dash = '\0'; + *dash++ = '\0'; +#if COMMON_PREFIX_HACK + { + const char *a = opt_i_str; + const char *b = dash; + /* Skip leading zeros (they may mask that common prefix does exist) */ + while (*a == '0') a++; + while (*b == '0') b++; + /* Do we have a common prefix (long enough to bother)? */ + padding_width = strlen(a); + if (padding_width > 5 && padding_width == strlen(b)) { + /* How long is it? */ + pfx = a; + while (isdigit(*a) && *a == *b) { + a++; + b++; + } + if (*a == '\0') { + /* "123456-123456", and we 'ate' all of them */ + /* prevent trying to xatoull("") */ + a--; + b--; + } + pfx_len = a - opt_i_str; /* can end up being 0 */ + padding_width -= pfx_len; + lo = xatoull(a); + hi = xatoull(b); + } else { + /* Undo leading zero 'eating' (think "0-9") */ + a = opt_i_str; + b = dash; + } + lo = xatoull(a); + hi = xatoull(b); + } +#else lo = xatoull(opt_i_str); - hi = xatoull(dash + 1); - *dash = '-'; + hi = xatoull(dash); +#endif + dash[-1] = '-'; if (hi < lo) bb_error_msg_and_die("bad range '%s'", opt_i_str); hi -= lo; @@ -165,9 +212,14 @@ int shuf_main(int argc, char **argv) eol = '\0'; for (i = numlines - outlines; i < numlines; i++) { - if (opts & OPT_i) - printf("%llu%c", lo + (uintptr_t)lines[i], eol); - else + if (opts & OPT_i) { +#if COMMON_PREFIX_HACK + if (pfx_len != 0) + printf("%.*s%0*llu%c", pfx_len, pfx, padding_width, lo + (uintptr_t)lines[i], eol); + else +#endif + printf("%llu%c", lo + (uintptr_t)lines[i], eol); + } else printf("%s%c", lines[i], eol); } From vda.linux at googlemail.com Wed Apr 12 12:51:11 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Wed, 12 Apr 2023 14:51:11 +0200 Subject: [git commit] shuf: remove redundant code Message-ID: <20230412125137.9522484020@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=8696f5d380209e6aba13ffc52eced9239510b275 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master Signed-off-by: Denys Vlasenko --- coreutils/shuf.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/coreutils/shuf.c b/coreutils/shuf.c index fe0358e07..3483a289b 100644 --- a/coreutils/shuf.c +++ b/coreutils/shuf.c @@ -140,8 +140,6 @@ int shuf_main(int argc, char **argv) } pfx_len = a - opt_i_str; /* can end up being 0 */ padding_width -= pfx_len; - lo = xatoull(a); - hi = xatoull(b); } else { /* Undo leading zero 'eating' (think "0-9") */ a = opt_i_str; From vda.linux at googlemail.com Wed Apr 12 12:56:05 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Wed, 12 Apr 2023 14:56:05 +0200 Subject: [git commit] shuf: fix pfx_len calculation Message-ID: <20230412125645.28C0984038@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=f7065aa9ae54ce0d1772fd2e6f0e0b6862a50b71 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master Signed-off-by: Denys Vlasenko --- coreutils/shuf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coreutils/shuf.c b/coreutils/shuf.c index 3483a289b..107899a10 100644 --- a/coreutils/shuf.c +++ b/coreutils/shuf.c @@ -138,7 +138,7 @@ int shuf_main(int argc, char **argv) a--; b--; } - pfx_len = a - opt_i_str; /* can end up being 0 */ + pfx_len = a - pfx; /* can end up being 0 */ padding_width -= pfx_len; } else { /* Undo leading zero 'eating' (think "0-9") */ From rep.dot.nop at gmail.com Wed Apr 12 18:31:44 2023 From: rep.dot.nop at gmail.com (Bernhard Reutner-Fischer) Date: Wed, 12 Apr 2023 20:31:44 +0200 Subject: [git commit] build system: clean more files on make clean Message-ID: <20230412183221.35EFA84044@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=7c1f975cddccff1e9705e750eed8a54131d7a392 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master Signed-off-by: Tomas Paukrt Signed-off-by: Bernhard Reutner-Fischer --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 7b4686fc8..e67553d5f 100644 --- a/Makefile +++ b/Makefile @@ -967,6 +967,7 @@ endif # CONFIG_MODULES # Directories & files removed with 'make clean' CLEAN_DIRS += $(MODVERDIR) _install 0_lib CLEAN_FILES += busybox busybox_unstripped* busybox.links \ + busybox*.suid busybox*.nosuid \ System.map .kernelrelease \ .tmp_kallsyms* .tmp_version .tmp_busybox* .tmp_System.map From vda.linux at googlemail.com Thu Apr 13 01:02:11 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Thu, 13 Apr 2023 03:02:11 +0200 Subject: [git commit] shuf: another tweak to COMMON_PREFIX_HACK code Message-ID: <20230413010217.E562084053@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=8b72877babb20be9bb46c4437f5e1870390c29cc branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master Signed-off-by: Denys Vlasenko --- coreutils/shuf.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/coreutils/shuf.c b/coreutils/shuf.c index 107899a10..466969745 100644 --- a/coreutils/shuf.c +++ b/coreutils/shuf.c @@ -67,7 +67,7 @@ static void shuffle_lines(char **lines, unsigned numlines, unsigned outlines) } /* We can handle insanity like this: - * shuf -i 3333333333333333333333333333333333333333333333333333333333333123456789001-3333333333333333333333333333333333333333333333333333333333333123456789019 + * shuf -i 333333333333333333333333333333001-333333333333333333333333333333019 * but do we want to have +200 bytes of code (~40% code growth)? */ #define COMMON_PREFIX_HACK 0 @@ -128,16 +128,12 @@ int shuf_main(int argc, char **argv) if (padding_width > 5 && padding_width == strlen(b)) { /* How long is it? */ pfx = a; - while (isdigit(*a) && *a == *b) { + while (isdigit(*a) && *a == *b + && a[1] /* "111111-111111" case: avoid xatoull("") */ + ) { a++; b++; } - if (*a == '\0') { - /* "123456-123456", and we 'ate' all of them */ - /* prevent trying to xatoull("") */ - a--; - b--; - } pfx_len = a - pfx; /* can end up being 0 */ padding_width -= pfx_len; } else { From vda.linux at googlemail.com Thu Apr 13 07:20:24 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Thu, 13 Apr 2023 09:20:24 +0200 Subject: [git commit] hush: quote variable values printed by "set" (match ash behavior) Message-ID: <20230413072107.E995F8404B@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=90b607d79a1377d6a5dda44ee112698c58432203 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta builtin_set 258 301 +43 Signed-off-by: Denys Vlasenko --- shell/hush.c | 19 +++++++++++++++++-- shell/hush_test/hush-misc/export-n.right | 4 ++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/shell/hush.c b/shell/hush.c index a938cc790..202c0993a 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -11147,6 +11147,12 @@ static int FAST_FUNC builtin_umask(char **argv) #if ENABLE_HUSH_EXPORT || ENABLE_HUSH_TRAP static void print_escaped(const char *s) { +//TODO? bash "set" does not quote variables which contain only alnums and "%+,-./:=@_~", +// (but "export" quotes all variables, even with only these chars). +// I think quoting strings with %+,=~ looks better +// (example: "set" printing var== instead of var='=' looks strange) +// IOW: do not quote "-./:@_": / is used in pathnames, : in PATH, -._ often in file names, @ in emails + if (*s == '\'') goto squote; do { @@ -11401,8 +11407,17 @@ static int FAST_FUNC builtin_set(char **argv) if (arg == NULL) { struct variable *e; - for (e = G.top_var; e; e = e->next) - puts(e->varstr); + for (e = G.top_var; e; e = e->next) { + const char *s = e->varstr; + const char *p = strchr(s, '='); + + if (!p) /* wtf? take next variable */ + continue; + /* var= */ + printf("%.*s", (int)(p - s) + 1, s); + print_escaped(p + 1); + putchar('\n'); + } return EXIT_SUCCESS; } diff --git a/shell/hush_test/hush-misc/export-n.right b/shell/hush_test/hush-misc/export-n.right index 3d55bf752..6079a0124 100644 --- a/shell/hush_test/hush-misc/export-n.right +++ b/shell/hush_test/hush-misc/export-n.right @@ -2,8 +2,8 @@ export aaa1="'''" export aaa2='' export aaa3="'''"'abc' export aaa8='8' -aaa9=9 -aaa10=10 +aaa9='9' +aaa10='10' Nothing: Nothing: Nothing: From vda.linux at googlemail.com Sun Apr 16 15:15:05 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Sun, 16 Apr 2023 17:15:05 +0200 Subject: [git commit] ash,hush: tab completion of functions and aliases Message-ID: <20230416155210.20957842B5@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=acae889dd97280ee59b7e04c18005bb8875cb0d2 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master Since commit 9e2a5668f (ash,hush: allow builtins to be tab-completed, closes 7532) ash and hush have supported tab completion of builtins. Other shells, bash and ksh for example, also support tab completion of functions and aliases. Add such support to ash and hush. function old new delta ash_command_name - 92 +92 hush_command_name - 63 +63 ash_builtin_name 17 - -17 hush_builtin_name 38 - -38 ------------------------------------------------------------------------------ (add/remove: 2/2 grow/shrink: 0/0 up/down: 169/-55) Total: 100 bytes Signed-off-by: Ron Yorston Signed-off-by: Avi Halachmi Signed-off-by: Denys Vlasenko --- shell/ash.c | 32 ++++++++++++++++++++++++++++---- shell/hush.c | 14 ++++++++++++-- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/shell/ash.c b/shell/ash.c index d4ee4c93e..d2c5c5d50 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -9732,7 +9732,7 @@ evalpipe(union node *n, int flags) /* setinteractive needs this forward reference */ #if ENABLE_FEATURE_TAB_COMPLETION -static const char *get_builtin_name(int i) FAST_FUNC; +static const char *ash_command_name(int i) FAST_FUNC; #endif /* @@ -9769,7 +9769,7 @@ setinteractive(int on) if (!line_input_state) { line_input_state = new_line_input_t(FOR_SHELL | WITH_PATH_LOOKUP); # if ENABLE_FEATURE_TAB_COMPLETION - line_input_state->get_exe_name = get_builtin_name; + line_input_state->get_exe_name = ash_command_name; # endif # if EDITING_HAS_sh_get_var line_input_state->sh_get_var = lookupvar; @@ -10284,9 +10284,33 @@ find_builtin(const char *name) #if ENABLE_FEATURE_TAB_COMPLETION static const char * FAST_FUNC -get_builtin_name(int i) +ash_command_name(int i) { - return /*i >= 0 &&*/ i < ARRAY_SIZE(builtintab) ? builtintab[i].name + 1 : NULL; + int n; + + if (/*i >= 0 &&*/ i < ARRAY_SIZE(builtintab)) + return builtintab[i].name + 1; + i -= ARRAY_SIZE(builtintab); + + for (n = 0; n < CMDTABLESIZE; n++) { + struct tblentry *cmdp; + for (cmdp = cmdtable[n]; cmdp; cmdp = cmdp->next) { + if (cmdp->cmdtype == CMDFUNCTION && --i < 0) + return cmdp->cmdname; + } + } + +# if ENABLE_ASH_ALIAS + for (n = 0; n < ATABSIZE; n++) { + struct alias *ap; + for (ap = atab[n]; ap; ap = ap->next) { + if (--i < 0) + return ap->name; + } + } +#endif + + return NULL; } #endif diff --git a/shell/hush.c b/shell/hush.c index 202c0993a..f8951d084 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -8220,7 +8220,7 @@ static const struct built_in_command *find_builtin(const char *name) } #if ENABLE_HUSH_JOB && ENABLE_FEATURE_TAB_COMPLETION -static const char * FAST_FUNC get_builtin_name(int i) +static const char * FAST_FUNC hush_command_name(int i) { if (/*i >= 0 && */ i < ARRAY_SIZE(bltins1)) { return bltins1[i].b_cmd; @@ -8229,6 +8229,16 @@ static const char * FAST_FUNC get_builtin_name(int i) if (i < ARRAY_SIZE(bltins2)) { return bltins2[i].b_cmd; } +# if ENABLE_HUSH_FUNCTIONS + { + struct function *funcp; + i -= ARRAY_SIZE(bltins2); + for (funcp = G.top_func; funcp; funcp = funcp->next) { + if (--i < 0) + return funcp->name; + } + } +# endif return NULL; } #endif @@ -10716,7 +10726,7 @@ int hush_main(int argc, char **argv) # if ENABLE_FEATURE_EDITING G.line_input_state = new_line_input_t(FOR_SHELL); # if ENABLE_FEATURE_TAB_COMPLETION - G.line_input_state->get_exe_name = get_builtin_name; + G.line_input_state->get_exe_name = hush_command_name; # endif # if EDITING_HAS_sh_get_var G.line_input_state->sh_get_var = get_local_var_value; From vda.linux at googlemail.com Sun Apr 16 15:54:00 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Sun, 16 Apr 2023 17:54:00 +0200 Subject: [git commit] tr: display usage for incorrect arguments Message-ID: <20230416155454.279A3842C0@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=2ffd8986e21f1782c78e1a9d34f6042af53d876c branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master tr must have one or two non-option arguments. Display the usage message if any other number is present. function old new delta .rodata 108389 108392 +3 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/0 up/down: 3/0) Total: 3 bytes Signed-off-by: Ron Yorston Signed-off-by: Denys Vlasenko --- coreutils/tr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coreutils/tr.c b/coreutils/tr.c index 1e402dfdb..7fe7f89d5 100644 --- a/coreutils/tr.c +++ b/coreutils/tr.c @@ -299,7 +299,7 @@ int tr_main(int argc UNUSED_PARAM, char **argv) */ /* '+': stop at first non-option */ - opts = getopt32(argv, "^+" "Ccds" "\0" "-1"); + opts = getopt32(argv, "^+" "Ccds" "\0" "-1:?2"); argv += optind; str1_length = expand(*argv++, &str1); From vda.linux at googlemail.com Sun Apr 16 16:01:44 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Sun, 16 Apr 2023 18:01:44 +0200 Subject: [git commit] readlink: support --, -n always Message-ID: <20230416160206.08D44842C8@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=d2b81b3dc2b31d32e1060d3ea8bd998d30a37d8a branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master POSIX will be standardizing readlink (just the -n option) and realpath (just -E and -e options): https://www.austingroupbugs.net/view.php?id=1457 Change things for readlink so that the POSIX-mandated -n and -- work even when disabling the non-standard (and partially non-working) -f when FEATURE_READLINK_FOLLOW is clear. POSIX also wants readlink to be verbose by default (if the argument is not a symlink, readlink must output a diagnostic); I did NOT address that one, because I'm waiting to see what the GNU Coreutils folks do: https://lists.gnu.org/archive/html/bug-coreutils/2023-03/msg00035.html Partial fix for https://bugs.busybox.net/show_bug.cgi?id=15466 function old new delta packed_usage 34538 34557 +19 Signed-off-by: Eric Blake Signed-off-by: Denys Vlasenko --- coreutils/readlink.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/coreutils/readlink.c b/coreutils/readlink.c index b2e867883..0a9aa957e 100644 --- a/coreutils/readlink.c +++ b/coreutils/readlink.c @@ -25,12 +25,14 @@ //kbuild:lib-$(CONFIG_READLINK) += readlink.o //usage:#define readlink_trivial_usage -//usage: IF_FEATURE_READLINK_FOLLOW("[-fnv] ") "FILE" +//usage: IF_FEATURE_READLINK_FOLLOW("[-fnv] ") +//usage: IF_NOT_FEATURE_READLINK_FOLLOW("[-n] ") +//usage: "FILE" //usage:#define readlink_full_usage "\n\n" -//usage: "Display the value of a symlink" -//usage: IF_FEATURE_READLINK_FOLLOW( "\n" -//usage: "\n -f Canonicalize by following all symlinks" +//usage: "Display the value of a symlink" "\n" //usage: "\n -n Don't add newline" +//usage: IF_FEATURE_READLINK_FOLLOW( +//usage: "\n -f Canonicalize by following all symlinks" //usage: "\n -v Verbose" //usage: ) @@ -67,25 +69,18 @@ int readlink_main(int argc UNUSED_PARAM, char **argv) { char *buf; char *fname; + unsigned opt; - IF_FEATURE_READLINK_FOLLOW( - unsigned opt; - /* We need exactly one non-option argument. */ - opt = getopt32(argv, "^" "fnvsq" "\0" "=1"); - fname = argv[optind]; - ) - IF_NOT_FEATURE_READLINK_FOLLOW( - const unsigned opt = 0; - if (argc != 2) bb_show_usage(); - fname = argv[1]; - ) + opt = getopt32(argv, "^" "n" IF_FEATURE_READLINK_FOLLOW("fvsq") + "\0" "=1"); + fname = argv[optind]; /* compat: coreutils readlink reports errors silently via exit code */ if (!(opt & 4)) /* not -v */ logmode = LOGMODE_NONE; /* NOFORK: only one alloc is allowed; must free */ - if (opt & 1) { /* -f */ + if (opt & 2) { /* -f */ buf = xmalloc_realpath_coreutils(fname); } else { buf = xmalloc_readlink_or_warn(fname); @@ -93,7 +88,7 @@ int readlink_main(int argc UNUSED_PARAM, char **argv) if (!buf) return EXIT_FAILURE; - printf((opt & 2) ? "%s" : "%s\n", buf); + printf((opt & 1) ? "%s" : "%s\n", buf); free(buf); fflush_stdout_and_exit_SUCCESS(); From vda.linux at googlemail.com Sun Apr 23 10:37:46 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Sun, 23 Apr 2023 12:37:46 +0200 Subject: [git commit] ip: code shrink Message-ID: <20230423103804.0A101843ED@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=7ddd233c807f71fc5a303e89ce166bc1cbccf89e branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta ipaddr_list_or_flush 1089 1079 -10 Signed-off-by: Denys Vlasenko --- networking/libiproute/ip_parse_common_args.c | 77 ++++++++++++++++++++++++++++ networking/libiproute/ipaddress.c | 10 ++-- 2 files changed, 82 insertions(+), 5 deletions(-) diff --git a/networking/libiproute/ip_parse_common_args.c b/networking/libiproute/ip_parse_common_args.c index d693c54fa..eccd7e670 100644 --- a/networking/libiproute/ip_parse_common_args.c +++ b/networking/libiproute/ip_parse_common_args.c @@ -14,6 +14,83 @@ #include "ip_common.h" /* #include "libbb.h" is inside */ #include "utils.h" +/* iproute2-5.17.0: +-V, -Version + Print the version of the ip utility and exit. +-h, -human, -human-readable + output statistics with human readable values followed by suffix. +-b, -batch FILENAME + Read commands from provided file or standard input and invoke them. + First failure will cause termination of ip. +-force Don't terminate ip on errors in batch mode. If there were any errors + during execution of the commands, the application return code will be + non zero. +-s, -stats, -statistics + Output more information. If the option appears twice or more, + the amount of information increases. As a rule, the information + is statistics or some time values. +-d, -details + Output more detailed information. +-l, -loops COUNT + Specify maximum number of loops the 'ip address flush' logic will + attempt before giving up. The default is 10. Zero (0) means loop + until all addresses are removed. +-f, -family FAMILY + Specifies the protocol family to use. The protocol family identifier + can be one of inet, inet6, bridge, mpls or link. If this option is + not present, the protocol family is guessed from other arguments. + If the rest of the command line does not give enough information + to guess the family, ip falls back to the default one, usually inet + or any. link is a special family identifier meaning that + no networking protocol is involved. +-4 shortcut for -family inet. +-6 shortcut for -family inet6. +-B shortcut for -family bridge. +-M shortcut for -family mpls. +-0 shortcut for -family link. +-o, -oneline + output each record on a single line, replacing line feeds with the '\' + character. This is convenient when you want to count records with wc(1) + or to grep(1) the output. +-r, -resolve + use the system's name resolver to print DNS names instead of addresses. +-n, -netns NETNS + switches ip to the specified network namespace NETNS. Actually it just + simplifies executing of: + ip netns exec NETNS ip [ OPTIONS ] OBJECT { COMMAND | help } + to + ip -n[etns] NETNS [ OPTIONS ] OBJECT { COMMAND | help } +-N, -Numeric + Print the number of protocol, scope, dsfield, etc directly instead of + converting it to human readable name. +-a, -all + executes specified command over all objects, it depends if command + supports this option. +-c[color][={always|auto|never} + Configure color output. If parameter is omitted or always, color output + is enabled regardless of stdout state. If parameter is auto, stdout is + checked to be a terminal before enabling color output. If parameter is + never, color output is disabled. If specified multiple times, the last + one takes precedence. This flag is ignored if -json is also given. + Used color palette can be influenced by COLORFGBG environment variable. +-t, -timestamp + display current time when using monitor option. +-ts, -tshort + Like -timestamp, but use shorter format. +-rc, -rcvbuf SIZE + Set the netlink socket receive buffer size, defaults to 1MB. +-iec print human readable rates in IEC units (e.g. 1Ki = 1024). +-br, -brief + Print only basic information in a tabular format for better readability. + This option is currently only supported by ip addr show , ip link show + & ip neigh show commands. +-j, -json + Output results in JavaScript Object Notation (JSON). +-p, -pretty + The default JSON format is compact and more efficient to parse but hard + for most users to read. This flag adds indentation for readability. +*/ + family_t preferred_family = AF_UNSPEC; smallint oneline; char _SL_; diff --git a/networking/libiproute/ipaddress.c b/networking/libiproute/ipaddress.c index ecc3848ff..c8d77422c 100644 --- a/networking/libiproute/ipaddress.c +++ b/networking/libiproute/ipaddress.c @@ -44,7 +44,7 @@ struct filter_t { int ifindex; family_t family; smallint showqueue; - smallint oneline; + /*smallint oneline; - redundant, global "oneline" flag is enough */ smallint up; /* Misnomer. Does not mean "flushed something" */ /* More like "flush commands were constructed by print_addrinfo()" */ @@ -297,7 +297,7 @@ static int FAST_FUNC print_addrinfo(const struct sockaddr_nl *who UNUSED_PARAM, if (n->nlmsg_type == RTM_DELADDR) printf("Deleted "); - if (G_filter.oneline) + if (/*G_filter.*/ oneline) printf("%u: %s", ifa->ifa_index, ll_index_to_name(ifa->ifa_index)); if (ifa->ifa_family == AF_INET) printf(" inet "); @@ -427,10 +427,10 @@ static int FAST_FUNC store_nlmsg(const struct sockaddr_nl *who, struct nlmsghdr return 0; } -static void ipaddr_reset_filter(int _oneline) +static void ipaddr_reset_filter(void /*int _oneline*/) { memset(&G_filter, 0, sizeof(G_filter)); - G_filter.oneline = _oneline; + /*G_filter.oneline = _oneline;*/ } /* Return value becomes exitcode. It's okay to not return at all */ @@ -444,7 +444,7 @@ int FAST_FUNC ipaddr_list_or_flush(char **argv, int flush) struct rtnl_handle rth; char *filter_dev = NULL; - ipaddr_reset_filter(oneline); + ipaddr_reset_filter(/*oneline*/); G_filter.showqueue = 1; if (G_filter.family == AF_UNSPEC) From vda.linux at googlemail.com Sun Apr 23 12:02:20 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Sun, 23 Apr 2023 14:02:20 +0200 Subject: [git commit] factor: we can pack 21, not 20, 3-bit elements into packed wheel words Message-ID: <20230423120232.CFE8B8448E@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=382e1634972f7aab883259dd22cf721d1c205055 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta packed_wheel 192 184 -8 factor_main 171 163 -8 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-16) Total: -16 bytes Signed-off-by: Denys Vlasenko --- coreutils/factor.c | 71 +++++++++++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/coreutils/factor.c b/coreutils/factor.c index de8ea4e11..46dd2a0d7 100644 --- a/coreutils/factor.c +++ b/coreutils/factor.c @@ -48,38 +48,40 @@ typedef unsigned long half_t; * Larger wheels improve sieving only slightly, but quickly grow in size * (adding just one prime, 13, results in 5766 element sieve). */ -#define R(a,b,c,d,e,f,g,h,i,j,A,B,C,D,E,F,G,H,I,J) \ - (((uint64_t)(a<<0) | (b<<3) | (c<<6) | (d<<9) | (e<<12) | (f<<15) | (g<<18) | (h<<21) | (i<<24) | (j<<27)) << 1) | \ - (((uint64_t)(A<<0) | (B<<3) | (C<<6) | (D<<9) | (E<<12) | (F<<15) | (G<<18) | (H<<21) | (I<<24) | (J<<27)) << 31) -#define P(a,b,c,d,e,f,g,h,i,j,A,B,C,D,E,F,G,H,I,J) \ +#define R(a,b,c,d,e,f,g,h,i,j,A,B,C,D,E,F,G,H,I,J,x) \ + (((uint64_t)(a<<0) | (b<<3) | (c<<6) | (d<<9) | (e<<12) | (f<<15) | (g<<18) | (h<<21) | (i<<24) | (j<<27)) << 1) | \ + (((uint64_t)(A<<0) | (B<<3) | (C<<6) | (D<<9) | (E<<12) | (F<<15) | (G<<18) | (H<<21) | (I<<24) | (J<<27)) << 31) | \ + ((uint64_t)x << 61) +#define P(a,b,c,d,e,f,g,h,i,j,A,B,C,D,E,F,G,H,I,J,x) \ R( (a/2),(b/2),(c/2),(d/2),(e/2),(f/2),(g/2),(h/2),(i/2),(j/2), \ - (A/2),(B/2),(C/2),(D/2),(E/2),(F/2),(G/2),(H/2),(I/2),(J/2) ) + (A/2),(B/2),(C/2),(D/2),(E/2),(F/2),(G/2),(H/2),(I/2),(J/2), \ + (x/2) \ + ) static const uint64_t packed_wheel[] = { - /*1, 2, 2, 4, 2,*/ - P( 4, 2, 4, 6, 2, 6, 4, 2, 4, 6, 6, 2, 6, 4, 2, 6, 4, 6, 8, 4), //01 - P( 2, 4, 2, 4,14, 4, 6, 2,10, 2, 6, 6, 4, 2, 4, 6, 2,10, 2, 4), //02 - P( 2,12,10, 2, 4, 2, 4, 6, 2, 6, 4, 6, 6, 6, 2, 6, 4, 2, 6, 4), //03 - P( 6, 8, 4, 2, 4, 6, 8, 6,10, 2, 4, 6, 2, 6, 6, 4, 2, 4, 6, 2), //04 - P( 6, 4, 2, 6,10, 2,10, 2, 4, 2, 4, 6, 8, 4, 2, 4,12, 2, 6, 4), //05 - P( 2, 6, 4, 6,12, 2, 4, 2, 4, 8, 6, 4, 6, 2, 4, 6, 2, 6,10, 2), //06 - P( 4, 6, 2, 6, 4, 2, 4, 2,10, 2,10, 2, 4, 6, 6, 2, 6, 6, 4, 6), //07 - P( 6, 2, 6, 4, 2, 6, 4, 6, 8, 4, 2, 6, 4, 8, 6, 4, 6, 2, 4, 6), //08 - P( 8, 6, 4, 2,10, 2, 6, 4, 2, 4, 2,10, 2,10, 2, 4, 2, 4, 8, 6), //09 - P( 4, 2, 4, 6, 6, 2, 6, 4, 8, 4, 6, 8, 4, 2, 4, 2, 4, 8, 6, 4), //10 - P( 6, 6, 6, 2, 6, 6, 4, 2, 4, 6, 2, 6, 4, 2, 4, 2,10, 2,10, 2), //11 - P( 6, 4, 6, 2, 6, 4, 2, 4, 6, 6, 8, 4, 2, 6,10, 8, 4, 2, 4, 2), //12 - P( 4, 8,10, 6, 2, 4, 8, 6, 6, 4, 2, 4, 6, 2, 6, 4, 6, 2,10, 2), //13 - P(10, 2, 4, 2, 4, 6, 2, 6, 4, 2, 4, 6, 6, 2, 6, 6, 6, 4, 6, 8), //14 - P( 4, 2, 4, 2, 4, 8, 6, 4, 8, 4, 6, 2, 6, 6, 4, 2, 4, 6, 8, 4), //15 - P( 2, 4, 2,10, 2,10, 2, 4, 2, 4, 6, 2,10, 2, 4, 6, 8, 6, 4, 2), //16 - P( 6, 4, 6, 8, 4, 6, 2, 4, 8, 6, 4, 6, 2, 4, 6, 2, 6, 6, 4, 6), //17 - P( 6, 2, 6, 6, 4, 2,10, 2,10, 2, 4, 2, 4, 6, 2, 6, 4, 2,10, 6), //18 - P( 2, 6, 4, 2, 6, 4, 6, 8, 4, 2, 4, 2,12, 6, 4, 6, 2, 4, 6, 2), //19 - P(12, 4, 2, 4, 8, 6, 4, 2, 4, 2,10, 2,10, 6, 2, 4, 6, 2, 6, 4), //20 - P( 2, 4, 6, 6, 2, 6, 4, 2,10, 6, 8, 6, 4, 2, 4, 8, 6, 4, 6, 2), //21 - P( 4, 6, 2, 6, 6, 6, 4, 6, 2, 6, 4, 2, 4, 2,10,12, 2, 4, 2,10), //22 - P( 2, 6, 4, 2, 4, 6, 6, 2,10, 2, 6, 4,14, 4, 2, 4, 2, 4, 8, 6), //23 - P( 4, 6, 2, 4, 6, 2, 6, 6, 4, 2, 4, 6, 2, 6, 4, 2, 4,12, 2,12), //24 + /* 1, 2, */ + P( 2, 4, 2, 4, 2, 4, 6, 2, 6, 4, 2, 4, 6, 6, 2, 6, 4, 2, 6, 4, 6), + P( 8, 4, 2, 4, 2, 4,14, 4, 6, 2,10, 2, 6, 6, 4, 2, 4, 6, 2,10, 2), + P( 4, 2,12,10, 2, 4, 2, 4, 6, 2, 6, 4, 6, 6, 6, 2, 6, 4, 2, 6, 4), + P( 6, 8, 4, 2, 4, 6, 8, 6,10, 2, 4, 6, 2, 6, 6, 4, 2, 4, 6, 2, 6), + P( 4, 2, 6,10, 2,10, 2, 4, 2, 4, 6, 8, 4, 2, 4,12, 2, 6, 4, 2, 6), + P( 4, 6,12, 2, 4, 2, 4, 8, 6, 4, 6, 2, 4, 6, 2, 6,10, 2, 4, 6, 2), + P( 6, 4, 2, 4, 2,10, 2,10, 2, 4, 6, 6, 2, 6, 6, 4, 6, 6, 2, 6, 4), + P( 2, 6, 4, 6, 8, 4, 2, 6, 4, 8, 6, 4, 6, 2, 4, 6, 8, 6, 4, 2,10), + P( 2, 6, 4, 2, 4, 2,10, 2,10, 2, 4, 2, 4, 8, 6, 4, 2, 4, 6, 6, 2), + P( 6, 4, 8, 4, 6, 8, 4, 2, 4, 2, 4, 8, 6, 4, 6, 6, 6, 2, 6, 6, 4), + P( 2, 4, 6, 2, 6, 4, 2, 4, 2,10, 2,10, 2, 6, 4, 6, 2, 6, 4, 2, 4), + P( 6, 6, 8, 4, 2, 6,10, 8, 4, 2, 4, 2, 4, 8,10, 6, 2, 4, 8, 6, 6), + P( 4, 2, 4, 6, 2, 6, 4, 6, 2,10, 2,10, 2, 4, 2, 4, 6, 2, 6, 4, 2), + P( 4, 6, 6, 2, 6, 6, 6, 4, 6, 8, 4, 2, 4, 2, 4, 8, 6, 4, 8, 4, 6), + P( 2, 6, 6, 4, 2, 4, 6, 8, 4, 2, 4, 2,10, 2,10, 2, 4, 2, 4, 6, 2), + P(10, 2, 4, 6, 8, 6, 4, 2, 6, 4, 6, 8, 4, 6, 2, 4, 8, 6, 4, 6, 2), + P( 4, 6, 2, 6, 6, 4, 6, 6, 2, 6, 6, 4, 2,10, 2,10, 2, 4, 2, 4, 6), + P( 2, 6, 4, 2,10, 6, 2, 6, 4, 2, 6, 4, 6, 8, 4, 2, 4, 2,12, 6, 4), + P( 6, 2, 4, 6, 2,12, 4, 2, 4, 8, 6, 4, 2, 4, 2,10, 2,10, 6, 2, 4), + P( 6, 2, 6, 4, 2, 4, 6, 6, 2, 6, 4, 2,10, 6, 8, 6, 4, 2, 4, 8, 6), + P( 4, 6, 2, 4, 6, 2, 6, 6, 6, 4, 6, 2, 6, 4, 2, 4, 2,10,12, 2, 4), + P( 2,10, 2, 6, 4, 2, 4, 6, 6, 2,10, 2, 6, 4,14, 4, 2, 4, 2, 4, 8), + P( 6, 4, 6, 2, 4, 6, 2, 6, 6, 4, 2, 4, 6, 2, 6, 4, 2, 4,12, 2,12), }; #undef P #undef R @@ -93,8 +95,8 @@ static const uint64_t packed_wheel[] = { * function old new delta * wheel_tab - 485 +485 * 3-bit-packed insanity: - * packed_wheel - 192 +192 - * factor_main 108 171 +63 + * packed_wheel - 184 +184 + * factor_main 108 163 +55 */ static void unpack_wheel(void) { @@ -104,10 +106,7 @@ static void unpack_wheel(void) setup_common_bufsiz(); wheel_tab[0] = 1; wheel_tab[1] = 2; - wheel_tab[2] = 2; - wheel_tab[3] = 4; - wheel_tab[4] = 2; - p = &wheel_tab[5]; + p = &wheel_tab[2]; for (i = 0; i < ARRAY_SIZE(packed_wheel); i++) { uint64_t v = packed_wheel[i]; while ((v & 0xe) != 0) { From vda.linux at googlemail.com Tue Apr 25 13:54:35 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Tue, 25 Apr 2023 15:54:35 +0200 Subject: [git commit] Remove blackfin information, this CPU line is discontinued Message-ID: <20230425135526.5E8A084506@busybox.osuosl.org> commit: https://git.busybox.net/busybox-website/commit/?id=f7bafe81a7da4e9b0c8bbb33b5220caf552f9ed8 branch: https://git.busybox.net/busybox-website/commit/?id=refs/heads/master Signed-off-by: Denys Vlasenko --- news.html | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/news.html b/news.html index f986ea7..282f2d6 100644 --- a/news.html +++ b/news.html @@ -17,23 +17,6 @@

-
  • -

    I want to thank the following companies which are providing support for the BusyBox project: -

      -
    • Analog Devices, Inc. provided - a Blackfin development board free of charge. - Blackfin - is a NOMMU processor, and its availability for testing is invaluable. - If you are an embedded device developer, - please note that Analog Devices has an entire Linux distribution available - for download for this board. Visit - http://blackfin.uclinux.org/ - for more information. -
    • -
    -

    -
  • -
  • 3 January 2023 -- BusyBox 1.36.0 (unstable)

    BusyBox 1.36.0. (git, From vda.linux at googlemail.com Tue Apr 25 14:47:22 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Tue, 25 Apr 2023 16:47:22 +0200 Subject: [git commit branch/1_36_stable] ash: fix broken new mail detection Message-ID: <20230425144734.6F0228459B@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=07bc5de67b2724a6ed9bb980f3439504b67e20ec branch: https://git.busybox.net/busybox/commit/?id=refs/heads/1_36_stable Mea culpa, in "Do not allocate stack string in padvance" commit (I left an extraneous "break" statement). function old new delta cmdloop 329 398 +69 Signed-off-by: Denys Vlasenko --- shell/ash.c | 1 - 1 file changed, 1 deletion(-) diff --git a/shell/ash.c b/shell/ash.c index 18ccc1329..c15bce7ae 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -11287,7 +11287,6 @@ chkmail(void) if (!len) break; p = stackblock(); - break; if (*p == '\0') continue; for (q = p; *q; q++) From vda.linux at googlemail.com Tue Apr 25 14:47:22 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Tue, 25 Apr 2023 16:47:22 +0200 Subject: [git commit branch/1_36_stable] ash: fix still-broken new mail detection Message-ID: <20230425144734.7E5138459D@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=90f5f2a190bca489fac513a150ffab79c6f585b2 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/1_36_stable padvance() exit condition is return value < 0, not == 0. After MAIL changing twice, the logic erroneously concluded that "you have new mail". Signed-off-by: Denys Vlasenko --- shell/ash.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/shell/ash.c b/shell/ash.c index c15bce7ae..9344e4de1 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -11264,8 +11264,8 @@ static smallint mail_var_path_changed; /* * Print appropriate message(s) if mail has arrived. * If mail_var_path_changed is set, - * then the value of MAIL has mail_var_path_changed, - * so we just update the values. + * then the value of MAIL has changed, + * so we just update the hash value. */ static void chkmail(void) @@ -11284,7 +11284,7 @@ chkmail(void) int len; len = padvance_magic(&mpath, nullstr, 2); - if (!len) + if (len < 0) break; p = stackblock(); if (*p == '\0') @@ -11305,8 +11305,8 @@ chkmail(void) if (!mail_var_path_changed && mailtime_hash != new_hash) { if (mailtime_hash != 0) out2str("you have mail\n"); - mailtime_hash = new_hash; } + mailtime_hash = new_hash; mail_var_path_changed = 0; popstackmark(&smark); } From vda.linux at googlemail.com Tue Apr 25 14:47:22 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Tue, 25 Apr 2023 16:47:22 +0200 Subject: [git commit branch/1_36_stable] lineedit: fix matching of directories when searching PATH Message-ID: <20230425144734.5FFFE8459A@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=64e967fabb1cf6c190b76f51c69e0ecb5fa49be5 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/1_36_stable Commit 8baa643a3 (lineedit: match local directories when searching PATH) included subdirectories of the current directory in the search when tab-completing commands. Unfortunately a short time later commit 1d180cd74 (lineedit: use strncmp instead of is_prefixed_with (we know the length)) broke this feature by returning an incorrect length for the array of paths. Fix the length and reinstate matching of subdirectories. Signed-off-by: Ron Yorston Signed-off-by: Denys Vlasenko --- libbb/lineedit.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libbb/lineedit.c b/libbb/lineedit.c index d6b2e76ff..ed7c42ba8 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -825,8 +825,8 @@ static unsigned path_parse(char ***p) res[npth++] = tmp; } /* special case: "match subdirectories of the current directory" */ - /*res[npth++] = NULL; - filled by xzalloc() */ - return npth; + /*res[npth] = NULL; - filled by xzalloc() */ + return npth + 1; } /* Complete command, directory or file name. From vda.linux at googlemail.com Tue Apr 25 14:47:22 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Tue, 25 Apr 2023 16:47:22 +0200 Subject: [git commit branch/1_36_stable] ash: sleep builtin with no arguments should not exit Message-ID: <20230425144734.966578459A@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=d661cb1977def8215c50ae3eed1f9beb2877b862 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/1_36_stable function old new delta sleep_main 116 143 +27 .rodata 105245 105268 +23 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 50/0) Total: 50 bytes Signed-off-by: Denys Vlasenko --- coreutils/sleep.c | 15 ++++++++++++++- procps/kill.c | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/coreutils/sleep.c b/coreutils/sleep.c index 442841210..667db558d 100644 --- a/coreutils/sleep.c +++ b/coreutils/sleep.c @@ -65,15 +65,28 @@ int sleep_main(int argc UNUSED_PARAM, char **argv) { duration_t duration; + /* Note: sleep_main may be directly called from ash as a builtin. + * This brings some complications: + * + we can't use xfunc here + * + we can't use bb_show_usage + * + applet_name can be the name of the shell + */ ++argv; - if (!*argv) + if (!*argv) { + /* Without this, bare "sleep" in ash shows _ash_ --help */ + if (ENABLE_ASH_SLEEP && applet_name[0] != 's') { + bb_simple_error_msg("sleep: missing operand"); + return EXIT_FAILURE; + } bb_show_usage(); + } /* GNU sleep accepts "inf", "INF", "infinity" and "INFINITY" */ if (strncasecmp(argv[0], "inf", 3) == 0) for (;;) sleep(INT_MAX); +//FIXME: in ash, "sleep 123qwerty" as a builtin aborts the shell #if ENABLE_FEATURE_FANCY_SLEEP duration = 0; do { diff --git a/procps/kill.c b/procps/kill.c index 8f10e21ab..208efebde 100644 --- a/procps/kill.c +++ b/procps/kill.c @@ -85,8 +85,8 @@ * This brings some complications: * * + we can't use xfunc here - * + we can't use applet_name * + we can't use bb_show_usage + * + applet_name can be the name of the shell * (doesn't apply for killall[5], still should be careful b/c NOFORK) * * kill %n gets translated into kill ' -' by shell (note space!) From vda.linux at googlemail.com Tue Apr 25 14:47:22 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Tue, 25 Apr 2023 16:47:22 +0200 Subject: [git commit branch/1_36_stable] hush: printf builtin with no arguments should not exit Message-ID: <20230425144734.8A1A68459E@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=515adcc9f3eb437400c08c24e0f19b149aed7f06 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/1_36_stable Signed-off-by: Denys Vlasenko --- coreutils/printf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coreutils/printf.c b/coreutils/printf.c index 2e672d15f..b89df67f9 100644 --- a/coreutils/printf.c +++ b/coreutils/printf.c @@ -428,7 +428,7 @@ int printf_main(int argc UNUSED_PARAM, char **argv) if (argv[1] && argv[1][0] == '-' && argv[1][1] == '-' && !argv[1][2]) argv++; if (!argv[1]) { - if (ENABLE_ASH_PRINTF + if ((ENABLE_ASH_PRINTF || ENABLE_HUSH_PRINTF) && applet_name[0] != 'p' ) { bb_simple_error_msg("usage: printf FORMAT [ARGUMENT...]"); From vda.linux at googlemail.com Tue Apr 25 14:47:22 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Tue, 25 Apr 2023 16:47:22 +0200 Subject: [git commit branch/1_36_stable] sleep: fix error exit when called as "sh" builtin Message-ID: <20230425144734.AAA8A8459D@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=384cd2e436e9b15a7ffe2bf93260d94992dc1193 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/1_36_stable Signed-off-by: Denys Vlasenko --- coreutils/sleep.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/coreutils/sleep.c b/coreutils/sleep.c index 667db558d..a0cee5a4a 100644 --- a/coreutils/sleep.c +++ b/coreutils/sleep.c @@ -74,7 +74,8 @@ int sleep_main(int argc UNUSED_PARAM, char **argv) ++argv; if (!*argv) { /* Without this, bare "sleep" in ash shows _ash_ --help */ - if (ENABLE_ASH_SLEEP && applet_name[0] != 's') { + /* (ash can be the "sh" applet as well, so check 2nd char) */ + if (ENABLE_ASH_SLEEP && applet_name[1] != 'l') { bb_simple_error_msg("sleep: missing operand"); return EXIT_FAILURE; } From vda.linux at googlemail.com Tue Apr 25 14:47:22 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Tue, 25 Apr 2023 16:47:22 +0200 Subject: [git commit branch/1_36_stable] ash: fix sleep built-in not running INT trap immediately on ^C Message-ID: <20230425144734.A213C8459B@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=ce839dea92ce10627094096835e831bf5d267631 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/1_36_stable function old new delta sleep_for_duration 169 149 -20 Signed-off-by: Denys Vlasenko --- libbb/duration.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/libbb/duration.c b/libbb/duration.c index 793d02f42..0024f1a66 100644 --- a/libbb/duration.c +++ b/libbb/duration.c @@ -76,16 +76,14 @@ void FAST_FUNC sleep_for_duration(duration_t duration) ts.tv_sec = duration; ts.tv_nsec = (duration - ts.tv_sec) * 1000000000; } - /* NB: if ENABLE_ASH_SLEEP, we end up here if "sleep N" - * is run in ash. ^C will still work, because ash's signal handler - * does not return (it longjumps), the below loop - * will not continue looping. - * (This wouldn't work in hush) + /* NB: ENABLE_ASH_SLEEP requires that we do NOT loop on EINTR here: + * otherwise, traps won't execute until we finish looping. */ - do { - errno = 0; - nanosleep(&ts, &ts); - } while (errno == EINTR); + //do { + // errno = 0; + // nanosleep(&ts, &ts); + //} while (errno == EINTR); + nanosleep(&ts, &ts); } #else duration_t FAST_FUNC parse_duration_str(char *str) From vda.linux at googlemail.com Tue Apr 25 14:47:22 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Tue, 25 Apr 2023 16:47:22 +0200 Subject: [git commit branch/1_36_stable] lineedit: fix crash when icanon set with -echo Message-ID: <20230425144734.B42CC8459F@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=38d2d26a5fec3dfd24493c8b42a90e4c413f80d5 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/1_36_stable When icanon is set with -echo (e.g. ssh from an emacs shell) then S.state will remain null but later it will be deferenced causing ash to crash. Fix: additional check on state. Signed-off-by: Akos Somfai Signed-off-by: Denys Vlasenko --- libbb/lineedit.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libbb/lineedit.c b/libbb/lineedit.c index ed7c42ba8..c87d6064a 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -254,7 +254,7 @@ static NOINLINE const char *get_homedir_or_NULL(void) const char *home; # if ENABLE_SHELL_ASH || ENABLE_SHELL_HUSH - home = state->sh_get_var ? state->sh_get_var("HOME") : getenv("HOME"); + home = state && state->sh_get_var ? state->sh_get_var("HOME") : getenv("HOME"); # else home = getenv("HOME"); # endif @@ -2038,7 +2038,7 @@ static void parse_and_put_prompt(const char *prmt_ptr) if (!cwd_buf) { const char *home; # if EDITING_HAS_sh_get_var - cwd_buf = state->sh_get_var + cwd_buf = state && state->sh_get_var ? xstrdup(state->sh_get_var("PWD")) : xrealloc_getcwd_or_warn(NULL); # else