Compare commits

...
9 Commits
Author SHA1 Message Date
Denys Vlasenko 0cf9e105e6 Bump version to 1.34.1
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-30 22:27:55 +02:00
Denys Vlasenko 0e0dd21497 awk: never return NULL from awk_printf()
function                                             old     new   delta
awk_printf                                           651     628     -23

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-30 00:15:44 +02:00
Denys Vlasenko 118baea06e awk: code shrink
function                                             old     new   delta
awk_printf                                           652     651      -1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-30 00:15:44 +02:00
Denys Vlasenko 5ec12fa657 awk: code shrink: avoid duplicate NUL checks and strlen()
function                                             old     new   delta
awk_printf                                           665     652     -13

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-30 00:15:44 +02:00
Ron Yorston 150986c922 awk: fix read beyond end of buffer
Commit 7d06d6e18 (awk: fix printf %%) can cause awk printf to read
beyond the end of a strduped buffer:

  2349      while (*f && *f != '%')
  2350          f++;
  2351      c = *++f;

If the loop terminates because a NUL character is detected the
character after the NUL is read.  This can result in failures
depending on the value of that character.

function                                             old     new   delta
awk_printf                                           672     665      -7

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-30 00:15:44 +02:00
Denys Vlasenko 3c9f559a41 chat: hopefully fix infinite spinning on input EOF
function                                             old     new   delta
chat_main                                           1295    1303      +8

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-30 00:15:44 +02:00
Daniel Thau 9ea17d5a0a awk: fix printf %%
A refactor of the awk printf code in
e2e3802987
appears to have broken the printf interpretation of two percent signs,
which normally outputs only one percent sign.

The patch below brings busybox awk printf behavior back into alignment
with the pre-e2e380 behavior, the busybox printf util, and other common
(awk and non-awk) printf implementations.

function                                             old     new   delta
awk_printf                                           626     672     +46

Signed-off-by: Daniel Thau <danthau at bedrocklinux.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-30 00:15:44 +02:00
Ron Yorston 76ef439154 ash: regressions in process substitution
Stacy Harper reports that this script:

   test() { . /tmp/bb_test; }
   echo "export TEST=foo" >/tmp/bb_test
   test 2>/dev/null
   echo "$TEST"

correctly prints 'foo' in BusyBox 1.33 but hangs in 1.34.

Bisection suggested the problem was caused by commit a1b0d3856 (ash: add
process substitution in bash-compatibility mode).  Removing the call to
unwindredir() in cmdloop() introduced in that commit makes the script
work again.

Additionally, these examples of process substitution:

   while true; do cat <(echo hi); done
   f() { while true; do cat <(echo hi); done }
   f

result in running out of file descriptors.  This is a regression from
v5 of the process substitution patch caused by changes to evalcommand()
not being transferred to v6.

