From vda.linux at googlemail.com Sun May 1 00:06:20 2022 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Sun, 1 May 2022 02:06:20 +0200 Subject: [git commit] seedrng: do not hash lengths, they are very predictable Message-ID: <20220501001126.52C2784BDC@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=74716580380d609165cc0be1ae37ee52d77243b2 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta seedrng_main 982 930 -52 Signed-off-by: Denys Vlasenko --- util-linux/seedrng.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/util-linux/seedrng.c b/util-linux/seedrng.c index 3074e9a58..2965f3d47 100644 --- a/util-linux/seedrng.c +++ b/util-linux/seedrng.c @@ -151,7 +151,8 @@ static void seed_from_file_if_exists(const char *filename, int dfd, bool credit, */ fsync(dfd); - sha256_hash(hash, &seed_len, sizeof(seed_len)); +//Length is not random, and taking its address spills variable to stack +// sha256_hash(hash, &seed_len, sizeof(seed_len)); sha256_hash(hash, seed, seed_len); printf("Seeding %u bits %s crediting\n", (unsigned)seed_len * 8, credit ? "and" : "without"); @@ -220,7 +221,8 @@ int seedrng_main(int argc UNUSED_PARAM, char *argv[]) new_seed_len = determine_optimal_seed_len(); new_seed_creditable = read_new_seed(new_seed, new_seed_len); - sha256_hash(&hash, &new_seed_len, sizeof(new_seed_len)); +//Length is not random, and taking its address spills variable to stack +// sha256_hash(&hash, &new_seed_len, sizeof(new_seed_len)); sha256_hash(&hash, new_seed, new_seed_len); sha256_end(&hash, new_seed + new_seed_len - SHA256_OUTSIZE); @@ -230,7 +232,7 @@ int seedrng_main(int argc UNUSED_PARAM, char *argv[]) xwrite(fd, new_seed, new_seed_len); if (new_seed_creditable) { /* More paranoia when we create a file which we believe contains - * genuine entropy: make sure disk is not full, quota was't esceeded, etc: + * genuine entropy: make sure disk is not full, quota was't exceeded, etc: */ if (fsync(fd) < 0) bb_perror_msg_and_die("can't write '%s'", NON_CREDITABLE_SEED_NAME); From vda.linux at googlemail.com Sun May 1 14:37:39 2022 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Sun, 1 May 2022 16:37:39 +0200 Subject: [git commit] seedrng: reduce MAX_SEED_LEN from 512 to 256 Message-ID: <20220501145552.1F60884C4E@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=b5624be6df95fd26d19051af5d02001bbe8f2dd8 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master As proposed by Jason. getrandom() is more likely to block on reads larger than this. Signed-off-by: Denys Vlasenko --- util-linux/seedrng.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/util-linux/seedrng.c b/util-linux/seedrng.c index 2965f3d47..04e52a996 100644 --- a/util-linux/seedrng.c +++ b/util-linux/seedrng.c @@ -56,7 +56,11 @@ enum { MIN_SEED_LEN = SHA256_OUTSIZE, - MAX_SEED_LEN = 512 + /* kernels < 5.18 could return short reads from getrandom() + * if signal is pending and length is > 256. + * Let's limit our reads to 256 bytes. + */ + MAX_SEED_LEN = 256, }; static size_t determine_optimal_seed_len(void) From vda.linux at googlemail.com Sun May 1 14:51:06 2022 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Sun, 1 May 2022 16:51:06 +0200 Subject: [git commit] seedrng: shorten --help, assorted small cleanups Message-ID: <20220501145552.2B16684BD8@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=54867fec12e23a0606fd74e999ee30e34eea6a74 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta packed_usage 34295 34290 -5 Signed-off-by: Denys Vlasenko --- util-linux/seedrng.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/util-linux/seedrng.c b/util-linux/seedrng.c index 04e52a996..390dec12a 100644 --- a/util-linux/seedrng.c +++ b/util-linux/seedrng.c @@ -19,9 +19,8 @@ * * This is based on code from . */ - //config:config SEEDRNG -//config: bool "seedrng (2 kb)" +//config: bool "seedrng (1.3 kb)" //config: default y //config: help //config: Seed the kernel RNG from seed files, meant to be called @@ -33,12 +32,12 @@ //kbuild:lib-$(CONFIG_SEEDRNG) += seedrng.o //usage:#define seedrng_trivial_usage -//usage: "[-d SEED_DIRECTORY] [-n]" +//usage: "[-d DIR] [-n]" //usage:#define seedrng_full_usage "\n\n" //usage: "Seed the kernel RNG from seed files" //usage: "\n" -//usage: "\n -d DIR Use seed files from DIR (default: /var/lib/seedrng)" -//usage: "\n -n Skip crediting seeds, even if creditable" +//usage: "\n -d DIR Use seed files in DIR (default: /var/lib/seedrng)" +//usage: "\n -n Do not credit randomness, even if creditable" #include "libbb.h" @@ -50,8 +49,8 @@ #define GRND_INSECURE 0x0004 /* Apparently some headers don't ship with this yet. */ #endif -#define DEFAULT_SEED_DIR "/var/lib/seedrng" -#define CREDITABLE_SEED_NAME "seed.credit" +#define DEFAULT_SEED_DIR "/var/lib/seedrng" +#define CREDITABLE_SEED_NAME "seed.credit" #define NON_CREDITABLE_SEED_NAME "seed.no-credit" enum { @@ -75,7 +74,7 @@ static size_t determine_optimal_seed_len(void) return MIN_SEED_LEN; } poolsize_str[n] = '\0'; - poolsize = (bb_strtoul(poolsize_str, NULL, 10) + 7) / 8; + poolsize = (bb_strtou(poolsize_str, NULL, 10) + 7) / 8; return MAX(MIN(poolsize, MAX_SEED_LEN), MIN_SEED_LEN); } @@ -164,8 +163,8 @@ static void seed_from_file_if_exists(const char *filename, int dfd, bool credit, } } -int seedrng_main(int argc, char *argv[]) MAIN_EXTERNALLY_VISIBLE; -int seedrng_main(int argc UNUSED_PARAM, char *argv[]) +int seedrng_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; +int seedrng_main(int argc UNUSED_PARAM, char **argv) { const char *seed_dir; int fd, dfd; @@ -236,7 +235,7 @@ int seedrng_main(int argc UNUSED_PARAM, char *argv[]) xwrite(fd, new_seed, new_seed_len); if (new_seed_creditable) { /* More paranoia when we create a file which we believe contains - * genuine entropy: make sure disk is not full, quota was't exceeded, etc: + * genuine entropy: make sure disk is not full, quota isn't exceeded, etc: */ if (fsync(fd) < 0) bb_perror_msg_and_die("can't write '%s'", NON_CREDITABLE_SEED_NAME); From vda.linux at googlemail.com Sun May 1 15:02:20 2022 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Sun, 1 May 2022 17:02:20 +0200 Subject: [git commit] seedrng: manually inline seed_rng Message-ID: <20220501145552.3549484C52@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=a157c4c978d3e984f3cb7e2fc02d5ce428d5f82e branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master We can now remove a separate buffer function old new delta seedrng_main 930 884 -46 Signed-off-by: Bernhard Reutner-Fischer Signed-off-by: Denys Vlasenko --- util-linux/seedrng.c | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/util-linux/seedrng.c b/util-linux/seedrng.c index 390dec12a..8c81835f6 100644 --- a/util-linux/seedrng.c +++ b/util-linux/seedrng.c @@ -112,31 +112,16 @@ static bool read_new_seed(uint8_t *seed, size_t len) return is_creditable; } -static void seed_rng(uint8_t *seed, size_t len, bool credit) +static void seed_from_file_if_exists(const char *filename, int dfd, bool credit, sha256_ctx_t *hash) { struct { int entropy_count; int buf_size; - uint8_t buffer[MAX_SEED_LEN]; + uint8_t buf[MAX_SEED_LEN]; } req; - int random_fd; - - req.entropy_count = credit ? len * 8 : 0; - req.buf_size = len; - memcpy(req.buffer, seed, len); - - random_fd = xopen("/dev/urandom", O_RDONLY); - xioctl(random_fd, RNDADDENTROPY, &req); - if (ENABLE_FEATURE_CLEAN_UP) - close(random_fd); -} - -static void seed_from_file_if_exists(const char *filename, int dfd, bool credit, sha256_ctx_t *hash) -{ - uint8_t seed[MAX_SEED_LEN]; ssize_t seed_len; - seed_len = open_read_close(filename, seed, sizeof(seed)); + seed_len = open_read_close(filename, req.buf, sizeof(req.buf)); if (seed_len < 0) { if (errno != ENOENT) bb_perror_msg_and_die("can't read '%s'", filename); @@ -144,6 +129,8 @@ static void seed_from_file_if_exists(const char *filename, int dfd, bool credit, } xunlink(filename); if (seed_len != 0) { + int fd; + /* We are going to use this data to seed the RNG: * we believe it to genuinely containing entropy. * If this just-unlinked file survives @@ -156,10 +143,17 @@ static void seed_from_file_if_exists(const char *filename, int dfd, bool credit, //Length is not random, and taking its address spills variable to stack // sha256_hash(hash, &seed_len, sizeof(seed_len)); - sha256_hash(hash, seed, seed_len); + sha256_hash(hash, req.buf, seed_len); + + req.buf_size = seed_len; + seed_len *= 8; + req.entropy_count = credit ? seed_len : 0; printf("Seeding %u bits %s crediting\n", - (unsigned)seed_len * 8, credit ? "and" : "without"); - seed_rng(seed, seed_len, credit); + (unsigned)seed_len, credit ? "and" : "without"); + fd = xopen("/dev/urandom", O_RDONLY); + xioctl(fd, RNDADDENTROPY, &req); + if (ENABLE_FEATURE_CLEAN_UP) + close(fd); } } From vda.linux at googlemail.com Sun May 1 15:06:00 2022 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Sun, 1 May 2022 17:06:00 +0200 Subject: [git commit] style fix Message-ID: <20220501145552.4038484C4E@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=9b6f44e0403f9214343bdafd054a628aa1506630 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master Signed-off-by: Denys Vlasenko --- examples/shutdown-1.0/script/hardshutdown.c | 2 +- libbb/appletlib.c | 2 +- networking/httpd_indexcgi.c | 2 +- networking/httpd_ssi.c | 2 +- printutils/lpd.c | 4 ++-- printutils/lpr.c | 4 ++-- shell/match.c | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/shutdown-1.0/script/hardshutdown.c b/examples/shutdown-1.0/script/hardshutdown.c index c21ddad58..b4af26f0f 100644 --- a/examples/shutdown-1.0/script/hardshutdown.c +++ b/examples/shutdown-1.0/script/hardshutdown.c @@ -102,7 +102,7 @@ enum action_t { REBOOT }; -int main(int argc, char *argv[]) +int main(int argc, char **argv) { struct timespec t = {0,0}; enum action_t action = SHUTDOWN; diff --git a/libbb/appletlib.c b/libbb/appletlib.c index 841b3b873..d8ab2a450 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c @@ -762,7 +762,7 @@ get_script_content(unsigned n) //usage:#define busybox_trivial_usage NOUSAGE_STR //usage:#define busybox_full_usage "" //applet:IF_BUSYBOX(IF_FEATURE_SH_STANDALONE(IF_FEATURE_TAB_COMPLETION(APPLET(busybox, BB_DIR_BIN, BB_SUID_MAYBE)))) -int busybox_main(int argc, char *argv[]) MAIN_EXTERNALLY_VISIBLE; +int busybox_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; # else # define busybox_main(argc,argv) busybox_main(argv) static diff --git a/networking/httpd_indexcgi.c b/networking/httpd_indexcgi.c index 47b1159f4..edaaad566 100644 --- a/networking/httpd_indexcgi.c +++ b/networking/httpd_indexcgi.c @@ -211,7 +211,7 @@ static void fmt_04u(/*char *dst,*/ unsigned n) fmt_02u(n % 100); } -int main(int argc, char *argv[]) +int main(int argc, char **argv) { dir_list_t *dir_list; dir_list_t *cdir; diff --git a/networking/httpd_ssi.c b/networking/httpd_ssi.c index 4bd9a6d97..620b96332 100644 --- a/networking/httpd_ssi.c +++ b/networking/httpd_ssi.c @@ -143,7 +143,7 @@ static void process_includes(const char *filename) fclose(fp); } -int main(int argc, char *argv[]) +int main(int argc, char **argv) { if (!argv[1]) return 1; diff --git a/printutils/lpd.c b/printutils/lpd.c index e48feef90..34e5ea209 100644 --- a/printutils/lpd.c +++ b/printutils/lpd.c @@ -114,8 +114,8 @@ static char *xmalloc_read_stdin(void) return xmalloc_reads(STDIN_FILENO, &max); } -int lpd_main(int argc, char *argv[]) MAIN_EXTERNALLY_VISIBLE; -int lpd_main(int argc UNUSED_PARAM, char *argv[]) +int lpd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; +int lpd_main(int argc UNUSED_PARAM, char **argv) { int spooling = spooling; // for compiler char *s, *queue; diff --git a/printutils/lpr.c b/printutils/lpr.c index 77d1a79a4..d40d0a67c 100644 --- a/printutils/lpr.c +++ b/printutils/lpr.c @@ -78,8 +78,8 @@ static void get_response_or_say_and_die(int fd, const char *errmsg) } } -int lpqr_main(int argc, char *argv[]) MAIN_EXTERNALLY_VISIBLE; -int lpqr_main(int argc UNUSED_PARAM, char *argv[]) +int lpqr_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; +int lpqr_main(int argc UNUSED_PARAM, char **argv) { enum { OPT_P = 1 << 0, // -P queue[@host[:port]]. If no -P is given use $PRINTER, then "lp at localhost:515" diff --git a/shell/match.c b/shell/match.c index 90f77546d..8024f2747 100644 --- a/shell/match.c +++ b/shell/match.c @@ -95,7 +95,7 @@ char* FAST_FUNC scan_and_match(char *string, const char *pattern, unsigned flags } #ifdef STANDALONE -int main(int argc, char *argv[]) +int main(int argc, char **argv) { char *string; char *op; From vda.linux at googlemail.com Mon May 2 10:28:48 2022 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Mon, 2 May 2022 12:28:48 +0200 Subject: [git commit] crond: implement support for setting PATH in crontab files Message-ID: <20220502101852.EDAC084C4D@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=52a7bf6fa677abdb80f8e484f6ba77ed3d34e444 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master It's very inconvenient for a cron user not to be able to set a "personal" PATH for their cron jobs, as is possible with other crons function old new delta load_crontab 868 942 +74 .rodata 104878 104884 +6 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 80/0) Total: 80 bytes Signed-off-by: Paul Fox Signed-off-by: Denys Vlasenko --- miscutils/crond.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/miscutils/crond.c b/miscutils/crond.c index 1965af656..bd43c6b68 100644 --- a/miscutils/crond.c +++ b/miscutils/crond.c @@ -125,6 +125,7 @@ typedef struct CronLine { char *cl_mailto; /* whom to mail results, may be NULL */ #endif char *cl_shell; + char *cl_path; /* ordered by size, not in natural order. makes code smaller: */ char cl_Dow[7]; /* 0-6, beginning sunday */ char cl_Mons[12]; /* 0-11 */ @@ -421,6 +422,7 @@ static void load_crontab(const char *fileName) char *mailTo = NULL; #endif char *shell = NULL; + char *path = NULL; delete_cronfile(fileName); @@ -470,7 +472,12 @@ static void load_crontab(const char *fileName) shell = xstrdup(&tokens[0][6]); continue; } -//TODO: handle HOME= too? "man crontab" says: + if (is_prefixed_with(tokens[0], "PATH=")) { + free(path); + path = xstrdup(&tokens[0][5]); + continue; + } +//TODO: handle HOME= too? Better yet, handle arbitrary ENVVARs? "man crontab" says: //name = value // //where the spaces around the equal-sign (=) are optional, and any subsequent @@ -480,8 +487,8 @@ static void load_crontab(const char *fileName) // //Several environment variables are set up automatically by the cron(8) daemon. //SHELL is set to /bin/sh, and LOGNAME and HOME are set from the /etc/passwd -//line of the crontab's owner. HOME and SHELL may be overridden by settings -//in the crontab; LOGNAME may not. +//line of the crontab's owner. HOME, SHELL, and PATH may be overridden by +//settings in the crontab; LOGNAME may not. #if ENABLE_FEATURE_CROND_SPECIAL_TIMES if (tokens[0][0] == '@') { @@ -567,6 +574,7 @@ static void load_crontab(const char *fileName) line->cl_mailto = xstrdup(mailTo); #endif line->cl_shell = xstrdup(shell); + line->cl_path = xstrdup(path); /* copy command */ line->cl_cmd = xstrdup(tokens[5]); pline = &line->cl_next; @@ -653,21 +661,22 @@ static void safe_setenv(char **pvar_val, const char *var, const char *val) } #endif -static void set_env_vars(struct passwd *pas, const char *shell) +static void set_env_vars(struct passwd *pas, const char *shell, const char *path) { /* POSIX requires crond to set up at least HOME, LOGNAME, PATH, SHELL. - * We assume crond inherited suitable PATH. */ #if SETENV_LEAKS safe_setenv(&G.env_var_logname, "LOGNAME", pas->pw_name); safe_setenv(&G.env_var_user, "USER", pas->pw_name); safe_setenv(&G.env_var_home, "HOME", pas->pw_dir); safe_setenv(&G.env_var_shell, "SHELL", shell); + if (path) safe_setenv(&G.env_var_shell, "PATH", path); #else xsetenv("LOGNAME", pas->pw_name); xsetenv("USER", pas->pw_name); xsetenv("HOME", pas->pw_dir); xsetenv("SHELL", shell); + if (path) xsetenv("PATH", path); #endif } @@ -701,7 +710,7 @@ fork_job(const char *user, int mailFd, CronLine *line, bool run_sendmail) shell = line->cl_shell ? line->cl_shell : G.default_shell; prog = run_sendmail ? SENDMAIL : shell; - set_env_vars(pas, shell); + set_env_vars(pas, shell, NULL); /* don't use crontab's PATH for sendmail */ sv_logmode = logmode; pid = vfork(); @@ -845,7 +854,7 @@ static pid_t start_one_job(const char *user, CronLine *line) /* Prepare things before vfork */ shell = line->cl_shell ? line->cl_shell : G.default_shell; - set_env_vars(pas, shell); + set_env_vars(pas, shell, line->cl_path); /* Fork as the user in question and run program */ pid = vfork(); From vda.linux at googlemail.com Mon May 2 12:25:36 2022 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Mon, 2 May 2022 14:25:36 +0200 Subject: [git commit] tsort: new applet Message-ID: <20220502121609.4356C84D90@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=4642cf5b388bf60f6bea67ce3a5031d24bccd48a branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta tsort_main - 578 +578 .rodata 104884 104906 +22 applet_names 2759 2765 +6 applet_main 1596 1600 +4 packed_usage 34290 34288 -2 ------------------------------------------------------------------------------ (add/remove: 2/0 grow/shrink: 3/1 up/down: 610/-2) Total: 608 bytes Signed-off-by: David Leonard Signed-off-by: Denys Vlasenko --- coreutils/tsort.c | 188 +++++++++++++++++++++++++++++++++++++++++++++ docs/posix_conformance.txt | 2 +- testsuite/tsort.tests | 110 ++++++++++++++++++++++++++ 3 files changed, 299 insertions(+), 1 deletion(-) diff --git a/coreutils/tsort.c b/coreutils/tsort.c new file mode 100644 index 000000000..dedb65b15 --- /dev/null +++ b/coreutils/tsort.c @@ -0,0 +1,188 @@ +/* vi: set sw=4 ts=4: */ +/* + * tsort implementation for busybox + * + * public domain -- David Leonard, 2022 + */ +//config:config TSORT +//config: bool "tsort (0.7 kb)" +//config: default y +//config: help +//config: tsort performs a topological sort. + +//applet:IF_TSORT(APPLET(tsort, BB_DIR_USR_BIN, BB_SUID_DROP)) + +//kbuild:lib-$(CONFIG_TSORT) += tsort.o + +/* BB_AUDIT SUSv3 compliant */ +/* http://www.opengroup.org/onlinepubs/007904975/utilities/tsort.html */ + +//usage:#define tsort_trivial_usage +//usage: "[FILE]" +//usage:#define tsort_full_usage "\n\n" +//usage: "Topological sort" +//usage:#define tsort_example_usage +//usage: "$ echo -e \"a b\\nb c\" | tsort\n" +//usage: "a\n" +//usage: "b\n" +//usage: "c\n" + +#include "libbb.h" +#include "common_bufsiz.h" + +struct node { + unsigned in_count; + unsigned out_count; + struct node **out; + char name[1]; +}; + +struct globals { + struct node **nodes; + unsigned nodes_len; +}; +#define G (*(struct globals*)bb_common_bufsiz1) +#define INIT_G() do { \ + setup_common_bufsiz(); \ + BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ + G.nodes = NULL; \ + G.nodes_len = 0; \ +} while (0) + +static struct node * +get_node(const char *name) +{ + struct node *n; + unsigned a = 0; + unsigned b = G.nodes_len; + + /* Binary search for name */ + while (a != b) { + unsigned m = (a + b) / 2; + int cmp = strcmp(name, G.nodes[m]->name); + if (cmp == 0) + return G.nodes[m]; /* found */ + if (cmp < 0) { + b = m; + } else { + a = m + 1; + } + } + + /* Allocate new node */ + n = xzalloc(sizeof(*n) + strlen(name)); + //n->in_count = 0; + //n->out_count = 0; + //n->out = NULL; + strcpy(n->name, name); + + /* Insert to maintain sort */ + G.nodes = xrealloc(G.nodes, (G.nodes_len + 1) * sizeof(*G.nodes)); + memmove(&G.nodes[a + 1], &G.nodes[a], + (G.nodes_len - a) * sizeof(*G.nodes)); + G.nodes[a] = n; + G.nodes_len++; + return n; +} + +static void +add_edge(struct node *a, struct node *b) +{ + a->out = xrealloc_vector(a->out, 6, a->out_count); + a->out[a->out_count++] = b; + b->in_count++; +} + +int tsort_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; +int tsort_main(int argc UNUSED_PARAM, char **argv) +{ + char *line; + size_t linesz; + ssize_t len; + struct node *a; + int cycles; + + INIT_G(); + + if (argv[1]) { + if (argv[2]) + bb_show_usage(); + if (NOT_LONE_DASH(argv[1])) { + close(STDIN_FILENO); /* == 0 */ + xopen(argv[1], O_RDONLY); /* fd will be 0 */ + } + } + + /* Read in words separated by s */ + a = NULL; + line = NULL; + linesz = 0; + while ((len = getline(&line, &linesz, stdin)) != -1) { + char *s = line; + while (*(s = skip_whitespace(s)) != '\0') { + struct node *b; + char *word; + + word = s; + s = skip_non_whitespace(s); + if (*s) + *s++ = '\0'; + + /* Create nodes and edges for each word pair */ + b = get_node(word); + if (!a) { + a = b; + } else { + if (a != b) + add_edge(a, b); + a = NULL; + } + } + } +// Most other tools do not check for input read error (treat them as EOF) +// die_if_ferror(in, input_filename); + if (a) + bb_simple_error_msg_and_die("odd input"); + free(line); + + /* + * Kahn's algorithm: + * - find a node that has no incoming edges, print and remove it + * - repeat until the graph is empty + * - if any nodes are left, they form cycles. + */ + cycles = 0; + while (G.nodes_len) { + struct node *n; + unsigned i; + + /* Search for first node with no incoming edges */ + for (i = 0; i < G.nodes_len; i++) { + if (!G.nodes[i]->in_count) + break; + } + if (i == G.nodes_len) { + /* Must be a cycle; arbitraily break it at node 0 */ + cycles++; + i = 0; +#ifndef TINY + bb_error_msg("cycle at %s", G.nodes[i]->name); +#endif + } + + /* Remove the node (need no longer maintain sort) */ + n = G.nodes[i]; + G.nodes[i] = G.nodes[--G.nodes_len]; + + /* And remove its outgoing edges */ + for (i = 0; i < n->out_count; i++) + n->out[i]->in_count--; + free(n->out); + + puts(n->name); + free(n); + } + free(G.nodes); + + fflush_stdout_and_exit(cycles ? 1 : 0); +} diff --git a/docs/posix_conformance.txt b/docs/posix_conformance.txt index 5e107d74d..8edbe3e15 100644 --- a/docs/posix_conformance.txt +++ b/docs/posix_conformance.txt @@ -24,7 +24,7 @@ POSIX Tools not supported: gencat, getconf, iconv, join, link, locale, localedef, lp, m4, mailx, newgrp, nl, pathchk, pax, pr, qalter, qdel, qhold, qmove, qmsg, qrerun, qrls, qselect, qsig, qstat, qsub, tabs, talk, tput, - tsort, unlink, uucp, uustat, uux + unlink, uucp, uustat, uux POSIX Tools not supported (DEVELOPMENT): admin, cflow, ctags, cxref, delta, fort77, get, lex, make, nm, prs, rmdel, diff --git a/testsuite/tsort.tests b/testsuite/tsort.tests new file mode 100755 index 000000000..c6fe78272 --- /dev/null +++ b/testsuite/tsort.tests @@ -0,0 +1,110 @@ +#!/bin/sh + +# SUSv3 compliant sort tests. +# Public Domain, David Leonard 2022 + +. ./testing.sh + +# name cmd expected ./input stdin +testing "" "tsort" "a\n" "" "a a\n" +testing "" "tsort -" "a\n" "" "a a\n" +testing "" "tsort input" "a\n" "a a\n" "" +testing "tsort input (w/o eol)" "tsort input" "a\n" "a a" "" +testing "" "tsort /dev/null" "" "" "" + +testing "tsort empty" tsort "" "" "" +testing "tsort blank" tsort "" "" "\n" +testing "tsort blanks" tsort "" "" "\n\n \t\n " + +# simple inputs having exactly one solution +testing "tsort 1-edge" tsort "a\nb\n" "" "a b\n" +testing "tsort 2-edge" tsort "a\nb\nc\n" "" "a b b c\n" + + +# The following test helper accommodates future variable output because, as +# tsort is allowed to emit any total ordering that satisfies its input, +# should the implementation changes, these tests will remain valid. +# +# The idea is to verify that: +# - each input word is present EXACTLY ONCE in tsort's output +# - for each input pair 'a b', the occurrence of 'a' APPEARS BEFORE 'b' +# - the exit code is 0 + +tsort_test () { + fail= + name="$1"; shift + args="$*" + if [ $VERBOSE ]; then + echo "============" + echo "echo \"$args\" | tsort >actual" + fi + echo "$args" | tsort >actual + ec=$? + if [ $ec -ne 0 ]; then + fail "tsort exit $ec, expected 0" + fi + while [ $# -ne 0 ]; do + a=$1; shift + b=$1; shift + aline=$(grep -nxF "$a" /dev/null 2>/dev/null + ec=$? + if [ $ec -eq 0 ]; then + fail "$name: unexpected exit 0 ($*)" + fi + report "$name" +} + +fail () { + [ $VERBOSE ] && echo "ERROR: $*" + fail=1 +} + +report () { + if [ $fail ]; then + FAILCOUNT=$(($FAILCOUNT + 1)) + echo "FAIL: $*" + else + echo "PASS: $*" + fi +} + +tsort_test "tsort empty2" +tsort_test "tsort singleton" a a +tsort_test "tsort simple" a b b c +tsort_test "tsort 2singleton" a a b b +tsort_test "tsort medium" a b a b b c +tsort_test "tsort std.example" a b c c d e g g f g e f h h +tsort_test "tsort prefixes" a aa aa aaa aaaa aaaaa a aaaaa + +tsort_test_err "tsort odd" a +tsort_test_err "tsort odd2" a b c +tsort_test_err "tsort cycle" a b b a + +exit $FAILCOUNT From vda.linux at googlemail.com Mon May 2 12:47:53 2022 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Mon, 2 May 2022 14:47:53 +0200 Subject: [git commit] init: do not set HOME Message-ID: <20220502123745.2631E84DBE@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=1a290f889c5103d867ba1e0715ae730b394a3a12 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta .rodata 104906 104899 -7 init_main 786 776 -10 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-17) Total: -17 bytes Signed-off-by: Denys Vlasenko --- init/init.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/init/init.c b/init/init.c index 785a3b460..1e1ce833d 100644 --- a/init/init.c +++ b/init/init.c @@ -1105,10 +1105,14 @@ int init_main(int argc UNUSED_PARAM, char **argv) setsid(); /* Make sure environs is set to something sane */ - putenv((char *) "HOME=/"); putenv((char *) bb_PATH_root_path); putenv((char *) "SHELL=/bin/sh"); putenv((char *) "USER=root"); /* needed? why? */ + /* Linux kernel sets HOME="/" when execing init, + * and it can be overridden (but not unset?) on kernel's command line. + * We used to set it to "/" here, but now we do not: + */ + //putenv((char *) "HOME=/"); if (argv[1]) xsetenv("RUNLEVEL", argv[1]); From vda.linux at googlemail.com Mon May 2 12:53:14 2022 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Mon, 2 May 2022 14:53:14 +0200 Subject: [git commit] seedrng: it's not a part of util-linux, move to miscutils Message-ID: <20220502124325.E1BBE84DC6@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=5ba56e8b95ea84dbd7c0f7adfb9bdb1740480904 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master Signed-off-by: Denys Vlasenko --- {util-linux => miscutils}/seedrng.c | 0 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/util-linux/seedrng.c b/miscutils/seedrng.c similarity index 100% rename from util-linux/seedrng.c rename to miscutils/seedrng.c From vda.linux at googlemail.com Mon May 2 13:03:32 2022 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Mon, 2 May 2022 15:03:32 +0200 Subject: [git commit] seedrng: restore error check on fsync Message-ID: <20220502125351.5D30784DF3@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=3bfbcb5807ec43b6470bd7bb3e3ca0375ed16544 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master Or else security people will never stop nagging us. function old new delta seedrng_main 884 906 +22 Signed-off-by: Denys Vlasenko --- miscutils/seedrng.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/miscutils/seedrng.c b/miscutils/seedrng.c index 8c81835f6..4f2441abc 100644 --- a/miscutils/seedrng.c +++ b/miscutils/seedrng.c @@ -134,12 +134,14 @@ static void seed_from_file_if_exists(const char *filename, int dfd, bool credit, /* We are going to use this data to seed the RNG: * we believe it to genuinely containing entropy. * If this just-unlinked file survives - * (e.g. if machine crashes _right now_) + * (if machine crashes before deletion is recorded on disk) * and we reuse it after reboot, this assumption - * would be violated. Fsync the directory to - * make sure file is gone: + * would be violated, and RNG may end up generating + * the same data. fsync the directory + * to make sure file is gone: */ - fsync(dfd); + if (fsync(dfd) != 0) + bb_simple_perror_msg_and_die("I/O error"); //Length is not random, and taking its address spills variable to stack // sha256_hash(hash, &seed_len, sizeof(seed_len)); @@ -210,10 +212,11 @@ int seedrng_main(int argc UNUSED_PARAM, char **argv) sha256_hash(&hash, ×tamp, sizeof(timestamp)); for (i = 0; i <= 1; i++) { - seed_from_file_if_exists(i == 0 ? NON_CREDITABLE_SEED_NAME : CREDITABLE_SEED_NAME, - dfd, - /* credit? */ (opts ^ OPT_n) & i, /* 0, then 1 unless -n */ - &hash); + seed_from_file_if_exists( + i == 0 ? NON_CREDITABLE_SEED_NAME : CREDITABLE_SEED_NAME, + dfd, + /*credit?*/ (opts ^ OPT_n) & i, /* 0, then 1 unless -n */ + &hash); } new_seed_len = determine_optimal_seed_len(); @@ -224,7 +227,7 @@ int seedrng_main(int argc UNUSED_PARAM, char **argv) sha256_end(&hash, new_seed + new_seed_len - SHA256_OUTSIZE); printf("Saving %u bits of %screditable seed for next boot\n", - (unsigned)new_seed_len * 8, new_seed_creditable ? "" : "non-"); + (unsigned)new_seed_len * 8, new_seed_creditable ? "" : "non-"); fd = xopen3(NON_CREDITABLE_SEED_NAME, O_WRONLY | O_CREAT | O_TRUNC, 0400); xwrite(fd, new_seed, new_seed_len); if (new_seed_creditable) { From bugzilla at busybox.net Mon May 2 21:22:13 2022 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Mon, 02 May 2022 21:22:13 +0000 Subject: [Bug 14786] New: `xxd -r` introduces spurious bytes Message-ID: https://bugs.busybox.net/show_bug.cgi?id=14786 Bug ID: 14786 Summary: `xxd -r` introduces spurious bytes Product: Busybox Version: 1.34.x Hardware: All OS: Linux Status: NEW Severity: normal Priority: P5 Component: Other Assignee: unassigned at busybox.net Reporter: bugz.vufd7 at aleeas.com CC: busybox-cvs at busybox.net Target Milestone: --- Here's a sample hexdump, produced by xxd: $ cat > /tmp/encoded <? 00000040: 40 @ EOF If I run `xxd -r`, I expect to get back the original, 65-byte binary file represented by this hex dump. In other words, `xxd -r /tmp/encoded | xxd` should produce exactly the same encoded representation. It doesn't - `xxd -r` produces a *70*-byte file; 5 bytes have been added after the 64th bit. Here's the full output: $ /bin/busybox xxd -r /tmp/encoded | xxd 00000000: 0001 0203 0405 0607 0809 0a0b 0c0d 0e0f ................ 00000010: 1011 1213 1415 1617 1819 1a1b 1c1d 1e1f ................ 00000020: 2021 2223 2425 2627 2829 2a2b 2c2d 2e2f !"#$%&'()*+,-./ 00000030: 3031 3233 3435 3637 3839 3a3b 3c3d 3e3f 0123456789:;<=>? 00000040: 0123 4567 8940 .#Eg.@ ^^^^^^^^^^^^ extra bytes -- You are receiving this mail because: You are on the CC list for the bug. From bugzilla at busybox.net Tue May 3 08:01:03 2022 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Tue, 03 May 2022 08:01:03 +0000 Subject: [Bug 14786] `xxd -r` introduces spurious bytes In-Reply-To: References: Message-ID: https://bugs.busybox.net/show_bug.cgi?id=14786 --- Comment #1 from Rich --- After further testing, I've found that BusyBox's xxd is copying the first leading hex numerals out of the ASCII column. And it may be doing this because it is not taking the value of the -c option into account - or that may be a separate bug. Here's another example, contrasted with the output of the stand-alone xxd package. $ cat > sample << EOF 00000000: 0100 0000 0000 0000 0000 0000 0000 00ff deadbeef........ EOF BusyBox's reversed interpretation: $ /bin/busybox xxd -r -c2 sample | xxd 00000000: 0100 0000 0000 0000 0000 0000 0000 00ff ................ 00000010: dead beef .... Details of stand-alone package, and how it handles input by default: $ /usr/bin/xxd -v xxd 2022-01-14 by Juergen Weigert et al. $ /usr/bin/xxd -r sample | xxd 00000000: 0100 0000 0000 0000 0000 0000 0000 00ff ................ And how stand-alone package interprets the -c option: $ /usr/bin/xxd -r -c2 sample | xxd 00000000: 0100 .. -- You are receiving this mail because: You are on the CC list for the bug. From vda.linux at googlemail.com Tue May 3 10:48:50 2022 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Tue, 3 May 2022 12:48:50 +0200 Subject: [git commit] seedrng: do not hash in a constant string, it's not adding entropy Message-ID: <20220503103847.C9A4A84EAD@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=67fd6be0bb925839f4e6564dba741f9889b2fac8 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta seedrng_main 906 880 -26 .rodata 104899 104873 -26 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-52) Total: -52 bytes Signed-off-by: Denys Vlasenko --- miscutils/seedrng.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/miscutils/seedrng.c b/miscutils/seedrng.c index 4f2441abc..967741dc7 100644 --- a/miscutils/seedrng.c +++ b/miscutils/seedrng.c @@ -169,7 +169,7 @@ int seedrng_main(int argc UNUSED_PARAM, char **argv) uint8_t new_seed[MAX_SEED_LEN]; size_t new_seed_len; bool new_seed_creditable; - struct timespec timestamp; + struct timespec timestamp[2]; sha256_ctx_t hash; enum { @@ -197,19 +197,19 @@ int seedrng_main(int argc UNUSED_PARAM, char **argv) * Avoid concurrent runs by taking a blocking lock on the directory. * Not checking for errors. Looking at manpage, * ENOLCK "The kernel ran out of memory for allocating lock records" - * seems to be the only one which is likely - and if that happens, + * seems to be the only one which is possible - and if that happens, * machine is OOMing (much worse problem than inability to lock...). * Also, typically configured Linux machines do not fail GFP_KERNEL * allocations (they trigger memory reclaim instead). */ - flock(dfd, LOCK_EX); /* would block while another copy runs */ + flock(dfd, LOCK_EX); /* blocks while another instance runs */ sha256_begin(&hash); - sha256_hash(&hash, "SeedRNG v1 Old+New Prefix", 25); - clock_gettime(CLOCK_REALTIME, ×tamp); - sha256_hash(&hash, ×tamp, sizeof(timestamp)); - clock_gettime(CLOCK_BOOTTIME, ×tamp); - sha256_hash(&hash, ×tamp, sizeof(timestamp)); +//Hashing in a constant string doesn't add any entropy +// sha256_hash(&hash, "SeedRNG v1 Old+New Prefix", 25); + clock_gettime(CLOCK_REALTIME, ×tamp[0]); + clock_gettime(CLOCK_BOOTTIME, ×tamp[1]); + sha256_hash(&hash, timestamp, sizeof(timestamp)); for (i = 0; i <= 1; i++) { seed_from_file_if_exists( From bugzilla at busybox.net Wed May 4 21:04:21 2022 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Wed, 04 May 2022 21:04:21 +0000 Subject: [Bug 14791] New: Feature Request: Busybox grep exclude compatibility Message-ID: https://bugs.busybox.net/show_bug.cgi?id=14791 Bug ID: 14791 Summary: Feature Request: Busybox grep exclude compatibility Product: Busybox Version: 1.35.x Hardware: All OS: Linux Status: NEW Severity: normal Priority: P5 Component: Other Assignee: unassigned at busybox.net Reporter: Synper311 at aol.com CC: busybox-cvs at busybox.net Target Milestone: --- GNU grep documentation: https://www.gnu.org/software/grep/manual/grep.html#index-_002d_002dexclude This would allow scripts and programs relying upon this grep feature to work smoothly with Busybox grep to exclude resuls, files, and/or directories that match the exclude filter. -- You are receiving this mail because: You are on the CC list for the bug. From vda.linux at googlemail.com Tue May 10 10:56:28 2022 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Tue, 10 May 2022 12:56:28 +0200 Subject: [git commit] top: fix display of large PID/PPID Message-ID: <20220510114054.29F1085B74@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=294881d2e9ab014f918fba63c01a629906508515 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta display_process_list 1077 1191 +114 .rodata 104803 104807 +4 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 118/0) Total: 118 bytes Signed-off-by: Denys Vlasenko --- procps/top.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/procps/top.c b/procps/top.c index 804d6f258..15222f570 100644 --- a/procps/top.c +++ b/procps/top.c @@ -608,6 +608,8 @@ static NOINLINE void display_process_list(int lines_rem, int scr_width) BITS_PER_INT = sizeof(int) * 8 }; + char ppubuf[sizeof(int)*3 * 2 + 12]; + int n; top_status_t *s; unsigned long total_memory = display_header(scr_width, &lines_rem); /* or use total_vsz? */ /* xxx_shift and xxx_scale variables allow us to replace @@ -699,12 +701,36 @@ static NOINLINE void display_process_list(int lines_rem, int scr_width) smart_ulltoa5(s->vsz, vsz_str_buf, " mgtpezy"); /* PID PPID USER STAT VSZ %VSZ [%CPU] COMMAND */ + n = sprintf(ppubuf, "%5u %5u %-8.8s", s->pid, s->ppid, get_cached_username(s->uid)); + if (n != 6+6+8) { + /* Format PID PPID USER part into 6+6+8 chars: + * shrink PID/PPID if possible, then truncate USER + */ + char *pp, *p = ppubuf; + if (*p == ' ') { + do + p++, n--; + while (n != 6+6+8 && *p == ' '); + overlapping_strcpy(ppubuf, p); /* shrink PID */ + if (n == 6+6+8) + goto shortened; + } + pp = p = skip_non_whitespace(ppubuf) + 1; + if (*p == ' ') { + do + p++, n--; + while (n != 6+6+8 && *p == ' '); + overlapping_strcpy(pp, p); /* shrink PPID */ + } + ppubuf[6+6+8] = '\0'; /* truncate USER */ + } + shortened: col = snprintf(line_buf, scr_width, - "\n" "%5u%6u %-8.8s %s %.5s" FMT + "\n" "%s %s %.5s" FMT IF_FEATURE_TOP_SMP_PROCESS(" %3d") IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE(FMT) " ", - s->pid, s->ppid, get_cached_username(s->uid), + ppubuf, s->state, vsz_str_buf, SHOW_STAT(pmem) IF_FEATURE_TOP_SMP_PROCESS(, s->last_seen_on_cpu) From vda.linux at googlemail.com Tue May 10 11:51:09 2022 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Tue, 10 May 2022 13:51:09 +0200 Subject: [git commit] top: code shrink Message-ID: <20220510114054.3726784E3D@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=69f82e305b34aa35994b87f7ca6528abfbd73520 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta display_process_list 1191 1186 -5 Signed-off-by: Denys Vlasenko --- procps/top.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/procps/top.c b/procps/top.c index 15222f570..5141feef1 100644 --- a/procps/top.c +++ b/procps/top.c @@ -608,8 +608,6 @@ static NOINLINE void display_process_list(int lines_rem, int scr_width) BITS_PER_INT = sizeof(int) * 8 }; - char ppubuf[sizeof(int)*3 * 2 + 12]; - int n; top_status_t *s; unsigned long total_memory = display_header(scr_width, &lines_rem); /* or use total_vsz? */ /* xxx_shift and xxx_scale variables allow us to replace @@ -691,6 +689,9 @@ static NOINLINE void display_process_list(int lines_rem, int scr_width) lines_rem = ntop - G_scroll_ofs; s = top + G_scroll_ofs; while (--lines_rem >= 0) { + int n; + char *pp; + char ppubuf[sizeof(int)*3 * 2 + 12]; char vsz_str_buf[8]; unsigned col; @@ -706,14 +707,15 @@ static NOINLINE void display_process_list(int lines_rem, int scr_width) /* Format PID PPID USER part into 6+6+8 chars: * shrink PID/PPID if possible, then truncate USER */ - char *pp, *p = ppubuf; - if (*p == ' ') { - do - p++, n--; - while (n != 6+6+8 && *p == ' '); - overlapping_strcpy(ppubuf, p); /* shrink PID */ - if (n == 6+6+8) - goto shortened; + char *p; + pp = ppubuf; + if (*pp == ' ') { + do { + pp++, n--; + if (n == 6+6+8) + goto shortened; + } while (*pp == ' '); + overlapping_strcpy(ppubuf, pp); /* shrink PID */ } pp = p = skip_non_whitespace(ppubuf) + 1; if (*p == ' ') { @@ -724,13 +726,14 @@ static NOINLINE void display_process_list(int lines_rem, int scr_width) } ppubuf[6+6+8] = '\0'; /* truncate USER */ } + pp = ppubuf; shortened: col = snprintf(line_buf, scr_width, "\n" "%s %s %.5s" FMT IF_FEATURE_TOP_SMP_PROCESS(" %3d") IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE(FMT) " ", - ppubuf, + pp, s->state, vsz_str_buf, SHOW_STAT(pmem) IF_FEATURE_TOP_SMP_PROCESS(, s->last_seen_on_cpu) From vda.linux at googlemail.com Tue May 10 12:04:34 2022 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Tue, 10 May 2022 14:04:34 +0200 Subject: [git commit] top: code shrink Message-ID: <20220510115414.79E5F85C14@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=1099a27696cd733041db97f99da4e22ecd2424e5 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta display_process_list 1186 1168 -18 Signed-off-by: Denys Vlasenko --- procps/top.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/procps/top.c b/procps/top.c index 5141feef1..744f20e9b 100644 --- a/procps/top.c +++ b/procps/top.c @@ -690,7 +690,7 @@ static NOINLINE void display_process_list(int lines_rem, int scr_width) s = top + G_scroll_ofs; while (--lines_rem >= 0) { int n; - char *pp; + char *ppu; char ppubuf[sizeof(int)*3 * 2 + 12]; char vsz_str_buf[8]; unsigned col; @@ -703,37 +703,35 @@ static NOINLINE void display_process_list(int lines_rem, int scr_width) smart_ulltoa5(s->vsz, vsz_str_buf, " mgtpezy"); /* PID PPID USER STAT VSZ %VSZ [%CPU] COMMAND */ n = sprintf(ppubuf, "%5u %5u %-8.8s", s->pid, s->ppid, get_cached_username(s->uid)); + ppu = ppubuf; if (n != 6+6+8) { /* Format PID PPID USER part into 6+6+8 chars: * shrink PID/PPID if possible, then truncate USER */ - char *p; - pp = ppubuf; - if (*pp == ' ') { + char *p, *pp; + if (*ppu == ' ') { do { - pp++, n--; + ppu++, n--; if (n == 6+6+8) goto shortened; - } while (*pp == ' '); - overlapping_strcpy(ppubuf, pp); /* shrink PID */ + } while (*ppu == ' '); } - pp = p = skip_non_whitespace(ppubuf) + 1; + pp = p = skip_non_whitespace(ppu) + 1; if (*p == ' ') { do p++, n--; while (n != 6+6+8 && *p == ' '); overlapping_strcpy(pp, p); /* shrink PPID */ } - ppubuf[6+6+8] = '\0'; /* truncate USER */ + ppu[6+6+8] = '\0'; /* truncate USER */ } - pp = ppubuf; shortened: col = snprintf(line_buf, scr_width, "\n" "%s %s %.5s" FMT IF_FEATURE_TOP_SMP_PROCESS(" %3d") IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE(FMT) " ", - pp, + ppu, s->state, vsz_str_buf, SHOW_STAT(pmem) IF_FEATURE_TOP_SMP_PROCESS(, s->last_seen_on_cpu) From vda.linux at googlemail.com Thu May 12 09:07:12 2022 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Thu, 12 May 2022 11:07:12 +0200 Subject: [git commit] examples/var_service/dhcp_if: make helper scripts more talkative Message-ID: <20220512085645.E094985AAC@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=b9c2108b26ad1fe4634c250850a4abadff26c76e branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master Signed-off-by: Denys Vlasenko --- examples/var_service/dhcp_if/convert2ipconf | 16 ++++++++++++---- examples/var_service/dhcp_if/convert2ntpconf | 2 +- examples/var_service/dhcp_if/dhcp_handler | 6 ++---- examples/var_service/dhcp_if/finish | 2 +- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/examples/var_service/dhcp_if/convert2ipconf b/examples/var_service/dhcp_if/convert2ipconf index 31e3c7fde..98f6546bf 100755 --- a/examples/var_service/dhcp_if/convert2ipconf +++ b/examples/var_service/dhcp_if/convert2ipconf @@ -19,7 +19,7 @@ #let cfg=cfg+1 #if[$cfg]=...; ip[$cfg]=...; ipmask[$cfg]=.../...; gw[$cfg]=...; net[$cfg]=... dns[$cfg]=... -exec >/dev/null +#exec >/dev/null #exec >"$0.out" # debug exec 2>&1 @@ -31,23 +31,31 @@ test "$ip" || exit 1 if ! test "$mask"; then case "$ip" in 10.*) + echo "mask assumed 8 for ip=$ip" mask=8;; - 192.168.*) - mask=16;; #172.16-31.x.x 172.1[6789].*) + echo "mask assumed 12 for ip=$ip" mask=12;; 172.2[0123456789].*) + echo "mask assumed 12 for ip=$ip" mask=12;; 172.3[01].*) + echo "mask assumed 12 for ip=$ip" mask=12;; + 192.168.*) + echo "mask assumed 16 for ip=$ip" + mask=16;; esac fi # some servers do not return router option. # assume DHCP server is the router. if ! test "$router"; then - test "$serverid" && router="$serverid" + if test "$serverid"; then + router="$serverid" + echo "No 'router' from the server, assuming 'serverid' is the router: $serverid" + fi fi { diff --git a/examples/var_service/dhcp_if/convert2ntpconf b/examples/var_service/dhcp_if/convert2ntpconf index e9d829308..f51740ba0 100755 --- a/examples/var_service/dhcp_if/convert2ntpconf +++ b/examples/var_service/dhcp_if/convert2ntpconf @@ -19,7 +19,7 @@ #let cfg=cfg+1 #ntpip[$cfg]=... -exec >/dev/null +#exec >/dev/null #exec >"$0.out" # debug exec 2>&1 diff --git a/examples/var_service/dhcp_if/dhcp_handler b/examples/var_service/dhcp_if/dhcp_handler index 6a97e8543..3e652621d 100755 --- a/examples/var_service/dhcp_if/dhcp_handler +++ b/examples/var_service/dhcp_if/dhcp_handler @@ -38,12 +38,10 @@ file_ntpconf="$service.ntpconf" dir_ipconf="/var/run/service/fw" dir_ntpconf="/var/run/service/ntpd" -exec >/dev/null -#exec >>"$0.out" #debug +#exec >/dev/null +#exec >"$0.out" #debug exec 2>&1 -echo "`date`: Params: $*" - if test x"$1" != x"bound" && test x"$1" != x"renew" ; then # Reconfigure network with this interface disabled echo "Deconfiguring" diff --git a/examples/var_service/dhcp_if/finish b/examples/var_service/dhcp_if/finish index 8ce188336..50bfe67b5 100755 --- a/examples/var_service/dhcp_if/finish +++ b/examples/var_service/dhcp_if/finish @@ -1,5 +1,5 @@ #!/bin/sh -# executed when service is taken down ("sv d .") +# executed when service is taken down ("svc -d .") service=${PWD##*/} file_ipconf="$service.ipconf" From vda.linux at googlemail.com Thu May 12 09:44:47 2022 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Thu, 12 May 2022 11:44:47 +0200 Subject: [git commit] top: improve large PID display in memory ('s') mode Message-ID: <20220512093441.ECA7785BF6@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=8d67007a4dedef77dd0cf757bcc0e6fbee267ced branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta display_topmem_process_list 530 564 +34 Signed-off-by: Denys Vlasenko --- procps/top.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/procps/top.c b/procps/top.c index 744f20e9b..ff775422c 100644 --- a/procps/top.c +++ b/procps/top.c @@ -879,8 +879,11 @@ static NOINLINE void display_topmem_process_list(int lines_rem, int scr_width) lines_rem = ntop - G_scroll_ofs; while (--lines_rem >= 0) { /* PID VSZ VSZRW RSS (SHR) DIRTY (SHR) COMMAND */ - ulltoa6_and_space(s->pid , &line_buf[0*6]); + int n = sprintf(line_buf, "%5u ", s->pid); ulltoa6_and_space(s->vsz , &line_buf[1*6]); + if (n > 7 || (n == 7 && line_buf[6] != ' ')) + /* PID and VSZ are clumped together, truncate PID */ + line_buf[5] = '.'; ulltoa6_and_space(s->vszrw , &line_buf[2*6]); ulltoa6_and_space(s->rss , &line_buf[3*6]); ulltoa6_and_space(s->rss_sh , &line_buf[4*6]); From bugzilla at busybox.net Wed May 18 04:58:49 2022 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Wed, 18 May 2022 04:58:49 +0000 Subject: [Bug 14806] New: Erasure of intermediate values in sha_crypt() removed due to compiler optimization Message-ID: https://bugs.busybox.net/show_bug.cgi?id=14806 Bug ID: 14806 Summary: Erasure of intermediate values in sha_crypt() removed due to compiler optimization Product: Busybox Version: 1.35.x Hardware: All OS: Linux Status: NEW Severity: normal Priority: P5 Component: Other Assignee: unassigned at busybox.net Reporter: yufeidu at cs.unc.edu CC: busybox-cvs at busybox.net Target Milestone: --- Created attachment 9306 --> https://bugs.busybox.net/attachment.cgi?id=9306&action=edit .config file when building busybox The SHA encrypt function sha_crypt() (located in pw_encrypt_sha.c) uses memset to erase the intermediate results in both the stack object L and heap objects key_data and salt_data before it returns. The comment above memset calls indicates that these erasures are necessary to prevent information leaks. However, when compiled with Clang 14 at O3 optimization, all 3 calls to memset are removed due to the Dead Store Elimination optimization. As a result, the intermediate results in L and part of the results in key_data may stay in memory outside their scopes. Here is a snippet of the disassembly at O3 (with the corresponding C code generated using "objdump -S"): memset(&L, 0, sizeof(L)); /* [alt]_ctx and XXX_result buffers */ memset(key_data, 0, key_len); /* also p_bytes */ memset(salt_data, 0, salt_len); /* also s_bytes */ free(key_data); 50d97e: e8 d5 ad ef ff call 408758 free(salt_data); 50d983: 4c 89 ef mov %r13,%rdi 50d986: e8 cd ad ef ff call 408758 At the assembly level, there is no function call to memset. -- You are receiving this mail because: You are on the CC list for the bug. From bugzilla at busybox.net Wed May 18 14:23:16 2022 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Wed, 18 May 2022 14:23:16 +0000 Subject: [Bug 14811] New: networking/nslookup.c parse_reply() CVE-2022-28391 patch query Message-ID: https://bugs.busybox.net/show_bug.cgi?id=14811 Bug ID: 14811 Summary: networking/nslookup.c parse_reply() CVE-2022-28391 patch query Product: Busybox Version: unspecified Hardware: All OS: Linux Status: NEW Severity: normal Priority: P5 Component: Networking Assignee: unassigned at busybox.net Reporter: john.simner at atos.net CC: busybox-cvs at busybox.net Target Milestone: --- Is BusyBox affected by CVE-2022-28391 (BusyBox networking/nslookup.c parse_reply() Function DNS PTR Record Escape Sequence Handling Arbitrary Command Execution) and BusyBox networking/nslookup.c parse_reply() Function DNS PTR Record Escape Sequence Handling Arbitrary Command Execution)? If so, is there an official patch or update that fixes these vulnerabilities from BusyBox rather than git.alpinelinux.org? If https://git.alpinelinux.org/aports/plain/main/busybox/0001-libbb-sockaddr2str-ensure-only-printable-characters-.patch details a patch that can be applied to BusyBox, should the change from "xasprintf("%s:%s", host, serv);" to "xasprintf("%s:%s", printable_string(host), serv);" also be applied to ... #if ENABLE_FEATURE_IPV6 if (sa->sa_family == AF_INET6) { if (strchr(host, ':')) /* heh, it's not a resolved hostname */ return xasprintf("[%s]:%s", host, serv); /*return xasprintf("%s:%s", host, serv);*/ /* - fall through instead */ } #endif Thanks for your assistance and look forward to your response. -- You are receiving this mail because: You are on the CC list for the bug. From bugzilla at busybox.net Fri May 20 05:31:58 2022 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Fri, 20 May 2022 05:31:58 +0000 Subject: [Bug 14781] A use-after-free in Busybox's awk applet leads to denial of service and possibly code execution when processing a crafted awk pattern in the copyvar function In-Reply-To: References: Message-ID: https://bugs.busybox.net/show_bug.cgi?id=14781 --- Comment #1 from Steve Beattie --- This issue was assigned CVE-2022-30065 (https://nvd.nist.gov/vuln/detail/CVE-2022-30065). -- You are receiving this mail because: You are on the CC list for the bug.