Compare commits

...
12 Commits
Author SHA1 Message Date
Denys Vlasenko 1a64f6a20a Bump version to 1.36.1
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-19 00:31:04 +02:00
Akos Somfai 38d2d26a5f lineedit: fix crash when icanon set with -echo
When icanon is set with -echo (e.g. ssh from an emacs shell) then
S.state will remain null but later it will be deferenced causing ash to
crash. Fix: additional check on state.

Signed-off-by: Akos Somfai <akos.somfai@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-25 16:47:22 +02:00
Denys Vlasenko 384cd2e436 sleep: fix error exit when called as "sh" builtin
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-25 16:47:22 +02:00
Denys Vlasenko ce839dea92 ash: fix sleep built-in not running INT trap immediately on ^C
function                                             old     new   delta
sleep_for_duration                                   169     149     -20

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-25 16:47:22 +02:00
Denys Vlasenko d661cb1977 ash: sleep builtin with no arguments should not exit
function                                             old     new   delta
sleep_main                                           116     143     +27
.rodata                                           105245  105268     +23
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 50/0)               Total: 50 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-25 16:47:22 +02:00
Denys Vlasenko 515adcc9f3 hush: printf builtin with no arguments should not exit
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-25 16:47:22 +02:00
Denys Vlasenko 90f5f2a190 ash: fix still-broken new mail detection
padvance() exit condition is return value < 0, not == 0.
After MAIL changing twice, the logic erroneously
concluded that "you have new mail".

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-25 16:47:22 +02:00
Denys Vlasenko 07bc5de67b ash: fix broken new mail detection
Mea culpa, in "Do not allocate stack string in padvance" commit
(I left an extraneous "break" statement).

function                                             old     new   delta
cmdloop                                              329     398     +69

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-25 16:47:22 +02:00
Ron Yorston 64e967fabb lineedit: fix matching of directories when searching PATH
Commit 8baa643a3 (lineedit: match local directories when searching
PATH) included subdirectories of the current directory in the search
when tab-completing commands.

Unfortunately a short time later commit 1d180cd74 (lineedit: use
strncmp instead of is_prefixed_with (we know the length)) broke
this feature by returning an incorrect length for the array of paths.

Fix the length and reinstate matching of subdirectories.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-25 16:47:22 +02:00
Denys Vlasenko 8d198665a0 libbb/sha: fix sha-NI instruction detection
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-03-29 15:50:40 +02:00
Denys Vlasenko c0bb90e2fe unzip: clear SUID/GID bits, implement -K to not clear them
function                                             old     new   delta
unzip_main                                          2656    2715     +59
packed_usage                                       34517   34552     +35
.rodata                                           105250  105251      +1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 95/0)               Total: 95 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-03-28 17:42:00 +02:00
Sören Tempel f15dfd86c4 ed: don't use memcpy with overlapping memory regions
The memcpy invocations in the subCommand function, modified by this
commit, previously used memcpy with overlapping memory regions. This is
undefined behavior. On Alpine Linux, it causes BusyBox ed to crash since
we compile BusyBox with -D_FORTIFY_SOURCE=2 and our fortify-headers
implementation catches this source of undefined behavior [0]. The issue
can only be triggered if the replacement string is the same size or
shorter than the old string.

Looking at the code, it seems to me that a memmove(3) is what was
actually intended here, this commit modifies the code accordingly.

[0]: https://gitlab.alpinelinux.org/alpine/aports/-/issues/13504

