Compare commits

...
25 Commits
Author SHA1 Message Date
Denys Vlasenko 81e26c4b8e Bump version to 1.27.2
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-17 12:58:27 +02:00
Denys Vlasenko 0b16a67959 svc: fix a case where with more than option, getopt() state is not reset
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-05 01:40:12 +02:00
Natanael Copa 4989d05174 unzip: fix regression on big-endian machines
This fixes a regression which was introduced with commit 2a0867a5
("unzip: optional support for bzip2 and lzma") and causes unzip to exit
with error when extracting archives:

  unzip: unsupported method 2048

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-04 14:54:16 +02:00
Denys Vlasenko 21e5d0f841 config: FEDORA_COMPAT option (so far only tweaks uname)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-04 02:22:17 +02:00
Denys Vlasenko cf792a58ab NOFORK fixes
"rm -i FILE" and "yes" can now be interrupted by ^C in hush.
This also now works:

$ usleep 19999999
^C
$ echo $?
130

function                                             old     new   delta
run_pipe                                            1668    1711     +43
pseudo_exec_argv                                     312     321      +9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 52/0)               Total: 52 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-04 02:20:19 +02:00
Denys Vlasenko 0a53eadea5 tls: fix pstm asm constraint problem
function                                             old     new   delta
pstm_sqr_comba                                       551     475     -76

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-04 02:18:00 +02:00
Denys Vlasenko 25f07f5898 tls: fix build problem on non-static i386
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-04 02:17:54 +02:00
Denys Vlasenko 6bb89e1622 libbb: safe_write should not return EINTR
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-04 02:17:50 +02:00
Denys Vlasenko 310bcec4dc shuf: fix random line selection. Closes 9971
"""
For example, given input file:

    foo
    bar
    baz

after shuffling the input file, foo will never end up back on the first line.
This came to light when I ran into a use-case where someone was selecting
a random line from a file using shuf | head -n 1, and the results on busybox
were showing a statistical anomaly (as in, the first line would never ever
be picked) vs the same process running on environments that had gnu coreutils
installed.

On line https://git.busybox.net/busybox/tree/coreutils/shuf.c#n56 it uses
r %= i, which will result in 0 <= r < i, while the algorithm specifies
0 <= r <= i.
"""

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-04 02:17:42 +02:00
Denys Vlasenko 8fd69c7bdb Bump version to 1.27.1
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:22:15 +02:00
Denys Vlasenko 56a361bec1 fix more instances of ": $((a++))" in shell scripts
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
Kang-Che Sung 6f13dd1d65 make_single_applets: fix ": $((fail++))" expansion error
$((fail++)) is not a required expression in POSIX, and in "dash" it
could produce an error like this:

    ./make_single_applets.sh: 61: arithmetic expression: expecting primary: "fail++"

Replace this with something portable: fail=$((fail+1)) would work.

Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
Johannes Schindelin 3df48bdde9 copyfd: guard use of munmap() with #if (windows builds need this)
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
Johannes Schindelin 1f684bcde4 ash: protect WIFSTOPPED use with #if JOBS
This change fixes the build in setups where there are
no headers defining WIFSTOPPED and WSTOPSIG (where JOBS has to be
set to 0).

This partially reverts 4700fb5be (ash: make dowait() a bit more
readable. Logic is unchanged, 2015-10-09).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
Denys Vlasenko 2cb72bb8de libbb: hide getnetbyaddr() inside "#if ENABLE_FEATURE_ETC_NETWORKS" block
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
Denys Vlasenko 87d8ae94a2 uuencode: allow space instead of "`" as padding char. Closes 10046
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
Denys Vlasenko a3de7190a5 dd: fix status=none. Closes 10066
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
Denys Vlasenko f807b8e96e inetd,mount: do not die if uclibc without RPC is detected
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
Denys Vlasenko 2f6dc07d8f beep: disallow FEATURE_BEEP_FREQ = 0 in configuration
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
Denys Vlasenko 54916641be main: fix the case where user has "halt" as login shell. Closes 9986
halt::0:0::/:/sbin/halt

function                                             old     new   delta
run_applet_and_exit                                  748     751      +3
run_applet_no_and_exit                               467     459      -8

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
Peter Korsgaard 80cb8796f8 dpkg: fix CONFIG_FEATURE_CLEAN_UP handling
dpkg moved to away from dynamically allocating the hashtables in commit
c87339d584 (dpkg: trivial code shrinkage, and redo G trick correctly) almost
ten years ago, but the cleanup code was never adjusted to match.

Glibc loudly complains about this:

