aboutsummaryrefslogtreecommitdiff
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-18 19:20:58 +0200
commit442d522f0bc6f29c14a3e54a0af3aac68bb891a1 (patch)
treeaa36853bf59cf4b3d4808d391ab31a714c3fc28c
parentceaffde51163394c47fec34dac8663ae8152a699 (diff)
downloadbusybox-w32-442d522f0bc6f29c14a3e54a0af3aac68bb891a1.tar.gz
busybox-w32-442d522f0bc6f29c14a3e54a0af3aac68bb891a1.tar.bz2
busybox-w32-442d522f0bc6f29c14a3e54a0af3aac68bb891a1.zip
fixes for bugs found by make_single_applets.sh
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--archival/bbunzip.c11
-rw-r--r--include/libbb.h2
-rw-r--r--libbb/appletlib.c20
-rw-r--r--libbb/getopt32.c4
-rw-r--r--libbb/vfork_daemon_rexec.c3
-rw-r--r--networking/inetd.c17
-rwxr-xr-xscripts/randomtest.loop26
-rw-r--r--shell/hush.c26
-rw-r--r--shell/shell_common.c4
-rw-r--r--util-linux/fdisk.c3
10 files changed, 75 insertions, 41 deletions
diff --git a/archival/bbunzip.c b/archival/bbunzip.c
index c60f6e6df..f7a7ab354 100644
--- a/archival/bbunzip.c
+++ b/archival/bbunzip.c
@@ -7,14 +7,19 @@
7#include "libbb.h" 7#include "libbb.h"
8#include "bb_archive.h" 8#include "bb_archive.h"
9 9
10//kbuild:lib-$(CONFIG_ZCAT) += bbunzip.o
11//kbuild:lib-$(CONFIG_GUNZIP) += bbunzip.o
12//kbuild:lib-$(CONFIG_BZCAT) += bbunzip.o
13//kbuild:lib-$(CONFIG_BUNZIP2) += bbunzip.o
14
10/* lzop_main() uses bbunpack(), need this: */ 15/* lzop_main() uses bbunpack(), need this: */
11//kbuild:lib-$(CONFIG_LZOP) += bbunzip.o 16//kbuild:lib-$(CONFIG_LZOP) += bbunzip.o
12//kbuild:lib-$(CONFIG_LZOPCAT) += bbunzip.o 17//kbuild:lib-$(CONFIG_LZOPCAT) += bbunzip.o
13//kbuild:lib-$(CONFIG_UNLZOP) += bbunzip.o 18//kbuild:lib-$(CONFIG_UNLZOP) += bbunzip.o
14/* bzip2_main() too: */ 19/* bzip2_main() too: */
15//kbuild:lib-$(CONFIG_FEATURE_BZIP2_DECOMPRESS) += bbunzip.o 20//kbuild:lib-$(CONFIG_BZIP2) += bbunzip.o
16/* gzip_main() too: */ 21/* gzip_main() too: */
17//kbuild:lib-$(CONFIG_FEATURE_GZIP_DECOMPRESS) += bbunzip.o 22//kbuild:lib-$(CONFIG_GZIP) += bbunzip.o
18 23
19/* Note: must be kept in sync with archival/lzop.c */ 24/* Note: must be kept in sync with archival/lzop.c */
20enum { 25enum {
@@ -443,7 +448,7 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
443//applet:IF_BUNZIP2(APPLET(bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP)) 448//applet:IF_BUNZIP2(APPLET(bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP))
444// APPLET_ODDNAME:name main location suid_type help 449// APPLET_ODDNAME:name main location suid_type help
445//applet:IF_BZCAT(APPLET_ODDNAME(bzcat, bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP, bzcat)) 450//applet:IF_BZCAT(APPLET_ODDNAME(bzcat, bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP, bzcat))
446#if ENABLE_FEATURE_BZIP2_DECOMPRESS 451#if ENABLE_FEATURE_BZIP2_DECOMPRESS || ENABLE_BUNZIP2
447int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 452int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
448int bunzip2_main(int argc UNUSED_PARAM, char **argv) 453int bunzip2_main(int argc UNUSED_PARAM, char **argv)
449{ 454{
diff --git a/include/libbb.h b/include/libbb.h
index 9b72c97be..557978e66 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -778,6 +778,8 @@ ssize_t recv_from_to(int fd, void *buf, size_t len, int flags,
778 778
779uint16_t inet_cksum(uint16_t *addr, int len) FAST_FUNC; 779uint16_t inet_cksum(uint16_t *addr, int len) FAST_FUNC;
780 780
781/* 0 if argv[0] is NULL: */
782unsigned string_array_len(char **argv) FAST_FUNC;
781void overlapping_strcpy(char *dst, const char *src) FAST_FUNC; 783void overlapping_strcpy(char *dst, const char *src) FAST_FUNC;
782char *safe_strncpy(char *dst, const char *src, size_t size) FAST_FUNC; 784char *safe_strncpy(char *dst, const char *src, size_t size) FAST_FUNC;
783char *strncpy_IFNAMSIZ(char *dst, const char *src) FAST_FUNC; 785char *strncpy_IFNAMSIZ(char *dst, const char *src) FAST_FUNC;
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) {
diff --git a/networking/inetd.c b/networking/inetd.c
index 01e659f13..39169a935 100644
--- a/networking/inetd.c
+++ b/networking/inetd.c
@@ -1513,8 +1513,11 @@ int inetd_main(int argc UNUSED_PARAM, char **argv)
1513 } /* for (;;) */ 1513 } /* for (;;) */
1514} 1514}
1515 1515
1516#if !BB_MMU 1516#if ENABLE_FEATURE_INETD_SUPPORT_BUILTIN_ECHO \
1517 || ENABLE_FEATURE_INETD_SUPPORT_BUILTIN_DISCARD
1518# if !BB_MMU
1517static const char *const cat_args[] = { "cat", NULL }; 1519static const char *const cat_args[] = { "cat", NULL };
1520# endif
1518#endif 1521#endif
1519 1522
1520/* 1523/*
@@ -1525,14 +1528,14 @@ static const char *const cat_args[] = { "cat", NULL };
1525/* ARGSUSED */ 1528/* ARGSUSED */
1526static void FAST_FUNC echo_stream(int s, servtab_t *sep UNUSED_PARAM) 1529static void FAST_FUNC echo_stream(int s, servtab_t *sep UNUSED_PARAM)
1527{ 1530{
1528#if BB_MMU 1531# if BB_MMU
1529 while (1) { 1532 while (1) {
1530 ssize_t sz = safe_read(s, line, LINE_SIZE); 1533 ssize_t sz = safe_read(s, line, LINE_SIZE);
1531 if (sz <= 0) 1534 if (sz <= 0)
1532 break; 1535 break;
1533 xwrite(s, line, sz); 1536 xwrite(s, line, sz);
1534 } 1537 }
1535#else 1538# else
1536 /* We are after vfork here! */ 1539 /* We are after vfork here! */
1537 /* move network socket to stdin/stdout */ 1540 /* move network socket to stdin/stdout */
1538 xmove_fd(s, STDIN_FILENO); 1541 xmove_fd(s, STDIN_FILENO);
@@ -1542,7 +1545,7 @@ static void FAST_FUNC echo_stream(int s, servtab_t *sep UNUSED_PARAM)
1542 xopen(bb_dev_null, O_WRONLY); 1545 xopen(bb_dev_null, O_WRONLY);
1543 BB_EXECVP("cat", (char**)cat_args); 1546 BB_EXECVP("cat", (char**)cat_args);
1544 /* on failure we return to main, which does exit(EXIT_FAILURE) */ 1547 /* on failure we return to main, which does exit(EXIT_FAILURE) */
1545#endif 1548# endif
1546} 1549}
1547static void FAST_FUNC echo_dg(int s, servtab_t *sep) 1550static void FAST_FUNC echo_dg(int s, servtab_t *sep)
1548{ 1551{
@@ -1566,10 +1569,10 @@ static void FAST_FUNC echo_dg(int s, servtab_t *sep)
1566/* ARGSUSED */ 1569/* ARGSUSED */
1567static void FAST_FUNC discard_stream(int s, servtab_t *sep UNUSED_PARAM) 1570static void FAST_FUNC discard_stream(int s, servtab_t *sep UNUSED_PARAM)
1568{ 1571{
1569#if BB_MMU 1572# if BB_MMU
1570 while (safe_read(s, line, LINE_SIZE) > 0) 1573 while (safe_read(s, line, LINE_SIZE) > 0)
1571 continue; 1574 continue;
1572#else 1575# else
1573 /* We are after vfork here! */ 1576 /* We are after vfork here! */
1574 /* move network socket to stdin */ 1577 /* move network socket to stdin */
1575 xmove_fd(s, STDIN_FILENO); 1578 xmove_fd(s, STDIN_FILENO);
@@ -1580,7 +1583,7 @@ static void FAST_FUNC discard_stream(int s, servtab_t *sep UNUSED_PARAM)
1580 xdup2(STDOUT_FILENO, STDERR_FILENO); 1583 xdup2(STDOUT_FILENO, STDERR_FILENO);
1581 BB_EXECVP("cat", (char**)cat_args); 1584 BB_EXECVP("cat", (char**)cat_args);
1582 /* on failure we return to main, which does exit(EXIT_FAILURE) */ 1585 /* on failure we return to main, which does exit(EXIT_FAILURE) */
1583#endif 1586# endif
1584} 1587}
1585/* ARGSUSED */ 1588/* ARGSUSED */
1586static void FAST_FUNC discard_dg(int s, servtab_t *sep UNUSED_PARAM) 1589static void FAST_FUNC discard_dg(int s, servtab_t *sep UNUSED_PARAM)
diff --git a/scripts/randomtest.loop b/scripts/randomtest.loop
index 710f5fd05..4d14b652f 100755
--- a/scripts/randomtest.loop
+++ b/scripts/randomtest.loop
@@ -1,7 +1,11 @@
1#!/bin/sh 1#!/bin/sh
2 2
3run_testsuite=false
3run_testsuite=true 4run_testsuite=true
4 5
6run_single_test=false
7run_single_test=true
8
5test -d "$1" || { echo "'$1' is not a directory"; exit 1; } 9test -d "$1" || { echo "'$1' is not a directory"; exit 1; }
6test -x "$1/scripts/randomtest" || { echo "No scripts/randomtest in '$1'"; exit 1; } 10test -x "$1/scripts/randomtest" || { echo "No scripts/randomtest in '$1'"; exit 1; }
7 11
@@ -40,6 +44,28 @@ while sleep 1; do
40 fi 44 fi
41 tail -n10 -- "$dir/testsuite/runtest.log" 45 tail -n10 -- "$dir/testsuite/runtest.log"
42 fi 46 fi
47 if $run_single_test; then
48 (
49 cd -- "$dir" || exit 1
50 echo "Running make_single_applets.sh in $dir..."
51
52 if grep -q '# CONFIG_FEATURE_TFTP_GET is not set' .config \
53 && grep -q '# CONFIG_FEATURE_TFTP_PUT is not set' .config \
54 ; then
55 # If both off, tftp[d] is ifdefed out and test fails.
56 # Enable one:
57 sed 's/# CONFIG_FEATURE_TFTP_GET is not set/CONFIG_FEATURE_TFTP_GET=y/' -i .config
58 fi
59
60 ./make_single_applets.sh
61 )
62 if test $? != 0; then
63 echo "Failed make_single_applets.sh in $dir"
64 exit 1 # you may comment this out...
65 let fail++
66 continue
67 fi
68 fi
43 rm -rf -- "$dir" 69 rm -rf -- "$dir"
44 let cnt++ 70 let cnt++
45done 71done
diff --git a/shell/hush.c b/shell/hush.c
index f5c1e5bc1..db8ca4f97 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -1486,8 +1486,6 @@ typedef struct save_arg_t {
1486 1486
1487static void save_and_replace_G_args(save_arg_t *sv, char **argv) 1487static void save_and_replace_G_args(save_arg_t *sv, char **argv)
1488{ 1488{
1489 int n;
1490
1491 sv->sv_argv0 = argv[0]; 1489 sv->sv_argv0 = argv[0];
1492 sv->sv_g_argv = G.global_argv; 1490 sv->sv_g_argv = G.global_argv;
1493 sv->sv_g_argc = G.global_argc; 1491 sv->sv_g_argc = G.global_argc;
@@ -1497,10 +1495,7 @@ static void save_and_replace_G_args(save_arg_t *sv, char **argv)
1497 G.global_argv = argv; 1495 G.global_argv = argv;
1498 IF_HUSH_SET(G.global_args_malloced = 0;) 1496 IF_HUSH_SET(G.global_args_malloced = 0;)
1499 1497
1500 n = 1; 1498 G.global_argc = 1 + string_array_len(argv + 1);
1501 while (*++argv)
1502 n++;
1503 G.global_argc = n;
1504} 1499}
1505 1500
1506static void restore_G_args(save_arg_t *sv, char **argv) 1501static void restore_G_args(save_arg_t *sv, char **argv)
@@ -6817,13 +6812,11 @@ static void exec_function(char ***to_free,
6817 char **argv) 6812 char **argv)
6818{ 6813{
6819# if BB_MMU 6814# if BB_MMU
6820 int n = 1; 6815 int n;
6821 6816
6822 argv[0] = G.global_argv[0]; 6817 argv[0] = G.global_argv[0];
6823 G.global_argv = argv; 6818 G.global_argv = argv;
6824 while (*++argv) 6819 G.global_argc = n = 1 + string_array_len(argv + 1);
6825 n++;
6826 G.global_argc = n;
6827 /* On MMU, funcp->body is always non-NULL */ 6820 /* On MMU, funcp->body is always non-NULL */
6828 n = run_list(funcp->body); 6821 n = run_list(funcp->body);
6829 fflush_all(); 6822 fflush_all();
@@ -8829,12 +8822,8 @@ static int FAST_FUNC builtin_true(char **argv UNUSED_PARAM)
8829#if ENABLE_HUSH_TEST || ENABLE_HUSH_ECHO || ENABLE_HUSH_PRINTF || ENABLE_HUSH_KILL 8822#if ENABLE_HUSH_TEST || ENABLE_HUSH_ECHO || ENABLE_HUSH_PRINTF || ENABLE_HUSH_KILL
8830static int run_applet_main(char **argv, int (*applet_main_func)(int argc, char **argv)) 8823static int run_applet_main(char **argv, int (*applet_main_func)(int argc, char **argv))
8831{ 8824{
8832 int argc = 0; 8825 int argc = string_array_len(argv);
8833 while (*argv) { 8826 return applet_main_func(argc, argv);
8834 argc++;
8835 argv++;
8836 }
8837 return applet_main_func(argc, argv - argc);
8838} 8827}
8839#endif 8828#endif
8840#if ENABLE_HUSH_TEST || BASH_TEST2 8829#if ENABLE_HUSH_TEST || BASH_TEST2
@@ -9381,10 +9370,7 @@ static int FAST_FUNC builtin_set(char **argv)
9381 /* This realloc's G.global_argv */ 9370 /* This realloc's G.global_argv */
9382 G.global_argv = pp = add_strings_to_strings(g_argv, argv, /*dup:*/ 1); 9371 G.global_argv = pp = add_strings_to_strings(g_argv, argv, /*dup:*/ 1);
9383 9372
9384 n = 1; 9373 G.global_argc = 1 + string_array_len(pp + 1);
9385 while (*++pp)
9386 n++;
9387 G.global_argc = n;
9388 9374
9389 return EXIT_SUCCESS; 9375 return EXIT_SUCCESS;
9390 9376
diff --git a/shell/shell_common.c b/shell/shell_common.c
index 03b7d0b75..bf56f3d78 100644
--- a/shell/shell_common.c
+++ b/shell/shell_common.c
@@ -405,9 +405,7 @@ shell_builtin_ulimit(char **argv)
405 */ 405 */
406 GETOPT_RESET(); 406 GETOPT_RESET();
407 407
408 argc = 1; 408 argc = string_array_len(argv);
409 while (argv[argc])
410 argc++;
411 409
412 opts = 0; 410 opts = 0;
413 while (1) { 411 while (1) {
diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c
index 916d4e30e..4467525c7 100644
--- a/util-linux/fdisk.c
+++ b/util-linux/fdisk.c
@@ -185,6 +185,8 @@ struct hd_geometry {
185 185
186#define HDIO_GETGEO 0x0301 /* get device geometry */ 186#define HDIO_GETGEO 0x0301 /* get device geometry */
187 187
188/* TODO: #if ENABLE_FEATURE_FDISK_WRITABLE */
189/* (currently fdisk_sun/sgi.c do not have proper WRITABLE #ifs) */
188static const char msg_building_new_label[] ALIGN1 = 190static const char msg_building_new_label[] ALIGN1 =
189"Building a new %s. Changes will remain in memory only,\n" 191"Building a new %s. Changes will remain in memory only,\n"
190"until you decide to write them. After that the previous content\n" 192"until you decide to write them. After that the previous content\n"
@@ -192,6 +194,7 @@ static const char msg_building_new_label[] ALIGN1 =
192 194
193static const char msg_part_already_defined[] ALIGN1 = 195static const char msg_part_already_defined[] ALIGN1 =
194"Partition %u is already defined, delete it before re-adding\n"; 196"Partition %u is already defined, delete it before re-adding\n";
197/* #endif */
195 198
196 199
197struct partition { 200struct partition {