Signed-off-by: Sören Tempel <soeren+git@soeren-tempel.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-05 16:26:49 +01:00
10 changed files with 48 additions and 28 deletions

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
VERSION = 1
PATCHLEVEL = 36
SUBLEVEL = 0
SUBLEVEL = 1
EXTRAVERSION =
NAME = Unnamed
+12 -3
View File
@@ -56,7 +56,7 @@
//kbuild:lib-$(CONFIG_UNZIP) += unzip.o
//usage:#define unzip_trivial_usage
//usage: "[-lnojpq] FILE[.zip] [FILE]... [-x FILE]... [-d DIR]"
//usage: "[-lnojpqK] FILE[.zip] [FILE]... [-x FILE]... [-d DIR]"
//usage:#define unzip_full_usage "\n\n"
//usage: "Extract FILEs from ZIP archive\n"
//usage: "\n -l List contents (with -q for short form)"
@@ -66,6 +66,7 @@
//usage: "\n -p Write to stdout"
//usage: "\n -t Test"
//usage: "\n -q Quiet"
//usage: "\n -K Do not clear SUID bit"
//usage: "\n -x FILE Exclude FILEs"
//usage: "\n -d DIR Extract into DIR"
@@ -494,6 +495,7 @@ int unzip_main(int argc, char **argv)
OPT_l = (1 << 0),
OPT_x = (1 << 1),
OPT_j = (1 << 2),
OPT_K = (1 << 3),
};
unsigned opts;
smallint quiet = 0;
@@ -559,7 +561,7 @@ int unzip_main(int argc, char **argv)
opts = 0;
/* '-' makes getopt return 1 for non-options */
while ((i = getopt(argc, argv, "-d:lnotpqxjv")) != -1) {
while ((i = getopt(argc, argv, "-d:lnotpqxjvK")) != -1) {
switch (i) {
case 'd': /* Extract to base directory */
base_dir = optarg;
@@ -602,6 +604,10 @@ int unzip_main(int argc, char **argv)
opts |= OPT_j;
break;
case 'K':
opts |= OPT_K;
break;
case 1:
if (!src_fn) {
/* The zip file */
@@ -819,7 +825,10 @@ int unzip_main(int argc, char **argv)
# endif
if ((cdf.fmt.version_made_by >> 8) == 3) {
/* This archive is created on Unix */
dir_mode = file_mode = (cdf.fmt.external_attributes >> 16);
file_mode = (cdf.fmt.external_attributes >> 16);
if (!(opts & OPT_K))
file_mode &= ~(mode_t)(S_ISUID | S_ISGID);
dir_mode = file_mode;
}
}
#endif
+1 -1
View File
@@ -428,7 +428,7 @@ int printf_main(int argc UNUSED_PARAM, char **argv)
if (argv[1] && argv[1][0] == '-' && argv[1][1] == '-' && !argv[1][2])
argv++;
if (!argv[1]) {
if (ENABLE_ASH_PRINTF
if ((ENABLE_ASH_PRINTF || ENABLE_HUSH_PRINTF)
&& applet_name[0] != 'p'
) {
bb_simple_error_msg("usage: printf FORMAT [ARGUMENT...]");
+15 -1
View File
@@ -65,15 +65,29 @@ int sleep_main(int argc UNUSED_PARAM, char **argv)
{
duration_t duration;
/* Note: sleep_main may be directly called from ash as a builtin.
* This brings some complications:
* + we can't use xfunc here
* + we can't use bb_show_usage
* + applet_name can be the name of the shell
*/
++argv;
if (!*argv)
if (!*argv) {
/* Without this, bare "sleep" in ash shows _ash_ --help */
/* (ash can be the "sh" applet as well, so check 2nd char) */
if (ENABLE_ASH_SLEEP && applet_name[1] != 'l') {
bb_simple_error_msg("sleep: missing operand");
return EXIT_FAILURE;
}
bb_show_usage();
}
/* GNU sleep accepts "inf", "INF", "infinity" and "INFINITY" */
if (strncasecmp(argv[0], "inf", 3) == 0)
for (;;)
sleep(INT_MAX);
//FIXME: in ash, "sleep 123qwerty" as a builtin aborts the shell
#if ENABLE_FEATURE_FANCY_SLEEP
duration = 0;
do {
+1 -1
View File
@@ -720,7 +720,7 @@ static void subCommand(const char *cmd, int num1, int num2)
if (deltaLen <= 0) {
memcpy(&lp->data[offset], newStr, newLen);
if (deltaLen) {
memcpy(&lp->data[offset + newLen],
memmove(&lp->data[offset + newLen],
&lp->data[offset + oldLen],
lp->len - offset - oldLen);
+7 -9
View File
@@ -76,16 +76,14 @@ void FAST_FUNC sleep_for_duration(duration_t duration)
ts.tv_sec = duration;
ts.tv_nsec = (duration - ts.tv_sec) * 1000000000;
}
/* NB: if ENABLE_ASH_SLEEP, we end up here if "sleep N"
* is run in ash. ^C will still work, because ash's signal handler
* does not return (it longjumps), the below loop
* will not continue looping.
* (This wouldn't work in hush)
/* NB: ENABLE_ASH_SLEEP requires that we do NOT loop on EINTR here:
* otherwise, traps won't execute until we finish looping.
*/
do {
errno = 0;
nanosleep(&ts, &ts);
} while (errno == EINTR);
//do {
// errno = 0;
// nanosleep(&ts, &ts);
//} while (errno == EINTR);
nanosleep(&ts, &ts);
}
#else
duration_t FAST_FUNC parse_duration_str(char *str)
+2 -2
View File
@@ -1178,7 +1178,7 @@ void FAST_FUNC sha1_begin(sha1_ctx_t *ctx)
if (!shaNI) {
unsigned eax = 7, ebx = ebx, ecx = 0, edx = edx;
cpuid(&eax, &ebx, &ecx, &edx);
shaNI = ((ebx >> 29) << 1) - 1;
shaNI = ((ebx >> 28) & 2) - 1; /* bit 29 -> 1 or -1 */
}
if (shaNI > 0)
ctx->process_block = sha1_process_block64_shaNI;
@@ -1232,7 +1232,7 @@ void FAST_FUNC sha256_begin(sha256_ctx_t *ctx)
if (!shaNI) {
unsigned eax = 7, ebx = ebx, ecx = 0, edx = edx;
cpuid(&eax, &ebx, &ecx, &edx);
shaNI = ((ebx >> 29) << 1) - 1;
shaNI = ((ebx >> 28) & 2) - 1; /* bit 29 -> 1 or -1 */
}
if (shaNI > 0)
ctx->process_block = sha256_process_block64_shaNI;
+4 -4
View File
@@ -254,7 +254,7 @@ static NOINLINE const char *get_homedir_or_NULL(void)
const char *home;
# if ENABLE_SHELL_ASH || ENABLE_SHELL_HUSH
home = state->sh_get_var ? state->sh_get_var("HOME") : getenv("HOME");
home = state && state->sh_get_var ? state->sh_get_var("HOME") : getenv("HOME");
# else
home = getenv("HOME");
# endif
@@ -825,8 +825,8 @@ static unsigned path_parse(char ***p)
res[npth++] = tmp;
}
/* special case: "match subdirectories of the current directory" */
/*res[npth++] = NULL; - filled by xzalloc() */
return npth;
/*res[npth] = NULL; - filled by xzalloc() */
return npth + 1;
}
/* Complete command, directory or file name.
@@ -2038,7 +2038,7 @@ static void parse_and_put_prompt(const char *prmt_ptr)
if (!cwd_buf) {
const char *home;
# if EDITING_HAS_sh_get_var
cwd_buf = state->sh_get_var
cwd_buf = state && state->sh_get_var
? xstrdup(state->sh_get_var("PWD"))
: xrealloc_getcwd_or_warn(NULL);
# else
+1 -1
View File
@@ -85,8 +85,8 @@
* This brings some complications:
*
* + we can't use xfunc here
* + we can't use applet_name
* + we can't use bb_show_usage
* + applet_name can be the name of the shell
* (doesn't apply for killall[5], still should be careful b/c NOFORK)
*
* kill %n gets translated into kill ' -<process group>' by shell (note space!)
+4 -5
View File
@@ -11264,8 +11264,8 @@ static smallint mail_var_path_changed;
/*
* Print appropriate message(s) if mail has arrived.
* If mail_var_path_changed is set,
* then the value of MAIL has mail_var_path_changed,
* so we just update the values.
* then the value of MAIL has changed,
* so we just update the hash value.
*/
static void
chkmail(void)
@@ -11284,10 +11284,9 @@ chkmail(void)
int len;
len = padvance_magic(&mpath, nullstr, 2);
if (!len)
if (len < 0)
break;
p = stackblock();
break;
if (*p == '\0')
continue;
for (q = p; *q; q++)
@@ -11306,8 +11305,8 @@ chkmail(void)
if (!mail_var_path_changed && mailtime_hash != new_hash) {
if (mailtime_hash != 0)
out2str("you have mail\n");
mailtime_hash = new_hash;
}
mailtime_hash = new_hash;
mail_var_path_changed = 0;
popstackmark(&smark);
}