From 9b4a9d96b89f06355ad9551d782d34506699aac8 Mon Sep 17 00:00:00 2001 From: Martin Lewis Date: Sun, 8 Mar 2020 13:35:20 -0500 Subject: xstrndup: Use strndup instead of implementing it. Signed-off-by: Martin Lewis Signed-off-by: Denys Vlasenko --- libbb/xfuncs_printf.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) (limited to 'libbb') diff --git a/libbb/xfuncs_printf.c b/libbb/xfuncs_printf.c index 93f325c62..f1cf7aeed 100644 --- a/libbb/xfuncs_printf.c +++ b/libbb/xfuncs_printf.c @@ -93,26 +93,17 @@ char* FAST_FUNC xstrdup(const char *s) // the (possibly truncated to length n) string into it. char* FAST_FUNC xstrndup(const char *s, int n) { - int m; char *t; if (ENABLE_DEBUG && s == NULL) bb_simple_error_msg_and_die("xstrndup bug"); - /* We can just xmalloc(n+1) and strncpy into it, */ - /* but think about xstrndup("abc", 10000) wastage! */ - m = n; - t = (char*) s; - while (m) { - if (!*t) break; - m--; - t++; - } - n -= m; - t = xmalloc(n + 1); - t[n] = '\0'; + t = strndup(s, n); - return memcpy(t, s, n); + if (t == NULL) + bb_die_memory_exhausted(); + + return t; } void* FAST_FUNC xmemdup(const void *s, int n) -- cgit v1.2.3-55-g6feb From 5fa5c4bde8b9ab75fa0ed37ee2fafca3fd46288a Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 23 Jun 2020 21:28:19 +0200 Subject: randomconfig fixes Signed-off-by: Denys Vlasenko --- editors/patch.c | 3 ++- include/libbb.h | 1 + libbb/duration.c | 1 + scripts/randomtest | 22 ++++++++++++++++++++++ testsuite/cpio.tests | 6 +++--- testsuite/patch.tests | 4 ++-- 6 files changed, 31 insertions(+), 6 deletions(-) (limited to 'libbb') diff --git a/editors/patch.c b/editors/patch.c index 0ce0210fd..aaa253591 100644 --- a/editors/patch.c +++ b/editors/patch.c @@ -264,7 +264,7 @@ static int apply_one_hunk(void) if (!plist && matcheof) break; if (backwarn) - fdprintf(2,"Possibly reversed hunk %d at %ld\n", + fdprintf(2, "Possibly reversed hunk %d at %ld\n", TT.hunknum, TT.linenum); // File ended before we found a place for this hunk. @@ -593,6 +593,7 @@ int patch_main(int argc UNUSED_PARAM, char **argv) TT.linenum = 0; TT.hunknum = 0; } + fflush_all(); // make "patching file F" visible } TT.hunknum++; diff --git a/include/libbb.h b/include/libbb.h index d9858f5df..6be934994 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -298,6 +298,7 @@ typedef unsigned long uoff_t; /* scary. better ideas? (but do *test* them first!) */ #define OFF_T_MAX ((off_t)~((off_t)1 << (sizeof(off_t)*8-1))) /* Users report bionic to use 32-bit off_t even if LARGEFILE support is requested. + * On musl, !ENABLE_LFS on 32-bit arches thinks that off_t is 32-bit. * We misdetected that. Don't let it build: */ struct BUG_off_t_size_is_misdetected { diff --git a/libbb/duration.c b/libbb/duration.c index 5acd0dba3..22b209f4d 100644 --- a/libbb/duration.c +++ b/libbb/duration.c @@ -17,6 +17,7 @@ //kbuild:lib-$(CONFIG_TIMEOUT) += duration.o //kbuild:lib-$(CONFIG_PING) += duration.o //kbuild:lib-$(CONFIG_PING6) += duration.o +//kbuild:lib-$(CONFIG_WATCH) += duration.o #include "libbb.h" diff --git a/scripts/randomtest b/scripts/randomtest index 94709a99f..ec2f095b2 100755 --- a/scripts/randomtest +++ b/scripts/randomtest @@ -113,6 +113,28 @@ if test x"$LIBC" = x"uclibc"; then echo 'CONFIG_ASH_INTERNAL_GLOB=y' >>.config fi +# If musl +if test x"$LIBC" = x"musl"; then + cat .config \ + | grep -v CONFIG_STATIC \ + | grep -v CONFIG_LFS \ + | grep -v CONFIG_EXTRA_COMPAT \ + | grep -v CONFIG_FEATURE_2_4_MODULES \ + | grep -v CONFIG_FEATURE_VI_REGEX_SEARCH \ + | grep -v CONFIG_FEATURE_MOUNT_NFS \ + | grep -v CONFIG_FEATURE_INETD_RPC \ + >.config.new + mv .config.new .config + echo 'CONFIG_STATIC=y' >>.config + # with LFS off, uoff_t will have wrong width: + echo 'CONFIG_LFS=y' >>.config + echo '# CONFIG_EXTRA_COMPAT is not set' >>.config + echo '# CONFIG_FEATURE_2_4_MODULES is not set' >>.config + echo '# CONFIG_FEATURE_VI_REGEX_SEARCH is not set' >>.config + echo '# CONFIG_FEATURE_MOUNT_NFS is not set' >>.config + echo '# CONFIG_FEATURE_INETD_RPC is not set' >>.config +fi + # If STATIC, remove some things. # PAM with static linking is probably pointless # (but I need to try - now I don't have libpam.a on my system, only libpam.so) diff --git a/testsuite/cpio.tests b/testsuite/cpio.tests index 88ec086b6..85e746589 100755 --- a/testsuite/cpio.tests +++ b/testsuite/cpio.tests @@ -129,7 +129,7 @@ SKIP= optional FEATURE_CPIO_O testing "cpio uses by default uid/gid" \ -"echo $0 | cpio -o -H newc | cpio -tv 2>&1 | tail -n +2 | awk ' { print \$2 } '; echo \$?" \ +"echo $0 | cpio -o -H newc | cpio -tv 2>&1 | head -n1 | awk ' { print \$2 } '; echo \$?" \ "\ $user/$group 0 @@ -138,7 +138,7 @@ SKIP= optional FEATURE_CPIO_O testing "cpio -R with create" \ -"echo $0 | cpio -o -H newc -R 1234:5678 | cpio -tv 2>&1 | tail -n +2 | awk ' { print \$2 } '; echo \$?" \ +"echo $0 | cpio -o -H newc -R 1234:5678 | cpio -tv 2>&1 | head -n1 | awk ' { print \$2 } '; echo \$?" \ "\ 1234/5678 0 @@ -147,7 +147,7 @@ SKIP= optional FEATURE_CPIO_O testing "cpio -R with extract" \ -"echo $0 | cpio -o -H newc | cpio -tv -R 8765:4321 2>&1 | tail -n +2 | awk ' { print \$2 } '; echo \$?" \ +"echo $0 | cpio -o -H newc | cpio -tv -R 8765:4321 2>&1 | head -n1 | awk ' { print \$2 } '; echo \$?" \ "\ 8765/4321 0 diff --git a/testsuite/patch.tests b/testsuite/patch.tests index 39205242c..1d48e90be 100755 --- a/testsuite/patch.tests +++ b/testsuite/patch.tests @@ -75,12 +75,12 @@ zxc testing "patch detects already applied hunk" \ 'patch 2>&1; echo $?; cat input' \ "\ +patching file input Possibly reversed hunk 1 at 4 Hunk 1 FAILED 1/1. abc +def 123 -patching file input 1 abc def @@ -103,12 +103,12 @@ def testing "patch detects already applied hunk at the EOF" \ 'patch 2>&1; echo $?; cat input' \ "\ +patching file input Possibly reversed hunk 1 at 4 Hunk 1 FAILED 1/1. abc 123 +456 -patching file input 1 abc 123 -- cgit v1.2.3-55-g6feb From d5314e71294d228cff5d86e00d15661461f68fc9 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 24 Jun 2020 09:31:30 +0200 Subject: suppress a few compile warnings Signed-off-by: Denys Vlasenko --- libbb/lineedit.c | 2 +- shell/hush.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'libbb') diff --git a/libbb/lineedit.c b/libbb/lineedit.c index de236dea0..e40a72064 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -99,7 +99,7 @@ static bool BB_ispunct(CHAR_T c) # if ENABLE_FEATURE_EDITING_VI static bool BB_isalnum_or_underscore(CHAR_T c) { - return ((unsigned)c < 256 && isalnum(c)) || c == '_'; + return isalnum(c) || c == '_'; } # endif # define BB_ispunct(c) ispunct(c) diff --git a/shell/hush.c b/shell/hush.c index cab7ea5b0..2cf2170ca 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -7917,7 +7917,7 @@ static const struct built_in_command *find_builtin(const char *name) return find_builtin_helper(name, bltins2, &bltins2[ARRAY_SIZE(bltins2)]); } -#if EDITING_HAS_get_exe_name +#if ENABLE_HUSH_JOB && EDITING_HAS_get_exe_name static const char * FAST_FUNC get_builtin_name(int i) { if (/*i >= 0 && */ i < ARRAY_SIZE(bltins1)) { -- cgit v1.2.3-55-g6feb From 67e1529b921416d6c3f33fb43691bc9919e3eacc Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 24 Jun 2020 13:39:13 +0200 Subject: nologin: make it possible to build it as single applet Signed-off-by: Denys Vlasenko --- libbb/appletlib.c | 38 +++++++++++++++++++++++---- shell/Config.src | 20 ++++++++------ shell/ash.c | 41 +++++++++++++++-------------- shell/hush.c | 73 ++++++++++++++++++++++++++++++---------------------- util-linux/nologin.c | 2 +- 5 files changed, 110 insertions(+), 64 deletions(-) (limited to 'libbb') diff --git a/libbb/appletlib.c b/libbb/appletlib.c index f842e73cc..a515c3fe3 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c @@ -754,7 +754,9 @@ static void install_links(const char *busybox UNUSED_PARAM, } # endif +# if ENABLE_BUSYBOX || NUM_APPLETS > 0 static void run_applet_and_exit(const char *name, char **argv) NORETURN; +#endif # if NUM_SCRIPTS > 0 static int find_script_by_name(const char *name) @@ -775,13 +777,13 @@ int scripted_main(int argc UNUSED_PARAM, char **argv) { int script = find_script_by_name(applet_name); if (script >= 0) -#if ENABLE_ASH || ENABLE_SH_IS_ASH || ENABLE_BASH_IS_ASH +# if ENABLE_SHELL_ASH exit(ash_main(-script - 1, argv)); -#elif ENABLE_HUSH || ENABLE_SH_IS_HUSH || ENABLE_BASH_IS_HUSH +# elif ENABLE_SHELL_HUSH exit(hush_main(-script - 1, argv)); -#else +# else return 1; -#endif +# endif return 0; } @@ -1024,7 +1026,33 @@ static NORETURN void run_applet_and_exit(const char *name, char **argv) } # endif -#endif /* !defined(SINGLE_APPLET_MAIN) */ +#else /* defined(SINGLE_APPLET_MAIN) */ + +# if NUM_SCRIPTS > 0 +/* if SINGLE_APPLET_MAIN, these two functions are simpler: */ +int scripted_main(int argc UNUSED_PARAM, char **argv) MAIN_EXTERNALLY_VISIBLE; +int scripted_main(int argc UNUSED_PARAM, char **argv) +{ +# if ENABLE_SHELL_ASH + int script = 0; + exit(ash_main(-script - 1, argv)); +# elif ENABLE_SHELL_HUSH + int script = 0; + exit(hush_main(-script - 1, argv)); +# else + return 1; +# endif +} +char* FAST_FUNC +get_script_content(unsigned n UNUSED_PARAM) +{ + char *t = unpack_bz2_data(packed_scripts, sizeof(packed_scripts), + UNPACKED_SCRIPTS_LENGTH); + return t; +} +# endif /* NUM_SCRIPTS > 0 */ + +#endif /* defined(SINGLE_APPLET_MAIN) */ #if ENABLE_BUILD_LIBBUSYBOX diff --git a/shell/Config.src b/shell/Config.src index d7623f774..5efbf9995 100644 --- a/shell/Config.src +++ b/shell/Config.src @@ -17,6 +17,7 @@ choice config SH_IS_ASH depends on !NOMMU bool "ash" + select SHELL_ASH help Choose ash to be the shell executed by 'sh' name. The ash code will be built into busybox. If you don't select @@ -25,6 +26,7 @@ config SH_IS_ASH config SH_IS_HUSH bool "hush" + select SHELL_HUSH help Choose hush to be the shell executed by 'sh' name. The hush code will be built into busybox. If you don't select @@ -57,6 +59,7 @@ choice config BASH_IS_ASH depends on !NOMMU bool "ash" + select SHELL_ASH help Choose ash to be the shell executed by 'bash' name. The ash code will be built into busybox. If you don't select @@ -65,6 +68,7 @@ config BASH_IS_ASH config BASH_IS_HUSH bool "hush" + select SHELL_HUSH help Choose hush to be the shell executed by 'bash' name. The hush code will be built into busybox. If you don't select @@ -81,12 +85,12 @@ INSERT comment "Options common to all shells" -if ASH || HUSH || SH_IS_ASH || BASH_IS_ASH || SH_IS_HUSH || BASH_IS_HUSH +if SHELL_ASH || SHELL_HUSH config FEATURE_SH_MATH bool "POSIX math support" default y - depends on ASH || HUSH || SH_IS_ASH || BASH_IS_ASH || SH_IS_HUSH || BASH_IS_HUSH + depends on SHELL_ASH || SHELL_HUSH help Enable math support in the shell via $((...)) syntax. @@ -107,14 +111,14 @@ config FEATURE_SH_MATH_BASE config FEATURE_SH_EXTRA_QUIET bool "Hide message on interactive shell startup" default y - depends on ASH || HUSH || SH_IS_ASH || BASH_IS_ASH || SH_IS_HUSH || BASH_IS_HUSH + depends on SHELL_ASH || SHELL_HUSH help Remove the busybox introduction when starting a shell. config FEATURE_SH_STANDALONE bool "Standalone shell" default n - depends on ASH || HUSH || SH_IS_ASH || BASH_IS_ASH || SH_IS_HUSH || BASH_IS_HUSH + depends on SHELL_ASH || SHELL_HUSH help This option causes busybox shells to use busybox applets in preference to executables in the PATH whenever possible. For @@ -135,7 +139,7 @@ config FEATURE_SH_STANDALONE config FEATURE_SH_NOFORK bool "Run 'nofork' applets directly" default n - depends on ASH || HUSH || SH_IS_ASH || BASH_IS_ASH || SH_IS_HUSH || BASH_IS_HUSH + depends on SHELL_ASH || SHELL_HUSH help This option causes busybox shells to not execute typical fork/exec/wait sequence, but call _main directly, @@ -153,14 +157,14 @@ config FEATURE_SH_NOFORK config FEATURE_SH_READ_FRAC bool "read -t N.NNN support (+110 bytes)" default y - depends on ASH || HUSH || SH_IS_ASH || BASH_IS_ASH || SH_IS_HUSH || BASH_IS_HUSH + depends on SHELL_ASH || SHELL_HUSH help Enable support for fractional second timeout in read builtin. config FEATURE_SH_HISTFILESIZE bool "Use $HISTFILESIZE" default y - depends on ASH || HUSH || SH_IS_ASH || BASH_IS_ASH || SH_IS_HUSH || BASH_IS_HUSH + depends on SHELL_ASH || SHELL_HUSH help This option makes busybox shells to use $HISTFILESIZE variable to set shell history size. Note that its max value is capped @@ -169,7 +173,7 @@ config FEATURE_SH_HISTFILESIZE config FEATURE_SH_EMBEDDED_SCRIPTS bool "Embed scripts in the binary" default y - depends on ASH || HUSH || SH_IS_ASH || BASH_IS_ASH || SH_IS_HUSH || BASH_IS_HUSH + depends on SHELL_ASH || SHELL_HUSH help Allow scripts to be compressed and embedded in the busybox binary. The scripts should be placed in the 'embed' directory diff --git a/shell/ash.c b/shell/ash.c index 2a4c839a7..ecb9b132b 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -15,10 +15,15 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ +//config:config SHELL_ASH +//config: bool #hidden option +//config: depends on !NOMMU +//config: //config:config ASH //config: bool "ash (78 kb)" //config: default y //config: depends on !NOMMU +//config: select SHELL_ASH //config: help //config: The most complete and most pedantically correct shell included with //config: busybox. This shell is actually a derivative of the Debian 'dash' @@ -28,17 +33,17 @@ //config:# ash options //config:# note: Don't remove !NOMMU part in the next line; it would break //config:# menuconfig's indenting. -//config:if !NOMMU && (ASH || SH_IS_ASH || BASH_IS_ASH) +//config:if !NOMMU && (SHELL_ASH || ASH || SH_IS_ASH || BASH_IS_ASH) //config: //config:config ASH_OPTIMIZE_FOR_SIZE //config: bool "Optimize for size instead of speed" //config: default y -//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH +//config: depends on SHELL_ASH //config: //config:config ASH_INTERNAL_GLOB //config: bool "Use internal glob() implementation" //config: default y # Y is bigger, but because of uclibc glob() bug, let Y be default for now -//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH +//config: depends on SHELL_ASH //config: help //config: Do not use glob() function from libc, use internal implementation. //config: Use this if you are getting "glob.h: No such file or directory" @@ -49,7 +54,7 @@ //config:config ASH_BASH_COMPAT //config: bool "bash-compatible extensions" //config: default y -//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH +//config: depends on SHELL_ASH //config: //config:config ASH_BASH_SOURCE_CURDIR //config: bool "'source' and '.' builtins search current directory after $PATH" @@ -70,17 +75,17 @@ //config:config ASH_JOB_CONTROL //config: bool "Job control" //config: default y -//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH +//config: depends on SHELL_ASH //config: //config:config ASH_ALIAS //config: bool "Alias support" //config: default y -//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH +//config: depends on SHELL_ASH //config: //config:config ASH_RANDOM_SUPPORT //config: bool "Pseudorandom generator and $RANDOM variable" //config: default y -//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH +//config: depends on SHELL_ASH //config: help //config: Enable pseudorandom generator and dynamic variable "$RANDOM". //config: Each read of "$RANDOM" will generate a new pseudorandom value. @@ -91,7 +96,7 @@ //config:config ASH_EXPAND_PRMT //config: bool "Expand prompt string" //config: default y -//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH +//config: depends on SHELL_ASH //config: help //config: $PS# may contain volatile content, such as backquote commands. //config: This option recreates the prompt string from the environment @@ -100,14 +105,14 @@ //config:config ASH_IDLE_TIMEOUT //config: bool "Idle timeout variable $TMOUT" //config: default y -//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH +//config: depends on SHELL_ASH //config: help //config: Enable bash-like auto-logout after $TMOUT seconds of idle time. //config: //config:config ASH_MAIL //config: bool "Check for new mail in interactive shell" //config: default y -//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH +//config: depends on SHELL_ASH //config: help //config: Enable "check for new mail" function: //config: if set, $MAIL file and $MAILPATH list of files @@ -117,32 +122,32 @@ //config:config ASH_ECHO //config: bool "echo builtin" //config: default y -//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH +//config: depends on SHELL_ASH //config: //config:config ASH_PRINTF //config: bool "printf builtin" //config: default y -//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH +//config: depends on SHELL_ASH //config: //config:config ASH_TEST //config: bool "test builtin" //config: default y -//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH +//config: depends on SHELL_ASH //config: //config:config ASH_HELP //config: bool "help builtin" //config: default y -//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH +//config: depends on SHELL_ASH //config: //config:config ASH_GETOPTS //config: bool "getopts builtin" //config: default y -//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH +//config: depends on SHELL_ASH //config: //config:config ASH_CMDCMD //config: bool "command builtin" //config: default y -//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH +//config: depends on SHELL_ASH //config: help //config: Enable support for the 'command' builtin, which allows //config: you to run the specified command or builtin, @@ -155,9 +160,7 @@ //applet:IF_SH_IS_ASH( APPLET_ODDNAME(sh, ash, BB_DIR_BIN, BB_SUID_DROP, ash)) //applet:IF_BASH_IS_ASH(APPLET_ODDNAME(bash, ash, BB_DIR_BIN, BB_SUID_DROP, ash)) -//kbuild:lib-$(CONFIG_ASH) += ash.o ash_ptr_hack.o shell_common.o -//kbuild:lib-$(CONFIG_SH_IS_ASH) += ash.o ash_ptr_hack.o shell_common.o -//kbuild:lib-$(CONFIG_BASH_IS_ASH) += ash.o ash_ptr_hack.o shell_common.o +//kbuild:lib-$(CONFIG_SHELL_ASH) += ash.o ash_ptr_hack.o shell_common.o //kbuild:lib-$(CONFIG_ASH_RANDOM_SUPPORT) += random.o /* diff --git a/shell/hush.c b/shell/hush.c index 2cf2170ca..e9cec1cc9 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -95,6 +95,7 @@ //config:config HUSH //config: bool "hush (68 kb)" //config: default y +//config: select SHELL_HUSH //config: help //config: hush is a small shell. It handles the normal flow control //config: constructs such as if/then/elif/else/fi, for/in/do/done, while loops, @@ -106,10 +107,20 @@ //config: It does not handle select, aliases, tilde expansion, //config: &>file and >&file redirection of stdout+stderr. //config: +// This option is visible (has a description) to make it possible to select +// a "scripted" applet (such as NOLOGIN) but avoid selecting any shells: +//config:config SHELL_HUSH +//config: bool "Internal shell for embedded script support" +//config: default n +//config: +//config:# hush options +//config:# It's only needed to get "nice" menuconfig indenting. +//config:if SHELL_HUSH || HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: //config:config HUSH_BASH_COMPAT //config: bool "bash-compatible extensions" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: //config:config HUSH_BRACE_EXPANSION //config: bool "Brace expansion" @@ -133,7 +144,7 @@ //config:config HUSH_INTERACTIVE //config: bool "Interactive mode" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: help //config: Enable interactive mode (prompt and command editing). //config: Without this, hush simply reads and executes commands @@ -159,31 +170,31 @@ //config:config HUSH_TICK //config: bool "Support command substitution" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: help //config: Enable `command` and $(command). //config: //config:config HUSH_IF //config: bool "Support if/then/elif/else/fi" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: //config:config HUSH_LOOPS //config: bool "Support for, while and until loops" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: //config:config HUSH_CASE //config: bool "Support case ... esac statement" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: help //config: Enable case ... esac statement. +400 bytes. //config: //config:config HUSH_FUNCTIONS //config: bool "Support funcname() { commands; } syntax" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: help //config: Enable support for shell functions. +800 bytes. //config: @@ -197,7 +208,7 @@ //config:config HUSH_RANDOM_SUPPORT //config: bool "Pseudorandom generator and $RANDOM variable" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: help //config: Enable pseudorandom generator and dynamic variable "$RANDOM". //config: Each read of "$RANDOM" will generate a new pseudorandom value. @@ -205,7 +216,7 @@ //config:config HUSH_MODE_X //config: bool "Support 'hush -x' option and 'set -x' command" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: help //config: This instructs hush to print commands before execution. //config: Adds ~300 bytes. @@ -213,27 +224,27 @@ //config:config HUSH_ECHO //config: bool "echo builtin" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: //config:config HUSH_PRINTF //config: bool "printf builtin" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: //config:config HUSH_TEST //config: bool "test builtin" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: //config:config HUSH_HELP //config: bool "help builtin" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: //config:config HUSH_EXPORT //config: bool "export builtin" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: //config:config HUSH_EXPORT_N //config: bool "Support 'export -n' option" @@ -245,83 +256,83 @@ //config:config HUSH_READONLY //config: bool "readonly builtin" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: help //config: Enable support for read-only variables. //config: //config:config HUSH_KILL //config: bool "kill builtin (supports kill %jobspec)" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: //config:config HUSH_WAIT //config: bool "wait builtin" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: //config:config HUSH_COMMAND //config: bool "command builtin" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: //config:config HUSH_TRAP //config: bool "trap builtin" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: //config:config HUSH_TYPE //config: bool "type builtin" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: //config:config HUSH_TIMES //config: bool "times builtin" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: //config:config HUSH_READ //config: bool "read builtin" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: //config:config HUSH_SET //config: bool "set builtin" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: //config:config HUSH_UNSET //config: bool "unset builtin" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: //config:config HUSH_ULIMIT //config: bool "ulimit builtin" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: //config:config HUSH_UMASK //config: bool "umask builtin" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: //config:config HUSH_GETOPTS //config: bool "getopts builtin" //config: default y -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH //config: //config:config HUSH_MEMLEAK //config: bool "memleak builtin (debugging)" //config: default n -//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH +//config: depends on SHELL_HUSH +//config: +//config:endif # hush options //applet:IF_HUSH(APPLET(hush, BB_DIR_BIN, BB_SUID_DROP)) // APPLET_ODDNAME:name main location suid_type help //applet:IF_SH_IS_HUSH( APPLET_ODDNAME(sh, hush, BB_DIR_BIN, BB_SUID_DROP, hush)) //applet:IF_BASH_IS_HUSH(APPLET_ODDNAME(bash, hush, BB_DIR_BIN, BB_SUID_DROP, hush)) -//kbuild:lib-$(CONFIG_HUSH) += hush.o match.o shell_common.o -//kbuild:lib-$(CONFIG_SH_IS_HUSH) += hush.o match.o shell_common.o -//kbuild:lib-$(CONFIG_BASH_IS_HUSH) += hush.o match.o shell_common.o +//kbuild:lib-$(CONFIG_SHELL_HUSH) += hush.o match.o shell_common.o //kbuild:lib-$(CONFIG_HUSH_RANDOM_SUPPORT) += random.o /* -i (interactive) is also accepted, diff --git a/util-linux/nologin.c b/util-linux/nologin.c index 5e5e42305..5a8b047a5 100644 --- a/util-linux/nologin.c +++ b/util-linux/nologin.c @@ -7,7 +7,7 @@ //config: //config:config NOLOGIN_DEPENDENCIES //config: bool "Enable dependencies for nologin" -//config: default y +//config: default n # Y default makes it harder to select single-applet test //config: depends on NOLOGIN //config: select CAT //config: select ECHO -- cgit v1.2.3-55-g6feb From ac79db6a3b8c9d1815dc4f506d55bc6a2a4e34dd Mon Sep 17 00:00:00 2001 From: Martin Lewis Date: Thu, 11 Jun 2020 15:45:57 -0500 Subject: procps: code shrink function old new delta skip_whitespace_if_prefixed_with - 17 +17 procps_read_smaps 911 854 -57 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/1 up/down: 17/-57) Total: -40 bytes Signed-off-by: Martin Lewis Signed-off-by: Denys Vlasenko --- libbb/procps.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'libbb') diff --git a/libbb/procps.c b/libbb/procps.c index af3ad86ff..4cc3cb2a1 100644 --- a/libbb/procps.c +++ b/libbb/procps.c @@ -177,6 +177,15 @@ static char *skip_fields(char *str, int count) } #endif +static char* skip_whitespace_if_prefixed_with(char *buf, const char *prefix) +{ + char *tp = is_prefixed_with(buf, prefix); + if (tp) { + tp = skip_whitespace(tp); + } + return tp; +} + #if ENABLE_FEATURE_TOPMEM || ENABLE_PMAP int FAST_FUNC procps_read_smaps(pid_t pid, struct smaprec *total, void (*cb)(struct smaprec *, void *), void *data) @@ -207,8 +216,7 @@ int FAST_FUNC procps_read_smaps(pid_t pid, struct smaprec *total, char *tp, *p; #define SCAN(S, X) \ - if ((tp = is_prefixed_with(buf, S)) != NULL) { \ - tp = skip_whitespace(tp); \ + if ((tp = skip_whitespace_if_prefixed_with(buf, S)) != NULL) { \ total->X += currec.X = fast_strtoul_10(&tp); \ continue; \ } -- cgit v1.2.3-55-g6feb From c9fc15359ef8fe5aa98ab0308c1563d9bcf99bb8 Mon Sep 17 00:00:00 2001 From: Martin Lewis Date: Thu, 11 Jun 2020 15:45:58 -0500 Subject: compare_string_array: code shrink Code shrink and prevention of possible out of bounds access. function old new delta nth_string 36 26 -10 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-10) Total: -10 bytes text data bss dec hex filename 981342 16915 1872 1000129 f42c1 busybox_old 981332 16915 1872 1000119 f42b7 busybox_unstripped Signed-off-by: Martin Lewis Signed-off-by: Denys Vlasenko --- libbb/compare_string_array.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'libbb') diff --git a/libbb/compare_string_array.c b/libbb/compare_string_array.c index 01a9df0e2..a06e57d3d 100644 --- a/libbb/compare_string_array.c +++ b/libbb/compare_string_array.c @@ -117,8 +117,11 @@ int FAST_FUNC index_in_substrings(const char *strings, const char *key) const char* FAST_FUNC nth_string(const char *strings, int n) { while (n) { - n--; - strings += strlen(strings) + 1; + if (*strings++ == '\0') { + if (*strings == '\0') /* reached end of strings */ + break; + n--; + } } return strings; } -- cgit v1.2.3-55-g6feb From d21a63f9fca8eb16f79de9b72d4a3484dfaec1fc Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 30 Jun 2020 08:33:02 +0200 Subject: libbb: code shrink in last_char_is() Signed-off-by: Denys Vlasenko --- libbb/last_char_is.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'libbb') diff --git a/libbb/last_char_is.c b/libbb/last_char_is.c index 66f2e3635..918526e6c 100644 --- a/libbb/last_char_is.c +++ b/libbb/last_char_is.c @@ -8,16 +8,17 @@ */ #include "libbb.h" -/* Find out if the last character of a string matches the one given. - * Don't underrun the buffer if the string length is 0. - */ +/* Find out if the last character of a string matches the one given */ char* FAST_FUNC last_char_is(const char *s, int c) { - if (s && *s) { - size_t sz = strlen(s) - 1; - s += sz; - if ( (unsigned char)*s == c) - return (char*)s; + if (s) { + size_t sz = strlen(s); + /* Don't underrun the buffer if the string length is 0 */ + if (sz != 0) { + s += sz - 1; + if ((unsigned char)*s == c) + return (char*)s; + } } return NULL; } -- cgit v1.2.3-55-g6feb