diff options
author | Cem Keylan <cem@ckyln.com> | 2021-03-09 08:43:43 +0300 |
---|---|---|
committer | Cem Keylan <cem@ckyln.com> | 2021-03-09 08:43:43 +0300 |
commit | 7ccc9c2432a847b85da5f445977d09f014cbc75b (patch) | |
tree | 8067d45ebeea60f1ddaa8167cb1398e2b6631473 /libbb | |
parent | fef526c380e35cbdc0bdb8375487756c42659a75 (diff) | |
parent | 307cd26e9893ed0cf6ee88e7fca2d61d3da0e139 (diff) | |
download | busybox-master.tar.gz |
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/appletlib.c | 29 | ||||
-rw-r--r-- | libbb/lineedit.c | 10 | ||||
-rw-r--r-- | libbb/platform.c | 12 | ||||
-rw-r--r-- | libbb/vfork_daemon_rexec.c | 5 |
4 files changed, 40 insertions, 16 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c index 542211255..67c540abb 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c @@ -905,16 +905,8 @@ int busybox_main(int argc UNUSED_PARAM, char **argv) # endif # if NUM_APPLETS > 0 -void FAST_FUNC run_applet_no_and_exit(int applet_no, const char *name, char **argv) +void FAST_FUNC show_usage_if_dash_dash_help(int applet_no, char **argv) { - int argc = string_array_len(argv); - - /* - * We do not use argv[0]: do not want to repeat massaging of - * "-/sbin/halt" -> "halt", for example. - */ - applet_name = name; - /* Special case. POSIX says "test --help" * should be no different from e.g. "test --foo". * Thus for "test", we skip --help check. @@ -931,15 +923,32 @@ void FAST_FUNC run_applet_no_and_exit(int applet_no, const char *name, char **ar && applet_no != APPLET_NO_false # endif ) { - if (argc == 2 && strcmp(argv[1], "--help") == 0) { + if (argv[1] && !argv[2] && strcmp(argv[1], "--help") == 0) { /* Make "foo --help" exit with 0: */ xfunc_error_retval = 0; bb_show_usage(); } } +} + +void FAST_FUNC run_applet_no_and_exit(int applet_no, const char *name, char **argv) +{ + int argc; + + /* + * We do not use argv[0]: do not want to repeat massaging of + * "-/sbin/halt" -> "halt", for example. + */ + applet_name = name; + + show_usage_if_dash_dash_help(applet_no, argv); + if (ENABLE_FEATURE_SUID) check_suid(applet_no); + + argc = string_array_len(argv); xfunc_error_retval = applet_main[applet_no](argc, argv); + /* Note: applet_main() may also not return (die on a xfunc or such) */ xfunc_die(); } diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 367396b91..b0adcf140 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -769,8 +769,6 @@ static unsigned path_parse(char ***p) if (!tmp) break; tmp++; - if (*tmp == '\0') - break; /* :<empty> */ npth++; } @@ -782,8 +780,6 @@ static unsigned path_parse(char ***p) if (!tmp) break; *tmp++ = '\0'; /* ':' -> '\0' */ - if (*tmp == '\0') - break; /* :<empty> */ res[npth++] = tmp; } /* special case: "match subdirectories of the current directory" */ @@ -854,6 +850,7 @@ static NOINLINE unsigned complete_cmd_dir_file(const char *command, int type) struct dirent *next; struct stat st; char *found; + const char *lpath; if (paths[i] == NULL) { /* path_parse()'s last component? */ /* in PATH completion, current dir's subdir names @@ -863,7 +860,8 @@ static NOINLINE unsigned complete_cmd_dir_file(const char *command, int type) paths[i] = (char *)"."; } - dir = opendir(paths[i]); + lpath = *paths[i] ? paths[i] : "."; + dir = opendir(lpath); if (!dir) continue; /* don't print an error */ @@ -878,7 +876,7 @@ static NOINLINE unsigned complete_cmd_dir_file(const char *command, int type) if (strncmp(basecmd, name_found, baselen) != 0) continue; /* no */ - found = concat_path_file(paths[i], name_found); + found = concat_path_file(lpath, name_found); /* NB: stat() first so that we see is it a directory; * but if that fails, use lstat() so that * we still match dangling links */ diff --git a/libbb/platform.c b/libbb/platform.c index 329b0237e..7913353e2 100644 --- a/libbb/platform.c +++ b/libbb/platform.c @@ -166,6 +166,18 @@ char* FAST_FUNC stpcpy(char *p, const char *to_add) } #endif +#ifndef HAVE_STPNCPY +char* FAST_FUNC stpncpy(char *p, const char *to_add, size_t n) +{ + while (n != 0 && (*p = *to_add) != '\0') { + p++; + to_add++; + n--; + } + return p; +} +#endif + #ifndef HAVE_GETLINE ssize_t FAST_FUNC getline(char **lineptr, size_t *n, FILE *stream) { diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c index 65271e84f..a49fe8e01 100644 --- a/libbb/vfork_daemon_rexec.c +++ b/libbb/vfork_daemon_rexec.c @@ -109,8 +109,13 @@ int FAST_FUNC run_nofork_applet(int applet_no, char **argv) char *tmp_argv[argc+1]; memcpy(tmp_argv, argv, (argc+1) * sizeof(tmp_argv[0])); applet_name = tmp_argv[0]; + + /* longjmp's (instead of returning) if --help is seen */ + show_usage_if_dash_dash_help(applet_no, argv); + /* Finally we can call NOFORK applet's main() */ rc = applet_main[applet_no](argc, tmp_argv); + /* Important for shells: `which CMD` was failing */ fflush_all(); } else { |