Compare commits
10
Commits
1_24_2
...
1_24_stable
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b03007455c | ||
|
|
ca26f1c238 | ||
|
|
8191abd146 | ||
|
|
c1565a04f2 | ||
|
|
acad7392ee | ||
|
|
4c07ad9130 | ||
|
|
856af4e3dc | ||
|
|
4194c28753 | ||
|
|
3a76bb5136 | ||
|
|
3c4de6e36c |
No files matched your search
+3
-1
@@ -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)
|
||||
|
||||
+1
-1
@@ -2196,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) {
|
||||
|
||||
@@ -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).
|
||||
*/
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
-44
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
/ash
|
||||
/printenv
|
||||
/recho
|
||||
/zecho
|
||||
|
||||
/*.fail
|
||||
*.xx
|
||||
@@ -0,0 +1,2 @@
|
||||
bar
|
||||
bar
|
||||
Executable
+7
@@ -0,0 +1,7 @@
|
||||
foo () {
|
||||
cat <<EOF && { echo "$1" ; }
|
||||
$1
|
||||
EOF
|
||||
}
|
||||
|
||||
foo "bar"
|
||||
@@ -0,0 +1 @@
|
||||
hello
|
||||
Executable
+9
@@ -0,0 +1,9 @@
|
||||
echo hello >greeting
|
||||
cat <<EOF &&
|
||||
$(cat greeting)
|
||||
EOF
|
||||
{
|
||||
echo $?
|
||||
cat greeting
|
||||
} >/dev/null
|
||||
rm greeting
|
||||
@@ -0,0 +1 @@
|
||||
26
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
X=abcdÉfghÍjklmnÓpqrstÚvwcyz
|
||||
echo ${#X}
|
||||
+43
-19
@@ -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>",
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user