aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-07-03 21:31:16 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-07-03 21:31:16 +0200
commitd4e4fdb5ce5ccc067b3d35d877f7a7d978869517 (patch)
treebac3e4a55fa72db0c67d377b90869b4d63e8c3c9 /libbb
parent2e989ef232e35750df573898077dd356003705b2 (diff)
downloadbusybox-w32-d4e4fdb5ce5ccc067b3d35d877f7a7d978869517.tar.gz
busybox-w32-d4e4fdb5ce5ccc067b3d35d877f7a7d978869517.tar.bz2
busybox-w32-d4e4fdb5ce5ccc067b3d35d877f7a7d978869517.zip
fixes for bugs found by make_single_applets.sh
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r--libbb/appletlib.c20
-rw-r--r--libbb/getopt32.c4
-rw-r--r--libbb/vfork_daemon_rexec.c3
3 files changed, 19 insertions, 8 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index 7f0d62060..2dea2b43a 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -78,6 +78,17 @@
78#endif 78#endif
79 79
80 80
81unsigned FAST_FUNC string_array_len(char **argv)
82{
83 char **start = argv;
84
85 while (*argv)
86 argv++;
87
88 return argv - start;
89}
90
91
81#if ENABLE_SHOW_USAGE && !ENABLE_FEATURE_COMPRESS_USAGE 92#if ENABLE_SHOW_USAGE && !ENABLE_FEATURE_COMPRESS_USAGE
82static const char usage_messages[] ALIGN1 = UNPACKED_USAGE; 93static const char usage_messages[] ALIGN1 = UNPACKED_USAGE;
83#else 94#else
@@ -868,10 +879,7 @@ static int busybox_main(char **argv)
868# if NUM_APPLETS > 0 879# if NUM_APPLETS > 0
869void FAST_FUNC run_applet_no_and_exit(int applet_no, char **argv) 880void FAST_FUNC run_applet_no_and_exit(int applet_no, char **argv)
870{ 881{
871 int argc = 1; 882 int argc = string_array_len(argv);
872
873 while (argv[argc])
874 argc++;
875 883
876 /* Reinit some shared global data */ 884 /* Reinit some shared global data */
877 xfunc_error_retval = EXIT_FAILURE; 885 xfunc_error_retval = EXIT_FAILURE;
@@ -993,7 +1001,11 @@ int main(int argc UNUSED_PARAM, char **argv)
993 } 1001 }
994 /* applet_names in this case is just "applet\0\0" */ 1002 /* applet_names in this case is just "applet\0\0" */
995 lbb_prepare(applet_names IF_FEATURE_INDIVIDUAL(, argv)); 1003 lbb_prepare(applet_names IF_FEATURE_INDIVIDUAL(, argv));
1004# if ENABLE_BUILD_LIBBUSYBOX
1005 return SINGLE_APPLET_MAIN(string_array_len(argv), argv);
1006# else
996 return SINGLE_APPLET_MAIN(argc, argv); 1007 return SINGLE_APPLET_MAIN(argc, argv);
1008# endif
997 1009
998#elif !ENABLE_BUSYBOX && NUM_APPLETS == 0 1010#elif !ENABLE_BUSYBOX && NUM_APPLETS == 0
999 1011
diff --git a/libbb/getopt32.c b/libbb/getopt32.c
index b87b83538..80f4cc060 100644
--- a/libbb/getopt32.c
+++ b/libbb/getopt32.c
@@ -379,9 +379,7 @@ getopt32(char **argv, const char *applet_opts, ...)
379 int spec_flgs = 0; 379 int spec_flgs = 0;
380 380
381 /* skip 0: some applets cheat: they do not actually HAVE argv[0] */ 381 /* skip 0: some applets cheat: they do not actually HAVE argv[0] */
382 argc = 1; 382 argc = 1 + string_array_len(argv + 1);
383 while (argv[argc])
384 argc++;
385 383
386 va_start(p, applet_opts); 384 va_start(p, applet_opts);
387 385
diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c
index fd481bf6e..2695f99ee 100644
--- a/libbb/vfork_daemon_rexec.c
+++ b/libbb/vfork_daemon_rexec.c
@@ -16,6 +16,7 @@
16 */ 16 */
17 17
18#include "busybox.h" /* uses applet tables */ 18#include "busybox.h" /* uses applet tables */
19#include "NUM_APPLETS.h"
19 20
20/* This does a fork/exec in one call, using vfork(). Returns PID of new child, 21/* This does a fork/exec in one call, using vfork(). Returns PID of new child,
21 * -1 for failure. Runs argv[0], searching path if that has no / in it. */ 22 * -1 for failure. Runs argv[0], searching path if that has no / in it. */
@@ -156,7 +157,7 @@ int FAST_FUNC run_nofork_applet(int applet_no, char **argv)
156int FAST_FUNC spawn_and_wait(char **argv) 157int FAST_FUNC spawn_and_wait(char **argv)
157{ 158{
158 int rc; 159 int rc;
159#if ENABLE_FEATURE_PREFER_APPLETS 160#if ENABLE_FEATURE_PREFER_APPLETS && (NUM_APPLETS > 1)
160 int a = find_applet_by_name(argv[0]); 161 int a = find_applet_by_name(argv[0]);
161 162
162 if (a >= 0) { 163 if (a >= 0) {