function                                             old     new   delta
static.pushredir                                       -      99     +99
evalcommand                                         1729    1750     +21
exitreset                                             69      86     +17
cmdloop                                              372     365      -7
unwindredir                                           28       -     -28
pushredir                                            112       -    -112
------------------------------------------------------------------------------
(add/remove: 1/2 grow/shrink: 2/1 up/down: 137/-147)          Total: -10 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-30 00:15:33 +02:00
Denys Vlasenko 00adcdb64a udhcp: fix build breakage on MIPS
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-08-20 13:35:54 +02:00
7 changed files with 89 additions and 62 deletions

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
VERSION = 1
PATCHLEVEL = 34
SUBLEVEL = 0
SUBLEVEL = 1
EXTRAVERSION =
NAME = Unnamed
+36 -16
View File
@@ -2338,36 +2338,55 @@ static char *awk_printf(node *n, size_t *len)
b = NULL;
i = 0;
while (*f) { /* "print one format spec" loop */
while (1) { /* "print one format spec" loop */
char *s;
char c;
char sv;
var *arg;
size_t slen;
/* Find end of the next format spec, or end of line */
s = f;
while (*f && (*f != '%' || *++f == '%'))
f++;
while (*f && !isalpha(*f)) {
if (*f == '*')
syntax_error("%*x formats are not supported");
while (1) {
c = *f;
if (!c) /* no percent chars found at all */
goto nul;
f++;
if (c == '%')
break;
}
/* we are past % in "....%..." */
c = *f;
if (!c) {
/* Tail of fmt with no percent chars,
* or "....%" (percent seen, but no format specifier char found)
*/
slen = strlen(s);
goto tail;
if (!c) /* "....%" */
goto nul;
if (c == '%') { /* "....%%...." */
slen = f - s;
s = xstrndup(s, slen);
f++;
goto append; /* print "....%" part verbatim */
}
sv = *++f;
*f = '\0';
while (1) {
if (isalpha(c))
break;
if (c == '*')
syntax_error("%*x formats are not supported");
c = *++f;
if (!c) { /* "....%...." and no letter found after % */
/* Example: awk 'BEGIN { printf "^^^%^^^\n"; }' */
nul:
slen = f - s;
goto tail; /* print remaining string, exit loop */
}
}
/* we are at A in "....%...A..." */
arg = evaluate(nextarg(&n), TMPVAR);
/* Result can be arbitrarily long. Example:
* printf "%99999s", "BOOM"
*/
sv = *++f;
*f = '\0';
if (c == 'c') {
char cc = is_numeric(arg) ? getvar_i(arg) : *getvar_s(arg);
char *r = xasprintf(s, cc ? cc : '^' /* else strlen will be wrong */);
@@ -2386,13 +2405,14 @@ static char *awk_printf(node *n, size_t *len)
} else if (strchr("eEfFgGaA", c)) {
s = xasprintf(s, d);
} else {
//TODO: GNU Awk 5.0.1: printf "%W" prints "%W", does not error out
syntax_error(EMSG_INV_FMT);
}
}
slen = strlen(s);
}
*f = sv;
append:
if (i == 0) {
b = s;
i = slen;
@@ -2402,7 +2422,7 @@ static char *awk_printf(node *n, size_t *len)
b = xrealloc(b, i + slen + 1);
strcpy(b + i, s);
i += slen;
if (!c) /* tail? */
if (!c) /* s is NOT allocated and this is the last part of string? */
break;
free(s);
}
+34 -30
View File
@@ -201,6 +201,9 @@ int chat_main(int argc UNUSED_PARAM, char **argv)
DIR_RECORD,
};
#define inbuf bb_common_bufsiz1
setup_common_bufsiz();
// make x* functions fail with correct exitcode
xfunc_error_retval = ERR_IO;
@@ -361,35 +364,36 @@ int chat_main(int argc UNUSED_PARAM, char **argv)
// get reply
pfd.fd = STDIN_FILENO;
pfd.events = POLLIN;
while (!exitcode
while (exitcode == ERR_OK
&& poll(&pfd, 1, timeout) > 0
&& (pfd.revents & POLLIN)
/* && (pfd.revents & POLLIN) - may be untrue (e.g. only POLLERR set) */
) {
llist_t *l;
ssize_t delta;
#define buf bb_common_bufsiz1
setup_common_bufsiz();
// read next char from device
if (safe_read(STDIN_FILENO, buf+buf_len, 1) > 0) {
// dump device input if RECORD fname
if (record_fd > 0) {
full_write(record_fd, buf+buf_len, 1);
}
// dump device input if ECHO ON
if (echo) {
// if (buf[buf_len] < ' ') {
// full_write2_str("^");
// buf[buf_len] += '@';
// }
full_write(STDERR_FILENO, buf+buf_len, 1);
}
buf_len++;
// move input frame if we've reached higher bound
if (buf_len > COMMON_BUFSIZE) {
memmove(buf, buf+buf_len-max_len, max_len);
buf_len = max_len;
}
if (safe_read(STDIN_FILENO, inbuf + buf_len, 1) <= 0) {
exitcode = ERR_IO;
goto expect_done;
}
// dump device input if RECORD fname
if (record_fd > 0) {
full_write(record_fd, inbuf + buf_len, 1);
}
// dump device input if ECHO ON
if (echo) {
// if (inbuf[buf_len] < ' ') {
// full_write2_str("^");
// inbuf[buf_len] += '@';
// }
full_write(STDERR_FILENO, inbuf + buf_len, 1);
}
buf_len++;
// move input frame if we've reached higher bound
if (buf_len > COMMON_BUFSIZE) {
memmove(inbuf, inbuf + buf_len - max_len, max_len);
buf_len = max_len;
}
// N.B. rule of thumb: values being looked for can
// be found only at the end of input buffer
@@ -399,20 +403,20 @@ int chat_main(int argc UNUSED_PARAM, char **argv)
// abort condition is met? -> bail out
for (l = aborts, exitcode = ERR_ABORT; l; l = l->link, ++exitcode) {
size_t len = strlen(l->data);
delta = buf_len-len;
if (delta >= 0 && !memcmp(buf+delta, l->data, len))
delta = buf_len - len;
if (delta >= 0 && !memcmp(inbuf + delta, l->data, len))
goto expect_done;
}
exitcode = ERR_OK;
// expected reply received? -> goto next command
delta = buf_len - expect_len;
if (delta >= 0 && !memcmp(buf+delta, expect, expect_len))
if (delta >= 0 && memcmp(inbuf + delta, expect, expect_len) == 0)
goto expect_done;
#undef buf
} /* while (have data) */
// device timed out or unexpected reply received
// device timed out, or unexpected reply received,
// or we got a signal (poll() returned -1 with EINTR).
exitcode = ERR_TIMEOUT;
expect_done:
#if ENABLE_FEATURE_CHAT_NOFAIL
@@ -434,7 +438,7 @@ int chat_main(int argc UNUSED_PARAM, char **argv)
}
#endif
// bail out unless we expected successfully
if (exitcode)
if (exitcode != ERR_OK)
break;
//-----------------------
@@ -478,7 +482,7 @@ int chat_main(int argc UNUSED_PARAM, char **argv)
continue;
}
if ('p' == c) {
usleep(10000);
msleep(10);
len--;
continue;
}
-12
View File
@@ -304,18 +304,6 @@ void udhcp_dump_packet(struct dhcp_packet *packet) FAST_FUNC;
# define log3s(msg) ((void)0)
#endif
#if defined(__mips__)
/*
* The 'simple' message functions have a negative impact on the size of the
* DHCP code when compiled for MIPS, so don't use them in this case.
*/
#define bb_simple_info_msg bb_info_msg
#define bb_simple_error_msg bb_error_msg
#define bb_simple_perror_msg_and_die bb_perror_msg_and_die
#undef log1s
#define log1s log1
#endif
/*** Other shared functions ***/
/* 2nd param is "uint32_t*" */
+7 -3
View File
@@ -10278,6 +10278,9 @@ evalcommand(union node *cmd, int flags)
/* First expand the arguments. */
TRACE(("evalcommand(0x%lx, %d) called\n", (long)cmd, flags));
#if BASH_PROCESS_SUBST
redir_stop = redirlist;
#endif
file_stop = g_parsefile;
back_exitstatus = 0;
@@ -10356,7 +10359,11 @@ evalcommand(union node *cmd, int flags)
lastarg = nargv[-1];
expredir(cmd->ncmd.redirect);
#if !BASH_PROCESS_SUBST
redir_stop = pushredir(cmd->ncmd.redirect);
#else
pushredir(cmd->ncmd.redirect);
#endif
preverrout_fd = 2;
if (BASH_XTRACEFD && xflag) {
/* NB: bash closes fd == $BASH_XTRACEFD when it is changed.
@@ -13476,9 +13483,6 @@ cmdloop(int top)
#if JOBS
if (doing_jobctl)
showjobs(SHOW_CHANGED|SHOW_STDERR);
#endif
#if BASH_PROCESS_SUBST
unwindredir(NULL);
#endif
inter = 0;
if (iflag && top) {
+6
View File
@@ -463,4 +463,10 @@ testing "awk \"cmd\" | getline" \
"HELLO\n" \
'' ''
# printf %% should print one % (had a bug where it didn't)
testing 'awk printf %% prints one %' \
"awk 'BEGIN { printf \"%%\n\" }'" \
"%\n" \
'' ''
exit $FAILCOUNT
+5
View File
@@ -79,6 +79,11 @@ testing "printf understands %Ld" \
"-5\n""0\n" \
"" ""
testing "printf understands %%" \
"${bb}printf '%%\n' 2>&1; echo \$?" \
"%\n""0\n" \
"" ""
testing "printf handles positive numbers for %d" \
"${bb}printf '%d\n' 3 +3 ' 3' ' +3' 2>&1; echo \$?" \
"3\n"\