Compare commits

...
16 Commits
Author SHA1 Message Date
Denys Vlasenko b03007455c httpd: fix handling of range requests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-09-18 14:08:04 +02:00
Denys Vlasenko ca26f1c238 hush: fix a bug with "stdio rewind on exit". Closes 9186
With FEATURE_SH_STANDALONE=y, run this in a "sh SCRIPT":

sha256sum /dev/null
echo END

sha256sum is a NOEXEC applet. It runs in a forked child. Then child exit()s.
By this time, entire script is read, and buffered in a FILE object
from fopen("SCRIPT"). But fgetc() did not consume entire input.
exit() lseeks back by -9 bytes, from <eof> to 'e' in 'echo'.
(this may be libc-specific).
This change of fd position *is shared with the parent*!

Now parent can read more, and it thinks there is another "echo END".
End result: two "echo END"s are run.

`cmd` and arithmetic also need the fix for this, even without
FEATURE_SH_STANDALONE.

Fix this by _exit()ing instead.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-19 20:24:49 +02:00
Mike Frysinger 8191abd146 ash_test: ignore generated files
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
(cherry picked from commit b9b7aa1910)
2016-03-22 18:22:51 -04:00
Ron Yorston c1565a04f2 ash: simplify EOF/newline handling in list parser
Processing of here documents in ash has had a couple of breakages
which are now the subject of tests.  This commit should fix both.

It is based on the following commit in dash git by Herbert Xu:

   <7c245aa> [PARSER] Simplify EOF/newline handling in list parser