*** Error in `dpkg': free(): invalid pointer: 0x0000007fac3478c0 ***

Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
Patrick Steinhardt ee67c9a60a setpriv: do not process remaining args
By default, the 'getopt32' call will continue parsing the command line
even after hitting a non-option string. But in setpriv, this should be
avoided, as all parameters following the initial non-option argument are
in fact arguments to the binary that is to be executed by setpriv.
Otherwise, calling e.g. 'busybox setpriv ls -l' would result in an error
due to the unknown parameter "-l".

Fix the issue by passing "+" as the first character in the options
string. This will cause 'getopt32' to stop processing after hitting the
first non-option.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
Denys Vlasenko 8965e5089e tls: use capped SNI len everywhere
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
Denys Vlasenko e916d48e5a bzcat: compile bunzip2_main() if BZCAT.
Currently, BZCAT (and BUNZIP2) selects FEATURE_BZIP2_DECOMPRESS,
thus, "#if ENABLE_FEATURE_BZIP2_DECOMPRESS" around bunzip2_main()
is sufficient. But let's robustify it.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
Denys Vlasenko 442d522f0b fixes for bugs found by make_single_applets.sh
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
38 changed files with 236 additions and 125 deletions

No files matched your search

+13
View File
@@ -33,6 +33,19 @@ config EXTRA_COMPAT
some GNU extensions in libc. You probably only need this option
if you plan to run busybox on desktop.
config FEDORA_COMPAT
bool "Building for Fedora distribution"
default n
help
This option makes some tools behave like they do on Fedora.
At the time of this writing (2017-08) this only affects uname:
normally, uname -p (processor) and uname -i (platform)
are shown as "unknown", but with this option uname -p
shows the same string as uname -m (machine type),
and so does uname -i unless machine type is i486/i586/i686 -
then uname -i shows "i386".
config INCLUDE_SUSv2
bool "Enable obsolete features removed before SUSv3"
default y
+1 -1
View File
@@ -1,6 +1,6 @@
VERSION = 1
PATCHLEVEL = 27
SUBLEVEL = 0
SUBLEVEL = 2
EXTRAVERSION =
NAME = Unnamed
+8 -3
View File
@@ -7,14 +7,19 @@
#include "libbb.h"
#include "bb_archive.h"
//kbuild:lib-$(CONFIG_ZCAT) += bbunzip.o
//kbuild:lib-$(CONFIG_GUNZIP) += bbunzip.o
//kbuild:lib-$(CONFIG_BZCAT) += bbunzip.o
//kbuild:lib-$(CONFIG_BUNZIP2) += bbunzip.o
/* lzop_main() uses bbunpack(), need this: */
//kbuild:lib-$(CONFIG_LZOP) += bbunzip.o
//kbuild:lib-$(CONFIG_LZOPCAT) += bbunzip.o
//kbuild:lib-$(CONFIG_UNLZOP) += bbunzip.o
/* bzip2_main() too: */
//kbuild:lib-$(CONFIG_FEATURE_BZIP2_DECOMPRESS) += bbunzip.o
//kbuild:lib-$(CONFIG_BZIP2) += bbunzip.o
/* gzip_main() too: */
//kbuild:lib-$(CONFIG_FEATURE_GZIP_DECOMPRESS) += bbunzip.o
//kbuild:lib-$(CONFIG_GZIP) += bbunzip.o
/* Note: must be kept in sync with archival/lzop.c */
enum {
@@ -443,7 +448,7 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
//applet:IF_BUNZIP2(APPLET(bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP))
// APPLET_ODDNAME:name main location suid_type help
//applet:IF_BZCAT(APPLET_ODDNAME(bzcat, bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP, bzcat))
#if ENABLE_FEATURE_BZIP2_DECOMPRESS
#if ENABLE_FEATURE_BZIP2_DECOMPRESS || ENABLE_BUNZIP2 || ENABLE_BZCAT
int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int bunzip2_main(int argc UNUSED_PARAM, char **argv)
{
-4
View File
@@ -1938,10 +1938,6 @@ int dpkg_main(int argc UNUSED_PARAM, char **argv)
for (i = 0; i < STATUS_HASH_PRIME; i++) {
free(status_hashtable[i]);
}
free(status_hashtable);
free(package_hashtable);
free(name_hashtable);
}
return EXIT_SUCCESS;
+1
View File
@@ -113,6 +113,7 @@ typedef union {
#define FIX_ENDIANNESS_ZIP(zip) \
do { if (BB_BIG_ENDIAN) { \
(zip).fmt.method = SWAP_LE16((zip).fmt.method ); \
(zip).fmt.crc32 = SWAP_LE32((zip).fmt.crc32 ); \
(zip).fmt.cmpsize = SWAP_LE32((zip).fmt.cmpsize ); \
(zip).fmt.ucmpsize = SWAP_LE32((zip).fmt.ucmpsize ); \
+3 -4
View File
@@ -133,9 +133,8 @@ enum {
/* end of input flags */
FLAG_TWOBUFS = (1 << 6) * ENABLE_FEATURE_DD_IBS_OBS,
FLAG_COUNT = 1 << 7,
FLAG_STATUS = 1 << 8,
FLAG_STATUS_NONE = 1 << 9,
FLAG_STATUS_NOXFER = 1 << 10,
FLAG_STATUS_NONE = 1 << 8,
FLAG_STATUS_NOXFER = 1 << 9,
};
static void dd_output_status(int UNUSED_PARAM cur_signal)
@@ -396,7 +395,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
n = index_in_strings(status_words, val);
if (n < 0)
bb_error_msg_and_die(bb_msg_invalid_arg_to, val, "status");
G.flags |= FLAG_STATUS << n;
G.flags |= FLAG_STATUS_NONE << n;
/*continue;*/
}
#endif
+3 -2
View File
@@ -16,7 +16,8 @@
//config: help
//config: rm is used to remove files or directories.
//applet:IF_RM(APPLET_NOFORK(rm, rm, BB_DIR_BIN, BB_SUID_DROP, rm))
//applet:IF_RM(APPLET_NOEXEC(rm, rm, BB_DIR_BIN, BB_SUID_DROP, rm))
/* was NOFORK, but then "rm -i FILE" can't be ^C'ed if run by hush */
//kbuild:lib-$(CONFIG_RM) += rm.o
@@ -36,7 +37,7 @@
#include "libbb.h"
/* This is a NOFORK applet. Be very careful! */
/* This is a NOEXEC applet. Be very careful! */
int rm_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int rm_main(int argc UNUSED_PARAM, char **argv)
+3 -2
View File
@@ -12,7 +12,8 @@
//config: help
//config: print a sequence of numbers
//applet:IF_SEQ(APPLET_NOFORK(seq, seq, BB_DIR_USR_BIN, BB_SUID_DROP, seq))
//applet:IF_SEQ(APPLET_NOEXEC(seq, seq, BB_DIR_USR_BIN, BB_SUID_DROP, seq))
/* was NOFORK, but then "seq 1 999999999" can't be ^C'ed if run by hush */
//kbuild:lib-$(CONFIG_SEQ) += seq.o
@@ -26,7 +27,7 @@
#include "libbb.h"
/* This is a NOFORK applet. Be very careful! */
/* This is a NOEXEC applet. Be very careful! */
int seq_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int seq_main(int argc, char **argv)
+1 -1
View File
@@ -53,7 +53,7 @@ static void shuffle_lines(char **lines, unsigned numlines)
/* RAND_MAX can be as small as 32767 */
if (i > RAND_MAX)
r ^= rand() << 15;
r %= i;
r %= i + 1;
tmp = lines[i];
lines[i] = lines[r];
lines[r] = tmp;
+1 -1
View File
@@ -157,7 +157,7 @@ int uname_main(int argc UNUSED_PARAM, char **argv)
strcpy(uname_info.processor, unknown_str);
strcpy(uname_info.platform, unknown_str);
strcpy(uname_info.os, CONFIG_UNAME_OSNAME);
#if 0
#if ENABLE_FEDORA_COMPAT
/* Fedora does something like this */
strcpy(uname_info.processor, uname_info.name.machine);
strcpy(uname_info.platform, uname_info.name.machine);
+7
View File
@@ -38,6 +38,13 @@ int usleep_main(int argc UNUSED_PARAM, char **argv)
bb_show_usage();
}
/* Safe wrt NOFORK? (noforks are not allowed to run for
* a long time). Try "usleep 99999999" + ^C + "echo $?"
* in hush with FEATURE_SH_NOFORK=y.
* At least on uclibc, usleep() thanslates to nanosleep()
* which returns early on any signal (even caught one),
* and uclibc does not loop back on EINTR.
*/
usleep(xatou(argv[1]));
return EXIT_SUCCESS;
+9 -3
View File
@@ -47,10 +47,16 @@ static void FAST_FUNC read_stduu(FILE *src_stream, FILE *dst_stream, int flags U
line = xmalloc_fgets_str_len(src_stream, "\n", &line_len);
if (!line)
break;
/* Handle both Unix and MSDOS text, and stray trailing spaces */
/* Handle both Unix and MSDOS text.
* Note: space should not be trimmed, some encoders use it instead of "`"
* for padding of last incomplete 4-char block.
*/
str_len = line_len;
while (--str_len >= 0 && isspace(line[str_len]))
while (--str_len >= 0
&& (line[str_len] == '\n' || line[str_len] == '\r')
) {
line[str_len] = '\0';
}
if (strcmp(line, "end") == 0) {
return; /* the only non-error exit */
@@ -65,7 +71,7 @@ static void FAST_FUNC read_stduu(FILE *src_stream, FILE *dst_stream, int flags U
encoded_len = line[0] * 4 / 3;
/* Check that line is not too short. (we tolerate
* overly _long_ line to accommodate possible extra '`').
* overly _long_ line to accommodate possible extra "`").
* Empty line case is also caught here. */
if (str_len <= encoded_len) {
break; /* go to bb_error_msg_and_die("short file"); */
+2 -1
View File
@@ -17,7 +17,8 @@
//config: yes is used to repeatedly output a specific string, or
//config: the default string `y'.
//applet:IF_YES(APPLET_NOFORK(yes, yes, BB_DIR_USR_BIN, BB_SUID_DROP, yes))
//applet:IF_YES(APPLET_NOEXEC(yes, yes, BB_DIR_USR_BIN, BB_SUID_DROP, yes))
/* was NOFORK, but then yes can't be ^C'ed if run by hush */
//kbuild:lib-$(CONFIG_YES) += yes.o
+3
View File
@@ -52,6 +52,9 @@ xargs, find, shells do it (grep for "spawn_and_wait" and
This poses much more serious limitations on what applet can do:
* all NOEXEC limitations apply.
* do not run for a long time or wait for user input:
hush shell only handles signals (like ^C) after you return
from APPLET_main().
* do not ever exit() or exec().
- xfuncs are okay. They are using special trick to return
to the caller applet instead of dying when they detect "x" condition.
+1 -1
View File
@@ -14,7 +14,7 @@ env | sort
while sleep 1; test $cnt != 0; do
echo "Trying to reread partition table on $DEVNAME ($cnt)"
: $((cnt--))
cnt=$((cnt-1))
# If device node doesn't exist, it means the device was removed.
# Stop trying.
test -e "$DEVNAME" || { echo "$DEVNAME doesn't exist, aborting"; exit 1; }
+1 -1
View File
@@ -30,7 +30,7 @@ test x"$router" != x"" || exec env - sleep "$ping_time"
failcnt=0
while true; do
ping $ping_opts "$router" && exec env - sleep "$ping_time"
: $((failcnt++))
failcnt=$((failcnt+1))
msg "Failed to ping $router, fail count:$failcnt"
test $failcnt -ge $max_fail && break
env - sleep "$retry_time"
+3 -1
View File
@@ -778,6 +778,8 @@ ssize_t recv_from_to(int fd, void *buf, size_t len, int flags,
uint16_t inet_cksum(uint16_t *addr, int len) FAST_FUNC;
/* 0 if argv[0] is NULL: */
unsigned string_array_len(char **argv) FAST_FUNC;
void overlapping_strcpy(char *dst, const char *src) FAST_FUNC;
char *safe_strncpy(char *dst, const char *src, size_t size) FAST_FUNC;
char *strncpy_IFNAMSIZ(char *dst, const char *src) FAST_FUNC;
@@ -1106,7 +1108,7 @@ int spawn_and_wait(char **argv) FAST_FUNC;
int run_nofork_applet(int applet_no, char **argv) FAST_FUNC;
#ifndef BUILD_INDIVIDUAL
extern int find_applet_by_name(const char *name) FAST_FUNC;
extern void run_applet_no_and_exit(int a, char **argv) NORETURN FAST_FUNC;
extern void run_applet_no_and_exit(int a, const char *name, char **argv) NORETURN FAST_FUNC;
#endif
/* Helpers for daemonization.
+23 -7
View File
@@ -78,6 +78,17 @@
#endif
unsigned FAST_FUNC string_array_len(char **argv)
{
char **start = argv;
while (*argv)
argv++;
return argv - start;
}
#if ENABLE_SHOW_USAGE && !ENABLE_FEATURE_COMPRESS_USAGE
static const char usage_messages[] ALIGN1 = UNPACKED_USAGE;
#else
@@ -866,16 +877,17 @@ static int busybox_main(char **argv)
# endif
# if NUM_APPLETS > 0
void FAST_FUNC run_applet_no_and_exit(int applet_no, char **argv)
void FAST_FUNC run_applet_no_and_exit(int applet_no, const char *name, char **argv)
{
int argc = 1;
while (argv[argc])
argc++;
int argc = string_array_len(argv);
/* Reinit some shared global data */
xfunc_error_retval = EXIT_FAILURE;
applet_name = bb_get_last_path_component_nostrip(argv[0]);
/*
* 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".
@@ -919,7 +931,7 @@ static NORETURN void run_applet_and_exit(const char *name, char **argv)
{
int applet = find_applet_by_name(name);
if (applet >= 0)
run_applet_no_and_exit(applet, argv);
run_applet_no_and_exit(applet, name, argv);
}
# endif
@@ -993,7 +1005,11 @@ int main(int argc UNUSED_PARAM, char **argv)
}
/* applet_names in this case is just "applet\0\0" */
lbb_prepare(applet_names IF_FEATURE_INDIVIDUAL(, argv));
# if ENABLE_BUILD_LIBBUSYBOX
return SINGLE_APPLET_MAIN(string_array_len(argv), argv);
# else
return SINGLE_APPLET_MAIN(argc, argv);
# endif
#elif !ENABLE_BUSYBOX && NUM_APPLETS == 0
+3
View File
@@ -119,8 +119,11 @@ static off_t bb_full_fd_action(int src_fd, int dst_fd, off_t size)
}
out:
/* some environments don't have munmap(), hide it in #if */
#if CONFIG_FEATURE_COPYBUF_KB > 4
if (buffer_size > 4 * 1024)
munmap(buffer, buffer_size);
#endif
return status ? -1 : total;
}
+1 -3
View File
@@ -379,9 +379,7 @@ getopt32(char **argv, const char *applet_opts, ...)
int spec_flgs = 0;
/* skip 0: some applets cheat: they do not actually HAVE argv[0] */
argc = 1;
while (argv[argc])
argc++;
argc = 1 + string_array_len(argv + 1);
va_start(p, applet_opts);
+19 -27
View File
@@ -11,6 +11,12 @@
#include "libbb.h"
#include "inet_common.h"
#if 0
# define dbg(...) bb_error_msg(__VA_ARGS__)
#else
# define dbg(...) ((void)0)
#endif
int FAST_FUNC INET_resolve(const char *name, struct sockaddr_in *s_in, int hostfirst)
{
struct hostent *hp;
@@ -33,9 +39,7 @@ int FAST_FUNC INET_resolve(const char *name, struct sockaddr_in *s_in, int hostf
}
/* If we expect this to be a hostname, try hostname database first */
if (hostfirst) {
#ifdef DEBUG
bb_error_msg("gethostbyname(%s)", name);
#endif
dbg("gethostbyname(%s)", name);
hp = gethostbyname(name);
if (hp) {
memcpy(&s_in->sin_addr, hp->h_addr_list[0],
@@ -45,9 +49,7 @@ int FAST_FUNC INET_resolve(const char *name, struct sockaddr_in *s_in, int hostf
}
#if ENABLE_FEATURE_ETC_NETWORKS
/* Try the NETWORKS database to see if this is a known network. */
#ifdef DEBUG
bb_error_msg("getnetbyname(%s)", name);
#endif
dbg("getnetbyname(%s)", name);
np = getnetbyname(name);
if (np) {
s_in->sin_addr.s_addr = htonl(np->n_net);
@@ -61,8 +63,8 @@ int FAST_FUNC INET_resolve(const char *name, struct sockaddr_in *s_in, int hostf
#ifdef DEBUG
res_init();
_res.options |= RES_DEBUG;
bb_error_msg("gethostbyname(%s)", name);
#endif
dbg("gethostbyname(%s)", name);
hp = gethostbyname(name);
if (!hp) {
return -1;
@@ -93,17 +95,12 @@ char* FAST_FUNC INET_rresolve(struct sockaddr_in *s_in, int numeric, uint32_t ne
smallint is_host;
if (s_in->sin_family != AF_INET) {
#ifdef DEBUG
bb_error_msg("rresolve: unsupported address family %d!",
s_in->sin_family);
#endif
dbg("rresolve: unsupported address family %d!", s_in->sin_family);
errno = EAFNOSUPPORT;
return NULL;
}
nip = s_in->sin_addr.s_addr;
#ifdef DEBUG
bb_error_msg("rresolve: %08x mask:%08x num:%08x", (unsigned)nip, netmask, numeric);
#endif
dbg("rresolve: %08x mask:%08x num:%08x", (unsigned)nip, netmask, numeric);
if (numeric & 0x0FFF)
return xmalloc_sockaddr2dotted_noport((void*)s_in);
if (nip == INADDR_ANY) {
@@ -117,10 +114,8 @@ char* FAST_FUNC INET_rresolve(struct sockaddr_in *s_in, int numeric, uint32_t ne
pn = cache;
while (pn) {
if (pn->nip == nip && pn->is_host == is_host) {
#ifdef DEBUG
bb_error_msg("rresolve: found %s %08x in cache",
dbg("rresolve: found %s %08x in cache",
(is_host ? "host" : "net"), (unsigned)nip);
#endif
return xstrdup(pn->name);
}
pn = pn->next;
@@ -128,19 +123,18 @@ char* FAST_FUNC INET_rresolve(struct sockaddr_in *s_in, int numeric, uint32_t ne
name = NULL;
if (is_host) {
#ifdef DEBUG
bb_error_msg("sockaddr2host_noport(%08x)", (unsigned)nip);
#endif
dbg("sockaddr2host_noport(%08x)", (unsigned)nip);
name = xmalloc_sockaddr2host_noport((void*)s_in);
} else if (ENABLE_FEATURE_ETC_NETWORKS) {
}
#if ENABLE_FEATURE_ETC_NETWORKS
else {
struct netent *np;
#ifdef DEBUG
bb_error_msg("getnetbyaddr(%08x)", (unsigned)ntohl(nip));
#endif
dbg("getnetbyaddr(%08x)", (unsigned)ntohl(nip));
np = getnetbyaddr(ntohl(nip), AF_INET);
if (np)
name = xstrdup(np->n_name);
}
#endif
if (!name)
name = xmalloc_sockaddr2dotted_noport((void*)s_in);
@@ -183,10 +177,8 @@ int FAST_FUNC INET6_resolve(const char *name, struct sockaddr_in6 *sin6)
char* FAST_FUNC INET6_rresolve(struct sockaddr_in6 *sin6, int numeric)
{
if (sin6->sin6_family != AF_INET6) {
#ifdef DEBUG
bb_error_msg("rresolve: unsupported address family %d!",
dbg("rresolve: unsupported address family %d!",
sin6->sin6_family);
#endif
errno = EAFNOSUPPORT;
return NULL;
}
+10 -2
View File
@@ -13,9 +13,17 @@ ssize_t FAST_FUNC safe_write(int fd, const void *buf, size_t count)
{
ssize_t n;
do {
for (;;) {
n = write(fd, buf, count);
} while (n < 0 && errno == EINTR);
if (n >= 0 || errno != EINTR)
break;
/* Some callers set errno=0, are upset when they see EINTR.
* Returning EINTR is wrong since we retry write(),
* the "error" was transient.
*/
errno = 0;
/* repeat the write() */
}
return n;
}
+3 -2
View File
@@ -16,6 +16,7 @@
*/
#include "busybox.h" /* uses applet tables */
#include "NUM_APPLETS.h"
/* This does a fork/exec in one call, using vfork(). Returns PID of new child,
* -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)
int FAST_FUNC spawn_and_wait(char **argv)
{
int rc;
#if ENABLE_FEATURE_PREFER_APPLETS
#if ENABLE_FEATURE_PREFER_APPLETS && (NUM_APPLETS > 1)
int a = find_applet_by_name(argv[0]);
if (a >= 0) {
@@ -179,7 +180,7 @@ int FAST_FUNC spawn_and_wait(char **argv)
* as of yet (and that should probably always stay true).
*/
/* xfunc_error_retval and applet_name are init by: */
run_applet_no_and_exit(a, argv);
run_applet_no_and_exit(a, argv[0], argv);
}
# endif
}
+3 -3
View File
@@ -54,18 +54,18 @@ for app; do
fi
if ! yes '' | make oldconfig >busybox_make_${app}.log 2>&1; then
: $((fail++))
fail=$((fail+1))
echo "Config error for ${app}"
mv .config busybox_config_${app}
elif ! make $makeopts >>busybox_make_${app}.log 2>&1; then
: $((fail++))
fail=$((fail+1))
grep -i -e error: -e warning: busybox_make_${app}.log
echo "Build error for ${app}"
mv .config busybox_config_${app}
elif ! grep -q '^#define NUM_APPLETS 1$' include/NUM_APPLETS.h; then
grep -i -e error: -e warning: busybox_make_${app}.log
mv busybox busybox_${app}
: $((fail++))
fail=$((fail+1))
echo "NUM_APPLETS != 1 for ${app}: `cat include/NUM_APPLETS.h`"
mv .config busybox_config_${app}
else
+1 -1
View File
@@ -16,7 +16,7 @@
//config:
//config:config FEATURE_BEEP_FREQ
//config: int "default frequency"
//config: range 0 2147483647
//config: range 20 50000 # allowing 0 here breaks the build
//config: default 4000
//config: depends on BEEP
//config: help
+12 -8
View File
@@ -227,7 +227,8 @@
#if ENABLE_FEATURE_INETD_RPC
# if defined(__UCLIBC__) && ! defined(__UCLIBC_HAS_RPC__)
# error "You need to build uClibc with UCLIBC_HAS_RPC for NFS support"
# warning "You probably need to build uClibc with UCLIBC_HAS_RPC for NFS support"
/* not #error, since user may be using e.g. libtirpc instead */
# endif
# include <rpc/rpc.h>
# include <rpc/pmap_clnt.h>
@@ -1513,8 +1514,11 @@ int inetd_main(int argc UNUSED_PARAM, char **argv)
} /* for (;;) */
}
#if !BB_MMU
#if ENABLE_FEATURE_INETD_SUPPORT_BUILTIN_ECHO \
|| ENABLE_FEATURE_INETD_SUPPORT_BUILTIN_DISCARD
# if !BB_MMU
static const char *const cat_args[] = { "cat", NULL };
# endif
#endif
/*
@@ -1525,14 +1529,14 @@ static const char *const cat_args[] = { "cat", NULL };
/* ARGSUSED */
static void FAST_FUNC echo_stream(int s, servtab_t *sep UNUSED_PARAM)
{
#if BB_MMU
# if BB_MMU
while (1) {
ssize_t sz = safe_read(s, line, LINE_SIZE);
if (sz <= 0)
break;
xwrite(s, line, sz);
}
#else
# else
/* We are after vfork here! */
/* move network socket to stdin/stdout */
xmove_fd(s, STDIN_FILENO);
@@ -1542,7 +1546,7 @@ static void FAST_FUNC echo_stream(int s, servtab_t *sep UNUSED_PARAM)
xopen(bb_dev_null, O_WRONLY);
BB_EXECVP("cat", (char**)cat_args);
/* on failure we return to main, which does exit(EXIT_FAILURE) */
#endif
# endif
}
static void FAST_FUNC echo_dg(int s, servtab_t *sep)
{
@@ -1566,10 +1570,10 @@ static void FAST_FUNC echo_dg(int s, servtab_t *sep)
/* ARGSUSED */
static void FAST_FUNC discard_stream(int s, servtab_t *sep UNUSED_PARAM)
{
#if BB_MMU
# if BB_MMU
while (safe_read(s, line, LINE_SIZE) > 0)
continue;
#else
# else
/* We are after vfork here! */
/* move network socket to stdin */
xmove_fd(s, STDIN_FILENO);
@@ -1580,7 +1584,7 @@ static void FAST_FUNC discard_stream(int s, servtab_t *sep UNUSED_PARAM)
xdup2(STDOUT_FILENO, STDERR_FILENO);
BB_EXECVP("cat", (char**)cat_args);
/* on failure we return to main, which does exit(EXIT_FAILURE) */
#endif
# endif
}
/* ARGSUSED */
static void FAST_FUNC discard_dg(int s, servtab_t *sep UNUSED_PARAM)
+2 -2
View File
@@ -1199,11 +1199,11 @@ static void send_client_hello_and_alloc_hsd(tls_state_t *tls, const char *sni)
};
struct client_hello *record;
int len;
int sni_len = sni ? strnlen(sni, 127) : 0;
int sni_len = sni ? strnlen(sni, 127 - 9) : 0;
len = sizeof(*record);
if (sni_len)
len += 11 + strlen(sni);
len += 11 + sni_len;
record = tls_get_outbuf(tls, len);
memset(record, 0, len);
+2 -1
View File
@@ -85,7 +85,8 @@ asm( \
"addl %%eax,%0 \n\t" \
"adcl %%edx,%1 \n\t" \
"adcl $0,%2 \n\t" \
:"=r"(c0), "=r"(c1), "=r"(c2): "0"(c0), "1"(c1), "2"(c2), "m"(i), "m"(j) :"%eax","%edx","%cc");
:"=rm"(c0), "=rm"(c1), "=rm"(c2): "0"(c0), "1"(c1), "2"(c2), "m"(i), "m"(j) :"%eax","%edx","%cc");
//bbox: ^^^ replaced "=r" with "=rm": %ebx is not available on shared build
/******************************************************************************/
#elif defined(PSTM_X86_64)
+4 -2
View File
@@ -78,7 +78,8 @@ asm( \
"addl %%eax,%0 \n\t" \
"adcl %%edx,%1 \n\t" \
"adcl $0,%2 \n\t" \
:"=r"(c0), "=r"(c1), "=r"(c2): "0"(c0), "1"(c1), "2"(c2), "m"(i) :"%eax","%edx","%cc");
:"=rm"(c0), "=rm"(c1), "=rm"(c2): "0"(c0), "1"(c1), "2"(c2), "m"(i) :"%eax","%edx","%cc");
//bbox: ^^^ replaced "=r" with "=rm": %ebx is not available on shared build
#define SQRADD2(i, j) \
asm( \
@@ -90,7 +91,8 @@ asm( \
"addl %%eax,%0 \n\t" \
"adcl %%edx,%1 \n\t" \
"adcl $0,%2 \n\t" \
:"=r"(c0), "=r"(c1), "=r"(c2): "0"(c0), "1"(c1), "2"(c2), "m"(i), "m"(j) :"%eax","%edx","%cc");
:"=rm"(c0), "=rm"(c1), "=rm"(c2): "0"(c0), "1"(c1), "2"(c2), "m"(i), "m"(j) :"%eax","%edx","%cc");
//bbox: ^^^ replaced "=r" with "=rm": %ebx is not available on shared build
#define SQRADDSC(i, j) \
asm( \
+6 -5
View File
@@ -718,15 +718,16 @@ int svc_main(int argc UNUSED_PARAM, char **argv)
argv[1] = command;
command[1] = '\0';
/* getopt32() was already called:
* reset the libc getopt() function, which keeps internal state.
*/
GETOPT_RESET();
do {
if (opts & 1) {
int r;
command[0] = *optstring;
/* getopt() was already called by getopt32():
* reset the libc getopt() function's internal state.
*/
GETOPT_RESET();
r = sv(argv);
if (r)
return 1;
+26
View File
@@ -1,7 +1,11 @@
#!/bin/sh
run_testsuite=false
run_testsuite=true
run_single_test=false
run_single_test=true
test -d "$1" || { echo "'$1' is not a directory"; exit 1; }
test -x "$1/scripts/randomtest" || { echo "No scripts/randomtest in '$1'"; exit 1; }
@@ -40,6 +44,28 @@ while sleep 1; do
fi
tail -n10 -- "$dir/testsuite/runtest.log"
fi
if $run_single_test; then
(
cd -- "$dir" || exit 1
echo "Running make_single_applets.sh in $dir..."
if grep -q '# CONFIG_FEATURE_TFTP_GET is not set' .config \
&& grep -q '# CONFIG_FEATURE_TFTP_PUT is not set' .config \
; then
# If both off, tftp[d] is ifdefed out and test fails.
# Enable one:
sed 's/# CONFIG_FEATURE_TFTP_GET is not set/CONFIG_FEATURE_TFTP_GET=y/' -i .config
fi
./make_single_applets.sh
)
if test $? != 0; then
echo "Failed make_single_applets.sh in $dir"
exit 1 # you may comment this out...
let fail++
continue
fi
fi
rm -rf -- "$dir"
let cnt++
done
+10 -4
View File
@@ -4022,15 +4022,19 @@ sprint_status48(char *s, int status, int sigonly)
col = 0;
if (!WIFEXITED(status)) {
if (JOBS && WIFSTOPPED(status))
#if JOBS
if (WIFSTOPPED(status))
st = WSTOPSIG(status);
else
#endif
st = WTERMSIG(status);
if (sigonly) {
if (st == SIGINT || st == SIGPIPE)
goto out;
if (JOBS && WIFSTOPPED(status))
#if JOBS
if (WIFSTOPPED(status))
goto out;
#endif
}
st &= 0x7f;
//TODO: use bbox's get_signame? strsignal adds ~600 bytes to text+rodata
@@ -4182,8 +4186,10 @@ dowait(int block, struct job *job)
goto out;
}
/* The process wasn't found in job list */
if (JOBS && !WIFSTOPPED(status))
#if JOBS
if (!WIFSTOPPED(status))
jobless--;
#endif
out:
INT_ON;
@@ -7688,7 +7694,7 @@ tryexec(IF_FEATURE_SH_STANDALONE(int applet_no,) char *cmd, char **argv, char **
clearenv();
while (*envp)
putenv(*envp++);
run_applet_no_and_exit(applet_no, argv);
run_applet_no_and_exit(applet_no, cmd, argv);
}
/* re-exec ourselves with the new arguments */
execve(bb_busybox_exec_path, argv, envp);
+37 -22
View File
@@ -1486,8 +1486,6 @@ typedef struct save_arg_t {
static void save_and_replace_G_args(save_arg_t *sv, char **argv)
{
int n;
sv->sv_argv0 = argv[0];
sv->sv_g_argv = G.global_argv;
sv->sv_g_argc = G.global_argc;
@@ -1497,10 +1495,7 @@ static void save_and_replace_G_args(save_arg_t *sv, char **argv)
G.global_argv = argv;
IF_HUSH_SET(G.global_args_malloced = 0;)
n = 1;
while (*++argv)
n++;
G.global_argc = n;
G.global_argc = 1 + string_array_len(argv + 1);
}
static void restore_G_args(save_arg_t *sv, char **argv)
@@ -6817,13 +6812,11 @@ static void exec_function(char ***to_free,
char **argv)
{
# if BB_MMU
int n = 1;
int n;
argv[0] = G.global_argv[0];
G.global_argv = argv;
while (*++argv)
n++;
G.global_argc = n;
G.global_argc = n = 1 + string_array_len(argv + 1);
/* On MMU, funcp->body is always non-NULL */
n = run_list(funcp->body);
fflush_all();
@@ -7070,8 +7063,10 @@ static NOINLINE void pseudo_exec_argv(nommu_save_t *nommu_save,
if (APPLET_IS_NOEXEC(a)) {
/* Do not leak open fds from opened script files etc */
close_all_FILE_list();
/* Without this, "rm -i FILE" can't be ^C'ed: */
switch_off_special_sigs(G.special_sig_mask);
debug_printf_exec("running applet '%s'\n", argv[0]);
run_applet_no_and_exit(a, argv);
run_applet_no_and_exit(a, argv[0], argv);
}
# endif
/* Re-exec ourselves */
@@ -7732,6 +7727,24 @@ static NOINLINE int run_pipe(struct pipe *pi)
add_vars(old_vars);
/* clean_up_and_ret0: */
restore_redirects(squirrel);
/*
* Try "usleep 99999999" + ^C + "echo $?"
* with FEATURE_SH_NOFORK=y.
*/
if (!funcp) {
/* It was builtin or nofork.
* if this would be a real fork/execed program,
* it should have died if a fatal sig was received.
* But OTOH, there was no separate process,
* the sig was sent to _shell_, not to non-existing
* child.
* Let's just handle ^C only, this one is obvious:
* we aren't ok with exitcode 0 when ^C was pressed
* during builtin/nofork.
*/
if (sigismember(&G.pending_set, SIGINT))
rcode = 128 + SIGINT;
}
clean_up_and_ret1:
free(argv_expanded);
IF_HAS_KEYWORDS(if (pi->pi_inverted) rcode = !rcode;)
@@ -7747,6 +7760,14 @@ static NOINLINE int run_pipe(struct pipe *pi)
if (rcode == 0) {
debug_printf_exec(": run_nofork_applet '%s' '%s'...\n",
argv_expanded[0], argv_expanded[1]);
/*
* Note: signals (^C) can't interrupt here.
* We remember them and they will be acted upon
* after applet returns.
* This makes applets which can run for a long time
* and/or wait for user input ineligible for NOFORK:
* for example, "yes" or "rm" (rm -i waits for input).
*/
rcode = run_nofork_applet(n, argv_expanded);
}
goto clean_up_and_ret;
@@ -8167,7 +8188,7 @@ static int run_list(struct pipe *pi)
/* Last command's pid goes to $! */
G.last_bg_pid = pi->cmds[pi->num_cmds - 1].pid;
debug_printf_exec(": cmd&: exitcode EXIT_SUCCESS\n");
/* Check pi->pi_inverted? "! sleep 1 & echo $?": bash says 1. dash and ash says 0 */
/* Check pi->pi_inverted? "! sleep 1 & echo $?": bash says 1. dash and ash say 0 */
rcode = EXIT_SUCCESS;
goto check_traps;
} else {
@@ -8829,12 +8850,8 @@ static int FAST_FUNC builtin_true(char **argv UNUSED_PARAM)
#if ENABLE_HUSH_TEST || ENABLE_HUSH_ECHO || ENABLE_HUSH_PRINTF || ENABLE_HUSH_KILL
static int run_applet_main(char **argv, int (*applet_main_func)(int argc, char **argv))
{
int argc = 0;
while (*argv) {
argc++;
argv++;
}
return applet_main_func(argc, argv - argc);
int argc = string_array_len(argv);
return applet_main_func(argc, argv);
}
#endif
#if ENABLE_HUSH_TEST || BASH_TEST2
@@ -9381,10 +9398,7 @@ static int FAST_FUNC builtin_set(char **argv)
/* This realloc's G.global_argv */
G.global_argv = pp = add_strings_to_strings(g_argv, argv, /*dup:*/ 1);
n = 1;
while (*++pp)
n++;
G.global_argc = n;
G.global_argc = 1 + string_array_len(pp + 1);
return EXIT_SUCCESS;
@@ -9805,6 +9819,7 @@ static int wait_for_child_or_signal(struct pipe *waitfor_pipe, pid_t waitfor_pid
/* So, did we get a signal? */
sig = check_and_run_traps();
if (sig /*&& sig != SIGCHLD - always true */) {
/* Do this for any (non-ignored) signal, not only for ^C */
ret = 128 + sig;
break;
}
+1 -3
View File
@@ -405,9 +405,7 @@ shell_builtin_ulimit(char **argv)
*/
GETOPT_RESET();
argc = 1;
while (argv[argc])
argc++;
argc = string_array_len(argv);
opts = 0;
while (1) {
+3
View File
@@ -185,6 +185,8 @@ struct hd_geometry {
#define HDIO_GETGEO 0x0301 /* get device geometry */
/* TODO: #if ENABLE_FEATURE_FDISK_WRITABLE */
/* (currently fdisk_sun/sgi.c do not have proper WRITABLE #ifs) */
static const char msg_building_new_label[] ALIGN1 =
"Building a new %s. Changes will remain in memory only,\n"
"until you decide to write them. After that the previous content\n"
@@ -192,6 +194,7 @@ static const char msg_building_new_label[] ALIGN1 =
static const char msg_part_already_defined[] ALIGN1 =
"Partition %u is already defined, delete it before re-adding\n";
/* #endif */
struct partition {
+6 -6
View File
@@ -47,7 +47,7 @@ test_mke2fs() {
kilobytes=60
while true; do
test_mke2fs || exit 1
: $((kilobytes++))
kilobytes=$((kilobytes+1))
test $kilobytes = 200 && break
done
@@ -56,7 +56,7 @@ done
kilobytes=$((1 * 8*1024 - 50))
while true; do
test_mke2fs || exit 1
: $((kilobytes++))
kilobytes=$((kilobytes+1))
test $kilobytes = $((1 * 8*1024 + 300)) && break
done
@@ -65,7 +65,7 @@ done
kilobytes=$((2 * 8*1024 - 50))
while true; do
test_mke2fs || exit 1
: $((kilobytes++))
kilobytes=$((kilobytes+1))
test $kilobytes = $((2 * 8*1024 + 400)) && break
done
@@ -74,7 +74,7 @@ done
kilobytes=$((3 * 8*1024 - 50))
while true; do
test_mke2fs || exit 1
: $((kilobytes++))
kilobytes=$((kilobytes+1))
test $kilobytes = $((3 * 8*1024 + 500)) && break
done
@@ -83,7 +83,7 @@ done
kilobytes=$((4 * 8*1024 - 50))
while true; do
test_mke2fs || exit 1
: $((kilobytes++))
kilobytes=$((kilobytes+1))
test $kilobytes = $((4 * 8*1024 + 600)) && break
done
@@ -92,7 +92,7 @@ done
kilobytes=$((5 * 8*1024 - 50))
while true; do
test_mke2fs || exit 1
: $((kilobytes++))
kilobytes=$((kilobytes+1))
test $kilobytes = $((5 * 8*1024 + 700)) && break
done
exit
+2 -1
View File
@@ -246,7 +246,8 @@
/* This is just a warning of a common mistake. Possibly this should be a
* uclibc faq entry rather than in busybox... */
# if defined(__UCLIBC__) && ! defined(__UCLIBC_HAS_RPC__)
# error "You need to build uClibc with UCLIBC_HAS_RPC for NFS support"
# warning "You probably need to build uClibc with UCLIBC_HAS_RPC for NFS support"
/* not #error, since user may be using e.g. libtirpc instead */
# endif
# include <rpc/rpc.h>
# include <rpc/pmap_prot.h>
+2 -1
View File
@@ -62,7 +62,8 @@ int setpriv_main(int argc UNUSED_PARAM, char **argv)
opt_complementary = "-1";
applet_long_options = setpriv_longopts;
opts = getopt32(argv, "");
opts = getopt32(argv, "+");
if (opts) {
if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0))
bb_simple_perror_msg_and_die("prctl: NO_NEW_PRIVS");