(See git://git.kernel.org/pub/scm/utils/dash/dash.git)

Reported-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
(cherry picked from commit c0e007663d)
2016-03-22 18:21:45 -04:00
Ron Yorston acad7392ee Revert "ash: fix a SEGV case in an invalid heredoc" xxx
This reverts commit 7e66102f76 but
leaves the test in place as it's still valid.

Reported-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
(cherry picked from commit 6bd2fabc52)
2016-03-22 18:21:28 -04:00
Ron Yorston 4c07ad9130 ash: add test for issue with here document
This used to work but doesn't now:

foo () {
cat <<EOF && { echo "$1" ; }
$1
EOF
}

foo "bar"

Reported-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
(cherry picked from commit 9121510dc6)
2016-03-22 18:21:06 -04:00
Ron Yorston 856af4e3dc ash: fix corruption of ${#var} if $var contains UTF-8 characters
As reported in bug 8506:

   $ X=abcdÉfghÍjklmnÓpqrstÚvwcyz
   $ echo ${#X}
   abcd26

The result should be 26.

This regression was introduced by:

   <d68d1fb> 2015-05-18 [Ron Yorston]  ash: code shrink around varvalue

The length in characters was being used to discard the contents of
the variable instead of the length in bytes.

URL: https://bugs.busybox.net/8506
Reported-by: Martijn Dekker <martijn@inlv.org>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
(cherry picked from commit 3e3bfb896e)
2016-03-22 18:20:04 -04:00
Ron Yorston 4194c28753 ash: fix error during recursive processing of here document
Save the value of the checkkwd flag to prevent it being clobbered
during recursion.

Based on commit ec2c84d from git://git.kernel.org/pub/scm/utils/dash/dash.git
by Herbert Xu.

function                                             old     new   delta
readtoken                                            190     203     +13
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 13/0)               Total: 13 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
(cherry picked from commit 713f07d906)
2016-03-21 14:28:06 -04:00
Denys Vlasenko 3a76bb5136 udhcp: fix a SEGV on malformed RFC1035-encoded domain name
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
(cherry picked from commit d474ffc682)
2016-03-21 14:23:12 -04:00
Denys Vlasenko 3c4de6e36c udhcpc: fix OPTION_6RD parsing (could overflow its malloced buffer)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
(cherry picked from commit 352f79acbd)
2016-03-21 14:23:05 -04:00
Denys Vlasenko e50f74da70 Bump version to 1.24.2
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-17 21:38:03 +01:00
Denys Vlasenko 9de318d63e scripts/trylink: fix static build with glibc again. Closes 8471
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-17 21:37:12 +01:00
Ari Sundholm be729c1d3b truncate: always set mode when opening file to avoid fortify errors
Busybox crashes due to no mode being given when opening:
$ ./busybox truncate -s 1M foo
*** invalid open64 call: O_CREAT without mode ***: ./busybox terminated
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x7338f)[0x7f66d921338f]
/lib/x86_64-linux-gnu/libc.so.6(__fortify_fail+0x5c)[0x7f66d92aac9c]
/lib/x86_64-linux-gnu/libc.so.6(+0xeb6aa)[0x7f66d928b6aa]
./busybox[0x4899f9]
======= Memory map: ========
00400000-004d0000 r-xp 00000000 00:1a 137559                             /home/ari/busybox/busybox
006cf000-006d0000 r--p 000cf000 00:1a 137559                             /home/ari/busybox/busybox
006d0000-006d1000 rw-p 000d0000 00:1a 137559                             /home/ari/busybox/busybox
006d1000-006d4000 rw-p 00000000 00:00 0
014e7000-01508000 rw-p 00000000 00:00 0                                  [heap]
7f66d8f8a000-7f66d8fa0000 r-xp 00000000 08:07 1579008                    /lib/x86_64-linux-gnu/libgcc_s.so.1
7f66d8fa0000-7f66d919f000 ---p 00016000 08:07 1579008                    /lib/x86_64-linux-gnu/libgcc_s.so.1
7f66d919f000-7f66d91a0000 rw-p 00015000 08:07 1579008                    /lib/x86_64-linux-gnu/libgcc_s.so.1
7f66d91a0000-7f66d935b000 r-xp 00000000 08:07 1578994                    /lib/x86_64-linux-gnu/libc-2.19.so
7f66d935b000-7f66d955a000 ---p 001bb000 08:07 1578994                    /lib/x86_64-linux-gnu/libc-2.19.so
7f66d955a000-7f66d955e000 r--p 001ba000 08:07 1578994                    /lib/x86_64-linux-gnu/libc-2.19.so
7f66d955e000-7f66d9560000 rw-p 001be000 08:07 1578994                    /lib/x86_64-linux-gnu/libc-2.19.so
7f66d9560000-7f66d9565000 rw-p 00000000 00:00 0
7f66d9565000-7f66d966a000 r-xp 00000000 08:07 1579020                    /lib/x86_64-linux-gnu/libm-2.19.so
7f66d966a000-7f66d9869000 ---p 00105000 08:07 1579020                    /lib/x86_64-linux-gnu/libm-2.19.so
7f66d9869000-7f66d986a000 r--p 00104000 08:07 1579020                    /lib/x86_64-linux-gnu/libm-2.19.so
7f66d986a000-7f66d986b000 rw-p 00105000 08:07 1579020                    /lib/x86_64-linux-gnu/libm-2.19.so
7f66d986b000-7f66d988e000 r-xp 00000000 08:07 1578981                    /lib/x86_64-linux-gnu/ld-2.19.so
7f66d9a64000-7f66d9a67000 rw-p 00000000 00:00 0
7f66d9a8a000-7f66d9a8d000 rw-p 00000000 00:00 0
7f66d9a8d000-7f66d9a8e000 r--p 00022000 08:07 1578981                    /lib/x86_64-linux-gnu/ld-2.19.so
7f66d9a8e000-7f66d9a8f000 rw-p 00023000 08:07 1578981                    /lib/x86_64-linux-gnu/ld-2.19.so
7f66d9a8f000-7f66d9a90000 rw-p 00000000 00:00 0
7ffc47761000-7ffc47782000 rw-p 00000000 00:00 0                          [stack]
7ffc477ab000-7ffc477ad000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
Aborted (core dumped)
$

Fix this by simply always setting the mode, as it doesn't hurt even
when O_CREAT is not specified.

This bug is a regression introduced in fc3e40e, as xopen(), which
was originally used, would automatically set the mode.

Signed-off-by: Ari Sundholm <ari@tuxera.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
(cherry picked from commit e111a16404)
2016-01-13 13:33:38 -05:00
Denys Vlasenko 092fabcf1d [g]unzip: fix recent breakage.
Also, do emit error message we so painstakingly pass from gzip internals

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
(cherry picked from commit 6bd3fff51a)
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2015-12-02 00:03:42 -05:00
Denys Vlasenko 6767af17f1 unzip: test for bad archive SEGVing
function                                             old     new   delta
huft_build                                          1296    1300      +4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
(cherry picked from commit 1de25a6e87)
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2015-12-01 11:05:07 -05:00
Denys Vlasenko 5c23f2566c Apply post-1.24.0 patches, bump version to 1.24.1
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-24 02:29:00 +02:00
23 changed files with 307 additions and 125 deletions

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
VERSION = 1
PATCHLEVEL = 24
SUBLEVEL = 0
SUBLEVEL = 2
EXTRAVERSION =
NAME = Unnamed
+24 -12
View File
@@ -305,11 +305,11 @@ static int huft_build(const unsigned *b, const unsigned n,
unsigned i; /* counter, current code */
unsigned j; /* counter */
int k; /* number of bits in current code */
unsigned *p; /* pointer into c[], b[], or v[] */
const unsigned *p; /* pointer into c[], b[], or v[] */
huft_t *q; /* points to current table */
huft_t r; /* table entry for structure assignment */
huft_t *u[BMAX]; /* table stack */
unsigned v[N_MAX]; /* values in order of bit length */
unsigned v[N_MAX + 1]; /* values in order of bit length. last v[] is never used */
int ws[BMAX + 1]; /* bits decoded stack */
int w; /* bits decoded */
unsigned x[BMAX + 1]; /* bit offsets, then code stack */
@@ -324,7 +324,7 @@ static int huft_build(const unsigned *b, const unsigned n,
/* Generate counts for each bit length */
memset(c, 0, sizeof(c));
p = (unsigned *) b; /* cast allows us to reuse p for pointing to b */
p = b;
i = n;
do {
c[*p]++; /* assume all entries <= BMAX */
@@ -364,8 +364,12 @@ static int huft_build(const unsigned *b, const unsigned n,
*xp++ = j;
}
/* Make a table of values in order of bit lengths */
p = (unsigned *) b;
/* Make a table of values in order of bit lengths.
* To detect bad input, unused v[i]'s are set to invalid value UINT_MAX.
* In particular, last v[i] is never filled and must not be accessed.
*/
memset(v, 0xff, sizeof(v));
p = b;
i = 0;
do {
j = *p++;
@@ -432,7 +436,9 @@ static int huft_build(const unsigned *b, const unsigned n,
/* set up table entry in r */
r.b = (unsigned char) (k - w);
if (p >= v + n) {
if (/*p >= v + n || -- redundant, caught by the second check: */
*p == UINT_MAX /* do we access uninited v[i]? (see memset(v))*/
) {
r.e = 99; /* out of values--invalid code */
} else if (*p < s) {
r.e = (unsigned char) (*p < 256 ? 16 : 15); /* 256 is EOB code */
@@ -517,8 +523,9 @@ static NOINLINE int inflate_codes(STATE_PARAM_ONLY)
e = t->e;
if (e > 16)
do {
if (e == 99)
abort_unzip(PASS_STATE_ONLY);;
if (e == 99) {
abort_unzip(PASS_STATE_ONLY);
}
bb >>= t->b;
k -= t->b;
e -= 16;
@@ -554,8 +561,9 @@ static NOINLINE int inflate_codes(STATE_PARAM_ONLY)
e = t->e;
if (e > 16)
do {
if (e == 99)
if (e == 99) {
abort_unzip(PASS_STATE_ONLY);
}
bb >>= t->b;
k -= t->b;
e -= 16;
@@ -821,8 +829,9 @@ static int inflate_block(STATE_PARAM smallint *e)
b_dynamic >>= 4;
k_dynamic -= 4;
if (nl > 286 || nd > 30)
if (nl > 286 || nd > 30) {
abort_unzip(PASS_STATE_ONLY); /* bad lengths */
}
/* read in bit-length-code lengths */
for (j = 0; j < nb; j++) {
@@ -903,12 +912,14 @@ static int inflate_block(STATE_PARAM smallint *e)
bl = lbits;
i = huft_build(ll, nl, 257, cplens, cplext, &inflate_codes_tl, &bl);
if (i != 0)
if (i != 0) {
abort_unzip(PASS_STATE_ONLY);
}
bd = dbits;
i = huft_build(ll + nl, nd, 0, cpdist, cpdext, &inflate_codes_td, &bd);
if (i != 0)
if (i != 0) {
abort_unzip(PASS_STATE_ONLY);
}
/* set up data for inflate_codes() */
inflate_codes_setup(PASS_STATE bl, bd);
@@ -996,6 +1007,7 @@ inflate_unzip_internal(STATE_PARAM transformer_state_t *xstate)
error_msg = "corrupted data";
if (setjmp(error_jmp)) {
/* Error from deep inside zip machinery */
bb_error_msg(error_msg);
n = -1;
goto ret;
}
+15 -5
View File
@@ -106,7 +106,9 @@ static struct sort_key {
static char *get_key(char *str, struct sort_key *key, int flags)
{
int start = 0, end = 0, len, j;
int start = start; /* for compiler */
int end;
int len, j;
unsigned i;
/* Special case whole string, so we don't have to make a copy */
@@ -123,12 +125,15 @@ static char *get_key(char *str, struct sort_key *key, int flags)
end = len;
/* Loop through fields */
else {
unsigned char ch = 0;
end = 0;
for (i = 1; i < key->range[2*j] + j; i++) {
if (key_separator) {
/* Skip body of key and separator */
while (str[end]) {
if (str[end++] == key_separator)
while ((ch = str[end]) != '\0') {
end++;
if (ch == key_separator)
break;
}
} else {
@@ -136,7 +141,7 @@ static char *get_key(char *str, struct sort_key *key, int flags)
while (isspace(str[end]))
end++;
/* Skip body of key */
while (str[end]) {
while (str[end] != '\0') {
if (isspace(str[end]))
break;
end++;
@@ -144,8 +149,13 @@ static char *get_key(char *str, struct sort_key *key, int flags)
}
}
/* Remove last delim: "abc:def:" => "abc:def" */
if (key_separator && j && end != 0)
if (j && ch) {
//if (str[end-1] != key_separator)
// bb_error_msg(_and_die("BUG! "
// "str[start:%d,end:%d]:'%.*s'",
// start, end, (int)(end-start), &str[start]);
end--;
}
}
if (!j) start = end;
}
+1 -1
View File
@@ -64,7 +64,7 @@ int truncate_main(int argc UNUSED_PARAM, char **argv)
argv += optind;
while (*argv) {
int fd = open(*argv, flags);
int fd = open(*argv, flags, 0666);
if (fd < 0) {
if (errno != ENOENT || !(opts & OPT_NOCREATE)) {
bb_perror_msg("%s: open", *argv);
+3 -1
View File
@@ -771,7 +771,9 @@ void FAST_FUNC run_applet_no_and_exit(int applet_no, char **argv)
}
if (ENABLE_FEATURE_SUID)
check_suid(applet_no);
exit(applet_main[applet_no](argc, 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();
}
void FAST_FUNC run_applet_and_exit(const char *name, char **argv)
+16 -1
View File
@@ -1223,11 +1223,26 @@ int ftpd_main(int argc UNUSED_PARAM, char **argv)
#endif
argv += optind;
if (argv[0]) {
const char *basedir = argv[0];
#if !BB_MMU
G.root_fd = xopen("/", O_RDONLY | O_DIRECTORY);
close_on_exec_on(G.root_fd);
#endif
xchroot(argv[0]);
if (chroot(basedir) == 0)
basedir = "/";
#if !BB_MMU
else {
close(G.root_fd);
G.root_fd = -1;
}
#endif
/*
* If chroot failed, assume that we aren't root,
* and at least chdir to the specified DIR
* (older versions were dying with error message).
* If chroot worked, move current dir to new "/":
*/
xchdir(basedir);
}
#if ENABLE_FEATURE_FTP_AUTHENTICATION
+20 -7
View File
@@ -967,19 +967,30 @@ static void send_headers(int responseNum)
}
#endif
if (responseNum == HTTP_MOVED_TEMPORARILY) {
len += sprintf(iobuf + len, "Location: %s/%s%s\r\n",
/* Responding to "GET /dir" with
* "HTTP/1.0 302 Found" "Location: /dir/"
* - IOW, asking them to repeat with a slash.
* Here, overflow IS possible, can't use sprintf:
* mkdir test
* python -c 'print("get /test?" + ("x" * 8192))' | busybox httpd -i -h .
*/
len += snprintf(iobuf + len, IOBUF_SIZE-3 - len,
"Location: %s/%s%s\r\n",
found_moved_temporarily,
(g_query ? "?" : ""),
(g_query ? g_query : ""));
if (len > IOBUF_SIZE-3)
len = IOBUF_SIZE-3;
}
#if ENABLE_FEATURE_HTTPD_ERROR_PAGES
if (error_page && access(error_page, R_OK) == 0) {
strcat(iobuf, "\r\n");
len += 2;
if (DEBUG)
iobuf[len++] = '\r';
iobuf[len++] = '\n';
if (DEBUG) {
iobuf[len] = '\0';
fprintf(stderr, "headers: '%s'\n", iobuf);
}
full_write(STDOUT_FILENO, iobuf, len);
if (DEBUG)
fprintf(stderr, "writing error page: '%s'\n", error_page);
@@ -1021,8 +1032,10 @@ static void send_headers(int responseNum)
responseNum, responseString,
responseNum, responseString, infoString);
}
if (DEBUG)
if (DEBUG) {
iobuf[len] = '\0';
fprintf(stderr, "headers: '%s'\n", iobuf);
}
if (full_write(STDOUT_FILENO, iobuf, len) != len) {
if (verbose > 1)
bb_perror_msg("error");
@@ -2183,7 +2196,7 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr)
if (STRNCASECMP(iobuf, "Range:") == 0) {
/* We know only bytes=NNN-[MMM] */
char *s = skip_whitespace(iobuf + sizeof("Range:")-1);
if (is_prefixed_with(s, "bytes=") == 0) {
if (is_prefixed_with(s, "bytes=")) {
s += sizeof("bytes=")-1;
range_start = BB_STRTOOFF(s, &s, 10);
if (s[0] != '-' || range_start < 0) {
+13 -2
View File
@@ -142,7 +142,7 @@ const char dhcp_option_strings[] ALIGN1 =
* udhcp_str2optset: to determine how many bytes to allocate.
* xmalloc_optname_optval: to estimate string length
* from binary option length: (option[LEN] / dhcp_option_lengths[opt_type])
* is the number of elements, multiply in by one element's string width
* is the number of elements, multiply it by one element's string width
* (len_of_option_as_string[opt_type]) and you know how wide string you need.
*/
const uint8_t dhcp_option_lengths[] ALIGN1 = {
@@ -162,7 +162,18 @@ const uint8_t dhcp_option_lengths[] ALIGN1 = {
[OPTION_S32] = 4,
/* Just like OPTION_STRING, we use minimum length here */
[OPTION_STATIC_ROUTES] = 5,
[OPTION_6RD] = 22, /* ignored by udhcp_str2optset */
[OPTION_6RD] = 12, /* ignored by udhcp_str2optset */
/* The above value was chosen as follows:
* len_of_option_as_string[] for this option is >60: it's a string of the form
* "32 128 ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff 255.255.255.255 ".
* Each additional ipv4 address takes 4 bytes in binary option and appends
* another "255.255.255.255 " 16-byte string. We can set [OPTION_6RD] = 4
* but this severely overestimates string length: instead of 16 bytes,
* it adds >60 for every 4 bytes in binary option.
* We cheat and declare here that option is in units of 12 bytes.
* This adds more than 60 bytes for every three ipv4 addresses - more than enough.
* (Even 16 instead of 12 should work, but let's be paranoid).
*/
};
+2 -2
View File
@@ -113,7 +113,7 @@ static const uint8_t len_of_option_as_string[] = {
[OPTION_IP ] = sizeof("255.255.255.255 "),
[OPTION_IP_PAIR ] = sizeof("255.255.255.255 ") * 2,
[OPTION_STATIC_ROUTES ] = sizeof("255.255.255.255/32 255.255.255.255 "),
[OPTION_6RD ] = sizeof("32 128 ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff 255.255.255.255 "),
[OPTION_6RD ] = sizeof("132 128 ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff 255.255.255.255 "),
[OPTION_STRING ] = 1,
[OPTION_STRING_HOST ] = 1,
#if ENABLE_FEATURE_UDHCP_RFC3397
@@ -220,7 +220,7 @@ static NOINLINE char *xmalloc_optname_optval(uint8_t *option, const struct dhcp_
type = optflag->flags & OPTION_TYPE_MASK;
optlen = dhcp_option_lengths[type];
upper_length = len_of_option_as_string[type]
* ((unsigned)(len + optlen - 1) / (unsigned)optlen);
* ((unsigned)(len + optlen) / (unsigned)optlen);
dest = ret = xmalloc(upper_length + strlen(opt_name) + 2);
dest += sprintf(ret, "%s=", opt_name);
+9 -4
View File
@@ -63,11 +63,10 @@ char* FAST_FUNC dname_dec(const uint8_t *cstr, int clen, const char *pre)
if (crtpos + *c + 1 > clen) /* label too long? abort */
return NULL;
if (dst)
memcpy(dst + len, c + 1, *c);
/* \3com ---> "com." */
((char*)mempcpy(dst + len, c + 1, *c))[0] = '.';
len += *c + 1;
crtpos += *c + 1;
if (dst)
dst[len - 1] = '.';
} else {
/* NUL: end of current domain name */
if (retpos == 0) {
@@ -78,7 +77,10 @@ char* FAST_FUNC dname_dec(const uint8_t *cstr, int clen, const char *pre)
crtpos = retpos;
retpos = depth = 0;
}
if (dst)
if (dst && len != 0)
/* \4host\3com\0\4host and we are at \0:
* \3com was converted to "com.", change dot to space.
*/
dst[len - 1] = ' ';
}
@@ -228,6 +230,9 @@ int main(int argc, char **argv)
int len;
uint8_t *encoded;
uint8_t str[6] = { 0x00, 0x00, 0x02, 0x65, 0x65, 0x00 };
printf("NUL:'%s'\n", dname_dec(str, 6, ""));
#define DNAME_DEC(encoded,pre) dname_dec((uint8_t*)(encoded), sizeof(encoded), (pre))
printf("'%s'\n", DNAME_DEC("\4host\3com\0", "test1:"));
printf("test2:'%s'\n", DNAME_DEC("\4host\3com\0\4host\3com\0", ""));
+35 -24
View File
@@ -47,18 +47,22 @@ try() {
check_cc() {
local tempname="$(mktemp)"
local r
echo "int main(int argc,char**argv){return argv?argc:0;}" >"$tempname".c
# Can use "-o /dev/null", but older gcc tend to *unlink it* on failure! :(
# "-xc": C language. "/dev/null" is an empty source file.
if $CC $CPPFLAGS $CFLAGS $1 -shared -xc /dev/null -o "$tempname".o >/dev/null 2>&1; then
echo "$1";
else
echo "$2";
fi
rm -f "$tempname" "$tempname".o
# Was using "-xc /dev/null", but we need a valid C program.
# "eval" may be needed if CFLAGS can contain
# '... -D"BB_VER=KBUILD_STR(1.N.M)" ...'
# and we need shell to process quotes!
$CC $CFLAGS $1 "$tempname".c -o "$tempname" >/dev/null 2>&1
r=$?
rm -f "$tempname" "$tempname".c "$tempname".o
return $r
}
check_libc_is_glibc() {
local tempname="$(mktemp)"
local r
echo "\
#include <stdlib.h>
/* Apparently uclibc defines __GLIBC__ (compat trick?). Oh well. */
@@ -66,12 +70,10 @@ check_libc_is_glibc() {
syntax error here
#endif
" >"$tempname".c
if $CC $CPPFLAGS $CFLAGS "$tempname".c -c -o "$tempname".o >/dev/null 2>&1; then
echo "$2";
else
echo "$1";
fi
rm -f "$tempname" "$tempname".[co]
! $CC $CFLAGS "$tempname".c -c -o "$tempname".o >/dev/null 2>&1
r=$?
rm -f "$tempname" "$tempname".c "$tempname".o
return $r
}
EXE="$1"
@@ -83,32 +85,41 @@ A_FILES="$6"
LDLIBS="$7"
# The --sort-section option is not supported by older versions of ld
SORT_SECTION=`check_cc "-Wl,--sort-section,alignment" ""`
SORT_SECTION="-Wl,--sort-section,alignment"
if ! check_cc "-Wl,--sort-section,alignment"; then
echo "Your linker does not support --sort-section,alignment"
SORT_SECTION=""
fi
START_GROUP="-Wl,--start-group"
END_GROUP="-Wl,--end-group"
INFO_OPTS="-Wl,--warn-common -Wl,-Map,$EXE.map -Wl,--verbose"
# gold may not support --sort-common (yet)
SORT_COMMON=`check_cc "-Wl,--sort-common" ""`
SORT_COMMON="-Wl,--sort-common"
if ! check_cc "-Wl,--sort-common"; then
echo "Your linker does not support --sort-common"
SORT_COMMON=""
fi
# Static linking against glibc produces buggy executables
# (glibc does not cope well with ld --gc-sections).
# See sources.redhat.com/bugzilla/show_bug.cgi?id=3400
# Note that glibc is unsuitable for static linking anyway.
# We are removing -Wl,--gc-sections from link command line.
GC_SECTIONS=`(
. ./.config
if test x"$CONFIG_STATIC" = x"y"; then
check_libc_is_glibc "" "-Wl,--gc-sections"
else
echo "-Wl,--gc-sections"
GC_SECTIONS="-Wl,--gc-sections"
if (. ./.config && test x"$CONFIG_STATIC" = x"y") then
if check_libc_is_glibc; then
echo "Static linking against glibc, can't use --gc-sections"
GC_SECTIONS=""
fi
fi
)`
# The --gc-sections option is not supported by older versions of ld
if test -n "$GC_SECTIONS"; then
GC_SECTIONS=`check_cc "$GC_SECTIONS" ""`
if ! check_cc "$GC_SECTIONS"; then
echo "Your linker does not support $GC_SECTIONS"
GC_SECTIONS=""
fi
fi
# Sanitize lib list (dups, extra spaces etc)
+35 -44
View File
@@ -6693,6 +6693,8 @@ varvalue(char *name, int varflags, int flags, struct strlist *var_str_list)
if (subtype == VSLENGTH && len > 0) {
reinit_unicode_for_ash();
if (unicode_status == UNICODE_ON) {
STADJUST(-len, expdest);
discard = 0;
len = unicode_strlen(p);
}
}
@@ -10516,7 +10518,7 @@ static union node *andor(void);
static union node *pipeline(void);
static union node *parse_command(void);
static void parseheredoc(void);
static char nexttoken_ends_list(void);
static int peektoken(void);
static int readtoken(void);
static union node *
@@ -10525,11 +10527,27 @@ list(int nlflag)
union node *n1, *n2, *n3;
int tok;
checkkwd = CHKNL | CHKKWD | CHKALIAS;
if (nlflag == 2 && nexttoken_ends_list())
return NULL;
n1 = NULL;
for (;;) {
switch (peektoken()) {
case TNL:
if (!(nlflag & 1))
break;
parseheredoc();
return n1;
case TEOF:
if (!n1 && (nlflag & 1))
n1 = NODE_EOF;
parseheredoc();
return n1;
}
checkkwd = CHKNL | CHKKWD | CHKALIAS;
if (nlflag == 2 && tokname_array[peektoken()][0])
return n1;
nlflag |= 2;
n2 = andor();
tok = readtoken();
if (tok == TBACKGND) {
@@ -10555,37 +10573,15 @@ list(int nlflag)
n1 = n3;
}
switch (tok) {
case TNL:
case TEOF:
tokpushback = 1;
/* fall through */
case TBACKGND:
case TSEMI:
tok = readtoken();
/* fall through */
case TNL:
if (tok == TNL) {
parseheredoc();
if (nlflag == 1)
return n1;
} else {
tokpushback = 1;
}
checkkwd = CHKNL | CHKKWD | CHKALIAS;
if (nexttoken_ends_list()) {
/* Testcase: "<<EOF; then <W".
* It used to segfault w/o this check:
*/
if (heredoclist) {
raise_error_unexpected_syntax(-1);
}
return n1;
}
break;
case TEOF:
if (heredoclist)
parseheredoc();
else
pungetc(); /* push back EOF on input */
return n1;
default:
if (nlflag == 1)
if ((nlflag & 1))
raise_error_unexpected_syntax(-1);
tokpushback = 1;
return n1;
@@ -11893,6 +11889,7 @@ static int
readtoken(void)
{
int t;
int kwd = checkkwd;
#if DEBUG
smallint alreadyseen = tokpushback;
#endif
@@ -11906,7 +11903,7 @@ readtoken(void)
/*
* eat newlines
*/
if (checkkwd & CHKNL) {
if (kwd & CHKNL) {
while (t == TNL) {
parseheredoc();
t = xxreadtoken();
@@ -11920,7 +11917,7 @@ readtoken(void)
/*
* check for keywords
*/
if (checkkwd & CHKKWD) {
if (kwd & CHKKWD) {
const char *const *pp;
pp = findkwd(wordtext);
@@ -11954,14 +11951,14 @@ readtoken(void)
return t;
}
static char
nexttoken_ends_list(void)
static int
peektoken(void)
{
int t;
t = readtoken();
tokpushback = 1;
return tokname_array[t][0];
return t;
}
/*
@@ -11971,18 +11968,12 @@ nexttoken_ends_list(void)
static union node *
parsecmd(int interact)
{
int t;
tokpushback = 0;
checkkwd = 0;
heredoclist = 0;
doprompt = interact;
setprompt_if(doprompt, doprompt);
needprompt = 0;
t = readtoken();
if (t == TEOF)
return NODE_EOF;
if (t == TNL)
return NULL;
tokpushback = 1;
return list(1);
}
+7
View File
@@ -0,0 +1,7 @@
/ash
/printenv
/recho
/zecho
/*.fail
*.xx
@@ -0,0 +1,2 @@
bar
bar
+7
View File
@@ -0,0 +1,7 @@
foo () {
cat <<EOF && { echo "$1" ; }
$1
EOF
}
foo "bar"
@@ -0,0 +1 @@
hello
+9
View File
@@ -0,0 +1,9 @@
echo hello >greeting
cat <<EOF &&
$(cat greeting)
EOF
{
echo $?
cat greeting
} >/dev/null
rm greeting
@@ -0,0 +1 @@
26
+2
View File
@@ -0,0 +1,2 @@
X=abcdÉfghÍjklmnÓpqrstÚvwcyz
echo ${#X}
+43 -19
View File
@@ -1477,19 +1477,50 @@ static sighandler_t install_sighandler(int sig, sighandler_t handler)
return old_sa.sa_handler;
}
static void hush_exit(int exitcode) NORETURN;
static void fflush_and__exit(void) NORETURN;
static void restore_ttypgrp_and__exit(void) NORETURN;
static void restore_ttypgrp_and__exit(void)
{
/* xfunc has failed! die die die */
/* no EXIT traps, this is an escape hatch! */
G.exiting = 1;
hush_exit(xfunc_error_retval);
}
/* Needed only on some libc:
* It was observed that on exit(), fgetc'ed buffered data
* gets "unwound" via lseek(fd, -NUM, SEEK_CUR).
* With the net effect that even after fork(), not vfork(),
* exit() in NOEXECed applet in "sh SCRIPT":
* noexec_applet_here
* echo END_OF_SCRIPT
* lseeks fd in input FILE object from EOF to "e" in "echo END_OF_SCRIPT".
* This makes "echo END_OF_SCRIPT" executed twice.
* Similar problems can be seen with die_if_script() -> xfunc_die()
* and in `cmd` handling.
* If set as die_func(), this makes xfunc_die() exit via _exit(), not exit():
*/
static void fflush_and__exit(void)
{
fflush_all();
_exit(xfunc_error_retval);
}
#if ENABLE_HUSH_JOB
static void xfunc_has_died(void);
/* After [v]fork, in child: do not restore tty pgrp on xfunc death */
# define disable_restore_tty_pgrp_on_exit() (die_func = NULL)
# define disable_restore_tty_pgrp_on_exit() (die_func = fflush_and__exit)
/* After [v]fork, in parent: restore tty pgrp on xfunc death */
# define enable_restore_tty_pgrp_on_exit() (die_func = xfunc_has_died)
# define enable_restore_tty_pgrp_on_exit() (die_func = restore_ttypgrp_and__exit)
/* Restores tty foreground process group, and exits.
* May be called as signal handler for fatal signal
* (will resend signal to itself, producing correct exit state)
* or called directly with -EXITCODE.
* We also call it if xfunc is exiting. */
* We also call it if xfunc is exiting.
*/
static void sigexit(int sig) NORETURN;
static void sigexit(int sig)
{
@@ -1544,7 +1575,6 @@ static sighandler_t pick_sighandler(unsigned sig)
}
/* Restores tty foreground process group, and exits. */
static void hush_exit(int exitcode) NORETURN;
static void hush_exit(int exitcode)
{
#if ENABLE_FEATURE_EDITING_SAVE_ON_EXIT
@@ -1580,23 +1610,14 @@ static void hush_exit(int exitcode)
}
#endif
#if ENABLE_HUSH_JOB
fflush_all();
#if ENABLE_HUSH_JOB
sigexit(- (exitcode & 0xff));
#else
exit(exitcode);
_exit(exitcode);
#endif
}
static void xfunc_has_died(void) NORETURN;
static void xfunc_has_died(void)
{
/* xfunc has failed! die die die */
/* no EXIT traps, this is an escape hatch! */
G.exiting = 1;
hush_exit(xfunc_error_retval);
}
//TODO: return a mask of ALL handled sigs?
static int check_and_run_traps(void)
@@ -5913,7 +5934,8 @@ static FILE *generate_stream_from_string(const char *s, pid_t *pid_p)
) {
static const char *const argv[] = { NULL, NULL };
builtin_trap((char**)argv);
exit(0); /* not _exit() - we need to fflush */
fflush_all(); /* important */
_exit(0);
}
# if BB_MMU
reset_traps_to_defaults();
@@ -6466,7 +6488,8 @@ static void dump_cmd_in_x_mode(char **argv)
* Never returns.
* Don't exit() here. If you don't exec, use _exit instead.
* The at_exit handlers apparently confuse the calling process,
* in particular stdin handling. Not sure why? -- because of vfork! (vda) */
* in particular stdin handling. Not sure why? -- because of vfork! (vda)
*/
static void pseudo_exec_argv(nommu_save_t *nommu_save,
char **argv, int assignment_cnt,
char **argv_expanded) NORETURN;
@@ -7787,6 +7810,7 @@ int hush_main(int argc, char **argv)
INIT_G();
if (EXIT_SUCCESS != 0) /* if EXIT_SUCCESS == 0, it is already done */
G.last_exitcode = EXIT_SUCCESS;
#if ENABLE_HUSH_FAST
G.count_SIGCHLD++; /* ensure it is != G.handled_SIGCHLD */
#endif
@@ -7876,7 +7900,7 @@ int hush_main(int argc, char **argv)
/* Initialize some more globals to non-zero values */
cmdedit_update_prompt();
die_func = xfunc_has_died;
die_func = restore_ttypgrp_and__exit;
/* Shell is non-interactive at first. We need to call
* install_special_sighandlers() if we are going to execute "sh <script>",
+2 -1
View File
@@ -64,11 +64,12 @@ do_test()
echo -n "$1/$x:"
(
"$THIS_SH" "./$x" >"$name.xx" 2>&1
r=$?
# filter C library differences
sed -i \
-e "/: invalid option /s:'::g" \
"$name.xx"
test $? -eq 77 && rm -f "../$1-$x.fail" && exit 77
test $r -eq 77 && rm -f "../$1-$x.fail" && exit 77
diff -u "$name.xx" "$name.right" >"../$1-$x.fail" && rm -f "$name.xx" "../$1-$x.fail"
)
case $? in
+36
View File
@@ -106,6 +106,42 @@ a/a:a
a:b
" ""
testing "glibc build sort" "sort -t. -k 1,1 -k 2n,2n -k 3 input" "\
GLIBC_2.1
GLIBC_2.1.1
GLIBC_2.2
GLIBC_2.2.1
GLIBC_2.10
GLIBC_2.20
GLIBC_2.21
" "\
GLIBC_2.21
GLIBC_2.1.1
GLIBC_2.2.1
GLIBC_2.2
GLIBC_2.20
GLIBC_2.10
GLIBC_2.1
" ""
testing "glibc build sort unique" "sort -u -t. -k 1,1 -k 2n,2n -k 3 input" "\
GLIBC_2.1
GLIBC_2.1.1
GLIBC_2.2
GLIBC_2.2.1
GLIBC_2.10
GLIBC_2.20
GLIBC_2.21
" "\
GLIBC_2.10
GLIBC_2.2.1
GLIBC_2.1.1
GLIBC_2.20
GLIBC_2.2
GLIBC_2.1
GLIBC_2.21
" ""
testing "sort -u should consider field only when discarding" "sort -u -k2 input" "\
a c
" "\
+23 -1
View File
@@ -7,7 +7,7 @@
. ./testing.sh
# testing "test name" "options" "expected result" "file input" "stdin"
# testing "test name" "commands" "expected result" "file input" "stdin"
# file input will be file called "input"
# test can create a file "actual" instead of writing to stdout
@@ -30,6 +30,28 @@ testing "unzip (subdir only)" "unzip -q foo.zip foo/ && test -d foo && test ! -f
rmdir foo
rm foo.zip
# File containing some damaged encrypted stream
testing "unzip (bad archive)" "uudecode; unzip bad.zip 2>&1; echo \$?" \
"Archive: bad.zip
inflating: ]3j½r«IK-%Ix
unzip: corrupted data
unzip: inflate error
1
" \
"" "\
begin-base64 644 bad.zip
UEsDBBQAAgkIAAAAIQA5AAAANwAAADwAAAAQAAcAXTNqwr1ywqtJGxJLLSVJ
eCkBD0AdKBk8JzQsIj01JC0/ORJQSwMEFAECCAAAAAAhADoAAAAPAAAANgAA
AAwAAQASw73Ct1DCokohPXQiNjoUNTUiHRwgLT4WHlBLAQIQABQAAggIAAAA
oQA5AAAANwAAADwAAAAQQAcADAAAACwAMgCAAAAAAABdM2rCvXLCq0kbEkst
JUl4KQEPQB0oGSY4Cz4QNgEnJSYIPVBLAQIAABQAAggAAAAAIQAqAAAADwAA
BDYAAAAMAAEADQAAADIADQAAAEEAAAASw73Ct1DKokohPXQiNzA+FAI1HCcW
NzITNFBLBQUKAC4JAA04Cw0EOhZQSwUGAQAABAIAAgCZAAAAeQAAAAIALhM=
====
"
rm *
# Clean up scratch directory.
cd ..