From vda.linux at googlemail.com Wed Dec 1 14:09:44 2021 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Wed, 1 Dec 2021 15:09:44 +0100 Subject: [git commit] tls: x25519: code shrink by factoring out common code Message-ID: <20211201144812.26A94915E9@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=b240733ae7423cb8f542a624eef0cfa3037d05bc branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta fe_reduce - 37 +37 lm_add 67 43 -24 fe_mul_c 62 38 -24 fe_mul__distinct 138 112 -26 curve25519 800 767 -33 lm_sub 98 64 -34 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/5 up/down: 37/-141) Total: -104 bytes Signed-off-by: Denys Vlasenko --- networking/tls_fe.c | 68 +++++++++++++++++------------------------------------ 1 file changed, 21 insertions(+), 47 deletions(-) diff --git a/networking/tls_fe.c b/networking/tls_fe.c index 3a0a6776f..e5580fbcf 100644 --- a/networking/tls_fe.c +++ b/networking/tls_fe.c @@ -187,7 +187,7 @@ static void fprime_mul(byte *r, const byte *a, const byte *b, #if 0 //UNUSED static void fe_load(byte *x, word32 c) { - word32 i; + int i; for (i = 0; i < sizeof(c); i++) { x[i] = c; @@ -199,21 +199,29 @@ static void fe_load(byte *x, word32 c) } #endif -static void fe_normalize(byte *x) +static void fe_reduce(byte *x, word32 c) { - byte minusp[F25519_SIZE]; - unsigned c; int i; /* Reduce using 2^255 = 19 mod p */ - c = (x[31] >> 7) * 19; - x[31] &= 127; + x[31] = c & 127; + c = (c >> 7) * 19; for (i = 0; i < F25519_SIZE; i++) { c += x[i]; x[i] = (byte)c; c >>= 8; } +} + +static void fe_normalize(byte *x) +{ + byte minusp[F25519_SIZE]; + unsigned c; + int i; + + /* Reduce using 2^255 = 19 mod p */ + fe_reduce(x, x[31]); /* The number is now less than 2^255 + 18, and therefore less than * 2p. Try subtracting p, and conditionally load the subtracted @@ -247,14 +255,7 @@ static void lm_add(byte* r, const byte* a, const byte* b) } /* Reduce with 2^255 = 19 mod p */ - r[31] &= 127; - c = (c >> 7) * 19; - - for (i = 0; i < F25519_SIZE; i++) { - c += r[i]; - r[i] = (byte)c; - c >>= 8; - } + fe_reduce(r, c); } static void lm_sub(byte* r, const byte* a, const byte* b) @@ -264,21 +265,15 @@ static void lm_sub(byte* r, const byte* a, const byte* b) /* Calculate a + 2p - b, to avoid underflow */ c = 218; - for (i = 0; i + 1 < F25519_SIZE; i++) { + for (i = 0; i < F25519_SIZE - 1; i++) { c += 65280 + ((word32)a[i]) - ((word32)b[i]); r[i] = c; c >>= 8; } c += ((word32)a[31]) - ((word32)b[31]); - r[31] = c & 127; - c = (c >> 7) * 19; - for (i = 0; i < F25519_SIZE; i++) { - c += r[i]; - r[i] = c; - c >>= 8; - } + fe_reduce(r, c); } #if 0 //UNUSED @@ -289,21 +284,15 @@ static void lm_neg(byte* r, const byte* a) /* Calculate 2p - a, to avoid underflow */ c = 218; - for (i = 0; i + 1 < F25519_SIZE; i++) { + for (i = 0; i < F25519_SIZE - 1; i++) { c += 65280 - ((word32)a[i]); r[i] = c; c >>= 8; } c -= ((word32)a[31]); - r[31] = c & 127; - c = (c >> 7) * 19; - for (i = 0; i < F25519_SIZE; i++) { - c += r[i]; - r[i] = c; - c >>= 8; - } + fe_reduce(r, c); } #endif @@ -326,14 +315,7 @@ static void fe_mul__distinct(byte *r, const byte *a, const byte *b) r[i] = c; } - r[31] &= 127; - c = (c >> 7) * 19; - - for (i = 0; i < F25519_SIZE; i++) { - c += r[i]; - r[i] = c; - c >>= 8; - } + fe_reduce(r, c); } #if 0 //UNUSED @@ -357,15 +339,7 @@ static void fe_mul_c(byte *r, const byte *a, word32 b) r[i] = c; } - r[31] &= 127; - c >>= 7; - c *= 19; - - for (i = 0; i < F25519_SIZE; i++) { - c += r[i]; - r[i] = c; - c >>= 8; - } + fe_reduce(r, c); } static void fe_inv__distinct(byte *r, const byte *x) From bugzilla at busybox.net Mon Dec 6 01:52:20 2021 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Mon, 06 Dec 2021 01:52:20 +0000 Subject: [Bug 14421] New: wget HTTPS improvements Message-ID: https://bugs.busybox.net/show_bug.cgi?id=14421 Bug ID: 14421 Summary: wget HTTPS improvements Product: Busybox Version: unspecified Hardware: All OS: All Status: NEW Severity: enhancement Priority: P5 Component: Networking Assignee: unassigned at busybox.net Reporter: bugs-busybox at lanchon.33mail.com CC: busybox-cvs at busybox.net Target Milestone: --- FEATURE_WGET_HTTPS is, lets say, somewhat controversial. it has its very own CVE... :) here are a couple of suggestions to improve it. 1) require '--no-check-certificate' when accessing HTTPS resources (or else a failure message describing this requirement would be printed). this option exists in native wget and would end all discussions. the intention is clear: only be insecure if the user explicitly allows it. the principle "what you don't know won't hurt you" is a very important one to keep. (current printed warning should be kept anyway.) 2) if 1) is implemented, consider changing FEATURE_WGET_HTTPS to the new behavior. a new build flag would be included to enable previous behavior, but this would force builders to explicitly request the controversial, transparently insecure behavior. alternatively, two new build flags could be introduced, and FEATURE_WGET_HTTPS retired causing a build failure if defined. this forces an informed choice, and is in line with "what you don't know won't hurt you". 3) if the current issues with data signature are solved, then HTTPS could be made secure in a specific context. either one of '--no-check-certificate' or '--pinnedpubkey=FILE/HASHES' would be required. the user would have the option of providing a server cert o cert hash to allow for secure downloads without the complete public key infrastructure. this would be great: people everywhere would finally be able to bootstrap securely in small systems. if implementing wget's '--pinnedpubkey=' is too cumbersome, you could define your own simplified flag for this function. or a specific format for the existing flag could be required to ease implementation. -- You are receiving this mail because: You are on the CC list for the bug. From bugzilla at busybox.net Mon Dec 6 02:02:57 2021 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Mon, 06 Dec 2021 02:02:57 +0000 Subject: [Bug 14426] New: proposed FEATURE_WGET_CURL Message-ID: https://bugs.busybox.net/show_bug.cgi?id=14426 Bug ID: 14426 Summary: proposed FEATURE_WGET_CURL Product: Busybox Version: unspecified Hardware: All OS: All Status: NEW Severity: enhancement Priority: P5 Component: Networking Assignee: unassigned at busybox.net Reporter: bugs-busybox at lanchon.33mail.com CC: busybox-cvs at busybox.net Target Milestone: --- FEATURE_WGET_HTTPS is controversial. FEATURE_WGET_OPENSSL is a cool option when applicable. some distros, such as DD-WRT std, have a working cURL (including CA certs) but incomplete openssl. for those it would be great to have a FEATURE_WGET_CURL flag to offload HTTPS to cURL and make it secure. (right now it uses FEATURE_WGET_HTTPS, which clearly is an inferior option.) -- You are receiving this mail because: You are on the CC list for the bug. From bugzilla at busybox.net Tue Dec 7 07:30:31 2021 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Tue, 07 Dec 2021 07:30:31 +0000 Subject: [Bug 14431] New: adduser will add a user folder with 'shadow_t' Message-ID: https://bugs.busybox.net/show_bug.cgi?id=14431 Bug ID: 14431 Summary: adduser will add a user folder with 'shadow_t' Product: Busybox Version: unspecified Hardware: All OS: Linux Status: NEW Severity: normal Priority: P5 Component: Standard Compliance Assignee: unassigned at busybox.net Reporter: 15256067679 at 163.com CC: busybox-cvs at busybox.net Target Milestone: --- I compile the busybox with SELinux support(I tried both with 1.33.x and 1.34.1), then I try to use adduser to create a new user: # adduser user_1 Changing password for user_1 New password: Bad password: too weak Retype password: Passwords don't match passwd: password for user_1 is unchanged # cd /home/ # ls -Z system_u:object_r:user_home_dir_t:s0 default system_u:object_r:shadow_t:s0 user_1 and I check the source code in adduser.c: the function 'selinux_preserve_fcontext(old_fd)'in 'update_passwd(bb_path_shadow_file, pw.pw_name, p, NULL);' will change the filecontext for the file that adduser make to 'shadow_t' and I can't find where to change it back. -- You are receiving this mail because: You are on the CC list for the bug. From bugzilla at busybox.net Wed Dec 8 11:59:38 2021 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Wed, 08 Dec 2021 11:59:38 +0000 Subject: =?UTF-8?B?W0J1ZyAxNDM0MV0gQnVzeUJveCDigJMgMTQgbmV3IHZ1bG5lcmFi?= =?UTF-8?B?aWxpdGllcw==?= In-Reply-To: References: Message-ID: https://bugs.busybox.net/show_bug.cgi?id=14341 --- Comment #1 from xiechengliang --- http://lists.busybox.net/pipermail/busybox/2021-November/089328.html -- You are receiving this mail because: You are on the CC list for the bug. From bugzilla at busybox.net Wed Dec 8 12:00:26 2021 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Wed, 08 Dec 2021 12:00:26 +0000 Subject: =?UTF-8?B?W0J1ZyAxNDM0MV0gQnVzeUJveCDigJMgMTQgbmV3IHZ1bG5lcmFi?= =?UTF-8?B?aWxpdGllcw==?= In-Reply-To: References: Message-ID: https://bugs.busybox.net/show_bug.cgi?id=14341 xiechengliang changed: What |Removed |Added ---------------------------------------------------------------------------- Resolution|--- |FIXED Status|NEW |RESOLVED -- You are receiving this mail because: You are on the CC list for the bug. From bugzilla at busybox.net Thu Dec 9 19:25:04 2021 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Thu, 09 Dec 2021 19:25:04 +0000 Subject: [Bug 14436] New: syntax error: unexpected "fi" (expecting "then") Message-ID: https://bugs.busybox.net/show_bug.cgi?id=14436 Bug ID: 14436 Summary: syntax error: unexpected "fi" (expecting "then") Product: Busybox Version: 1.33.x Hardware: All OS: Linux Status: NEW Severity: major Priority: P5 Component: Networking Assignee: unassigned at busybox.net Reporter: mdvornic at dataremote.com CC: busybox-cvs at busybox.net Target Milestone: --- Created attachment 9181 --> https://bugs.busybox.net/attachment.cgi?id=9181&action=edit The script where the exception is triggered. The following exception is raised sporadically while executing one of the shell scripts with busybox 1.34 version : /sbin/internet.sh: line 438: syntax error: unexpected "fi" (expecting "then") The occurrence of the issue is rare, normally the script internet.sh executes without problems. When the exception is triggered, there is no special branch executing on the script. Code snippet from internet.sh attached. -- You are receiving this mail because: You are on the CC list for the bug. From bugzilla at busybox.net Thu Dec 9 19:30:13 2021 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Thu, 09 Dec 2021 19:30:13 +0000 Subject: [Bug 14441] New: syntax error: unexpected end of file (expecting "fi") Message-ID: https://bugs.busybox.net/show_bug.cgi?id=14441 Bug ID: 14441 Summary: syntax error: unexpected end of file (expecting "fi") Product: Busybox Version: 1.33.x Hardware: All OS: Linux Status: NEW Severity: major Priority: P5 Component: Networking Assignee: unassigned at busybox.net Reporter: mdvornic at dataremote.com CC: busybox-cvs at busybox.net Target Milestone: --- Created attachment 9186 --> https://bugs.busybox.net/attachment.cgi?id=9186&action=edit The script where the exception is triggered. The following exception is raised sporadically while executing one of the shell scripts with busybox 1.34 version : /sbin/lan.sh: line 5: syntax error: unexpected end of file (expecting "fi") The occurrence of the issue is rare, normally the script lan.sh executes without problems. When the exception is triggered, there is no special branch executing on the script. Code snippet from lan.sh attached. -- You are receiving this mail because: You are on the CC list for the bug. From vda.linux at googlemail.com Sat Dec 11 22:27:40 2021 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Sat, 11 Dec 2021 23:27:40 +0100 Subject: [git commit] tls: P256: factor out "multiply then reduce" operation Message-ID: <20211211222614.28ECE82A22@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=27df6aeef2d0d4b726a8b3b1ce1b1cafbbce3431 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta sp_256_mont_mul_and_reduce_8 - 44 +44 sp_256_ecc_mulmod_8 517 442 -75 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/1 up/down: 44/-75) Total: -31 bytes Signed-off-by: Denys Vlasenko --- networking/tls_sp_c32.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/networking/tls_sp_c32.c b/networking/tls_sp_c32.c index cb166e413..292dda24e 100644 --- a/networking/tls_sp_c32.c +++ b/networking/tls_sp_c32.c @@ -1091,6 +1091,17 @@ static void sp_256_mont_sqr_8(sp_digit* r, const sp_digit* a sp_256_mont_mul_8(r, a, a /*, m, mp*/); } +static NOINLINE void sp_256_mont_mul_and_reduce_8(sp_digit* r, + const sp_digit* a, const sp_digit* b + /*, const sp_digit* m, sp_digit mp*/) +{ + sp_digit rr[2 * 8]; + + sp_256_mont_mul_8(rr, a, b /*, p256_mod, p256_mp_mod*/); + memset(rr + 8, 0, sizeof(rr) / 2); + sp_512to256_mont_reduce_8(r, rr /*, p256_mod, p256_mp_mod*/); +} + /* Invert the number, in Montgomery form, modulo the modulus (prime) of the * P256 curve. (r = 1 / a mod m) * @@ -1186,7 +1197,6 @@ static void sp_256_map_8(sp_point* r, sp_point* p) { sp_digit t1[8]; sp_digit t2[8]; - sp_digit rr[2 * 8]; sp_256_mont_inv_8(t1, p->z); @@ -1194,18 +1204,14 @@ static void sp_256_map_8(sp_point* r, sp_point* p) sp_256_mont_mul_8(t1, t2, t1 /*, p256_mod, p256_mp_mod*/); /* x /= z^2 */ - sp_256_mont_mul_8(rr, p->x, t2 /*, p256_mod, p256_mp_mod*/); - memset(rr + 8, 0, sizeof(rr) / 2); - sp_512to256_mont_reduce_8(r->x, rr /*, p256_mod, p256_mp_mod*/); + sp_256_mont_mul_and_reduce_8(r->x, p->x, t2 /*, p256_mod, p256_mp_mod*/); /* Reduce x to less than modulus */ if (sp_256_cmp_8(r->x, p256_mod) >= 0) sp_256_sub_8_p256_mod(r->x); sp_256_norm_8(r->x); /* y /= z^3 */ - sp_256_mont_mul_8(rr, p->y, t1 /*, p256_mod, p256_mp_mod*/); - memset(rr + 8, 0, sizeof(rr) / 2); - sp_512to256_mont_reduce_8(r->y, rr /*, p256_mod, p256_mp_mod*/); + sp_256_mont_mul_and_reduce_8(r->y, p->y, t1 /*, p256_mod, p256_mp_mod*/); /* Reduce y to less than modulus */ if (sp_256_cmp_8(r->y, p256_mod) >= 0) sp_256_sub_8_p256_mod(r->y); From bugzilla at busybox.net Sat Dec 11 23:13:22 2021 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Sat, 11 Dec 2021 23:13:22 +0000 Subject: [Bug 14446] New: gzip: Please add --rsyncable support Message-ID: https://bugs.busybox.net/show_bug.cgi?id=14446 Bug ID: 14446 Summary: gzip: Please add --rsyncable support Product: Busybox Version: unspecified Hardware: All OS: Linux Status: NEW Severity: normal Priority: P5 Component: Other Assignee: unassigned at busybox.net Reporter: guillem at debian.org CC: busybox-cvs at busybox.net Target Milestone: --- This option started as an out of tree patch which at least Debian carried for a long time before it got merged upstream in GNU gzip 1.7. For a while the dpkg perl modules (used for the package building machinery) used the --rsyncable only conditionally whenever the system was Debian based. But I removed that given that GNU gzip 1.7 has been around for some time now. And then I got a report from Alpine Linux which seems to be using busybox, and was now failing. It would be nice to have this option implemented which helps with generating artifacts that can be more easily rsync'ed (and thus is potentially easier on mirrors), I'd also appreciate not having to look for a way to support the different implementations while not having to run something like ?gzip --help? at run-time whenever the perl module is first loaded which might incur a too heavy cost. -- You are receiving this mail because: You are on the CC list for the bug. From vda.linux at googlemail.com Sat Dec 11 23:34:15 2021 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Sun, 12 Dec 2021 00:34:15 +0100 Subject: [git commit] uudecode: special-case "/dev/stdout", closes 14241 Message-ID: <20211211232943.6D70282AF2@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=c7b90dc4d10ccc4f95940f42676ff907cee73272 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta uudecode_main 295 322 +27 Signed-off-by: Denys Vlasenko --- coreutils/uudecode.c | 11 ++++++++++- docs/posix_conformance.txt | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/coreutils/uudecode.c b/coreutils/uudecode.c index a607977e9..e90902f52 100644 --- a/coreutils/uudecode.c +++ b/coreutils/uudecode.c @@ -155,7 +155,16 @@ int uudecode_main(int argc UNUSED_PARAM, char **argv) break; } dst_stream = stdout; - if (NOT_LONE_DASH(outname)) { + if (NOT_LONE_DASH(outname) +/* https://pubs.opengroup.org/onlinepubs/9699919799/utilities/uudecode.html + * https://pubs.opengroup.org/onlinepubs/9699919799/utilities/uuencode.html + * The above says that output file name specified in input file + * or overridden by -o OUTFILE can be special "/dev/stdout" string. + * This usually works "implicitly": many systems have /dev/stdout. + * If ENABLE_DESKTOP, support that explicitly: + */ + && (!ENABLE_DESKTOP || strcmp(outname, "/dev/stdout") != 0) + ) { dst_stream = xfopen_for_write(outname); fchmod(fileno(dst_stream), mode & (S_IRWXU | S_IRWXG | S_IRWXO)); } diff --git a/docs/posix_conformance.txt b/docs/posix_conformance.txt index f6e8858cc..5e107d74d 100644 --- a/docs/posix_conformance.txt +++ b/docs/posix_conformance.txt @@ -690,7 +690,7 @@ uniq Busybox specific options: uudecode POSIX options option | exists | compliant | remarks - -o outfile | no | no | + -o outfile | yes | no | uudecode Busybox specific options: None uuencode POSIX options From bugzilla at busybox.net Sat Dec 11 23:35:31 2021 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Sat, 11 Dec 2021 23:35:31 +0000 Subject: [Bug 14241] uudecode doesn't recognise the special decode_pathname /dev/stdout In-Reply-To: References: Message-ID: https://bugs.busybox.net/show_bug.cgi?id=14241 Denys Vlasenko changed: What |Removed |Added ---------------------------------------------------------------------------- Resolution|--- |FIXED Status|NEW |RESOLVED --- Comment #5 from Denys Vlasenko --- Fixed in git. -- You are receiving this mail because: You are on the CC list for the bug. From bugzilla at busybox.net Sun Dec 12 00:45:55 2021 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Sun, 12 Dec 2021 00:45:55 +0000 Subject: [Bug 14241] uudecode doesn't recognise the special decode_pathname /dev/stdout In-Reply-To: References: Message-ID: https://bugs.busybox.net/show_bug.cgi?id=14241 --- Comment #6 from Christoph Anton Mitterer --- Any reason why you make this dependent on ENABLE_DESKTOP? I mean POSIX is quite clear... it should simply always behave that way and especially not doing so can lead to security issues on systems where /dev/stdout doesn't exists as a file (which is linked to FD1). -- You are receiving this mail because: You are on the CC list for the bug. From bugzilla at busybox.net Sun Dec 12 00:53:00 2021 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Sun, 12 Dec 2021 00:53:00 +0000 Subject: [Bug 14241] uudecode doesn't recognise the special decode_pathname /dev/stdout In-Reply-To: References: Message-ID: https://bugs.busybox.net/show_bug.cgi?id=14241 Christoph Anton Mitterer changed: What |Removed |Added ---------------------------------------------------------------------------- Resolution|FIXED |--- Status|RESOLVED |REOPENED --- Comment #7 from Christoph Anton Mitterer --- I've reopened this... cause it seems ENABLE_DESKTOP is not enabled per default, and even if one chooses to enable it, several other things also change their behaviour. So the problem is that the default setup of busybox' uudecode still behaves wrong and is thus vulnerable. -- You are receiving this mail because: You are on the CC list for the bug. From bugzilla at busybox.net Sun Dec 12 02:08:25 2021 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Sun, 12 Dec 2021 02:08:25 +0000 Subject: [Bug 10571] busybox timeout options is not compatible with coreutils timeout In-Reply-To: References: Message-ID: https://bugs.busybox.net/show_bug.cgi?id=10571 Denys Vlasenko changed: What |Removed |Added ---------------------------------------------------------------------------- Resolution|--- |FIXED Status|NEW |RESOLVED --- Comment #3 from Denys Vlasenko --- DURATION discrepancy has been fixed: commit c9720a761e88e83265b4d75808533cdfbc66075b Date: Fri Aug 3 18:27:00 2018 +0200 timeout: fix arguments to match coreutils Was: timeout [-t SECS] [-s SIG] PROG ARGS Is: timeout [-s SIG] SECS PROG ARGS -- You are receiving this mail because: You are on the CC list for the bug. From vda.linux at googlemail.com Sun Dec 12 02:22:43 2021 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Sun, 12 Dec 2021 03:22:43 +0100 Subject: [git commit] wget: allow end-users to customize Content-Type for --post-data and --post-file Message-ID: <20211212021740.BC5AC82B41@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=b9fba185c570b52fccffa2b9ae39ba32a0860daf branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master More explanation in this PR: https://github.com/rmyorston/busybox-w32/pull/233 The real use-case: wget https://api.github.com/markdown/raw --header "Content-Type: text/plain" function old new delta wget_main 2560 2581 +21 wget_user_headers 62 76 +14 .rodata 104196 104197 +1 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 36/0) Total: 36 bytes Signed-off-by: Ildar Shaimordanov Signed-off-by: Denys Vlasenko --- networking/wget.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/networking/wget.c b/networking/wget.c index 91ef99eab..9ec0e67b9 100644 --- a/networking/wget.c +++ b/networking/wget.c @@ -211,29 +211,33 @@ enum { HDR_HOST = (1<<0), HDR_USER_AGENT = (1<<1), HDR_RANGE = (1<<2), - HDR_AUTH = (1<<3) * ENABLE_FEATURE_WGET_AUTHENTICATION, - HDR_PROXY_AUTH = (1<<4) * ENABLE_FEATURE_WGET_AUTHENTICATION, + HDR_CONTENT_TYPE = (1<<3), + HDR_AUTH = (1<<4) * ENABLE_FEATURE_WGET_AUTHENTICATION, + HDR_PROXY_AUTH = (1<<5) * ENABLE_FEATURE_WGET_AUTHENTICATION, }; static const char wget_user_headers[] ALIGN1 = "Host:\0" "User-Agent:\0" "Range:\0" + "Content-Type:\0" # if ENABLE_FEATURE_WGET_AUTHENTICATION "Authorization:\0" "Proxy-Authorization:\0" # endif ; -# define USR_HEADER_HOST (G.user_headers & HDR_HOST) -# define USR_HEADER_USER_AGENT (G.user_headers & HDR_USER_AGENT) -# define USR_HEADER_RANGE (G.user_headers & HDR_RANGE) -# define USR_HEADER_AUTH (G.user_headers & HDR_AUTH) -# define USR_HEADER_PROXY_AUTH (G.user_headers & HDR_PROXY_AUTH) +# define USR_HEADER_HOST (G.user_headers & HDR_HOST) +# define USR_HEADER_USER_AGENT (G.user_headers & HDR_USER_AGENT) +# define USR_HEADER_RANGE (G.user_headers & HDR_RANGE) +# define USR_HEADER_CONTENT_TYPE (G.user_headers & HDR_CONTENT_TYPE) +# define USR_HEADER_AUTH (G.user_headers & HDR_AUTH) +# define USR_HEADER_PROXY_AUTH (G.user_headers & HDR_PROXY_AUTH) #else /* No long options, no user-headers :( */ -# define USR_HEADER_HOST 0 -# define USR_HEADER_USER_AGENT 0 -# define USR_HEADER_RANGE 0 -# define USR_HEADER_AUTH 0 -# define USR_HEADER_PROXY_AUTH 0 +# define USR_HEADER_HOST 0 +# define USR_HEADER_USER_AGENT 0 +# define USR_HEADER_RANGE 0 +# define USR_HEADER_CONTENT_TYPE 0 +# define USR_HEADER_AUTH 0 +# define USR_HEADER_PROXY_AUTH 0 #endif /* Globals */ @@ -1261,8 +1265,13 @@ static void download_one_url(const char *url) } if (G.post_data) { + /* If user did not override it... */ + if (!USR_HEADER_CONTENT_TYPE) { + SENDFMT(sfp, + "Content-Type: application/x-www-form-urlencoded\r\n" + ); + } SENDFMT(sfp, - "Content-Type: application/x-www-form-urlencoded\r\n" "Content-Length: %u\r\n" "\r\n" "%s", From vda.linux at googlemail.com Sun Dec 12 12:16:40 2021 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Sun, 12 Dec 2021 13:16:40 +0100 Subject: [git commit] Makefile.flags: use all cflags for crypt and rt checks Message-ID: <20211212121147.7144882B5E@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=9b678807198611308cfd8b10427f9e08c62f7bec branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master To check if libcrypt and librt are available, we check if we can compile and link a simple test program. These checks do not match the actual linking if CONFIG_STATIC is enabled. For CONFIG_STATIC, CFLAGS_busybox is set to -static. The checks don't use CFLAGS_busybox and detect a shared libcrypt or librt. If we link busybox later and we have no static libcrypt or librt, linking will fail. Update the libcrypt and librt checks to use CFLAGS_busybox. Signed-off-by: Martin Kaiser Signed-off-by: Denys Vlasenko --- Makefile.flags | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile.flags b/Makefile.flags index 667481983..c34356230 100644 --- a/Makefile.flags +++ b/Makefile.flags @@ -151,8 +151,8 @@ LDLIBS += m # gcc-4.2.1 fails if we try to feed C source on stdin: # echo 'int main(void){return 0;}' | $(CC) $(CFLAGS) -lcrypt -o /dev/null -xc - # fall back to using a temp file: -CRYPT_AVAILABLE := $(shell echo 'int main(void){return 0;}' >bb_libtest.c; $(CC) $(CFLAGS) -lcrypt -o /dev/null bb_libtest.c >/dev/null 2>&1 && echo "y"; rm bb_libtest.c) -RT_AVAILABLE := $(shell echo 'int main(void){return 0;}' >bb_libtest.c; $(CC) $(CFLAGS) -lrt -o /dev/null bb_libtest.c >/dev/null 2>&1 && echo "y"; rm bb_libtest.c) +CRYPT_AVAILABLE := $(shell echo 'int main(void){return 0;}' >bb_libtest.c; $(CC) $(CFLAGS) $(CFLAGS_busybox) -lcrypt -o /dev/null bb_libtest.c >/dev/null 2>&1 && echo "y"; rm bb_libtest.c) +RT_AVAILABLE := $(shell echo 'int main(void){return 0;}' >bb_libtest.c; $(CC) $(CFLAGS) $(CFLAGS_busybox) -lrt -o /dev/null bb_libtest.c >/dev/null 2>&1 && echo "y"; rm bb_libtest.c) ifeq ($(CRYPT_AVAILABLE),y) LDLIBS += crypt endif From vda.linux at googlemail.com Sun Dec 12 16:13:54 2021 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Sun, 12 Dec 2021 17:13:54 +0100 Subject: [git commit] udhcpc6: fix udhcp_find_option to actually find DHCP6 options Message-ID: <20211212161123.70A4383562@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=e67b80f4739c4075b51b0a575701b73928fe0bf1 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master udhcp_insert_new_option treats code for IPv6 as follows: new->data[D6_OPT_CODE] = code >> 8; new->data[D6_OPT_CODE + 1] = code & 0xff; udhcp_find_option tests the code as follows: while (opt_list && opt_list->data[OPT_CODE] < code) ... if (opt_list && opt_list->data[OPT_CODE] == code) So yes, OPT_CODE and D6_OPT_CODE are both 0, but the D6_OPT_CLIENTID = 1 value means that the 1 is in the seconds byte, and udhcp_find_option is only looking at the first byte, So the send_d6_release can never find it the created option. function old new delta udhcp_find_option 28 53 +25 attach_option 276 284 +8 udhcpc6_main 2602 2607 +5 perform_d6_release 262 267 +5 udhcpd_main 1518 1520 +2 udhcpc_main 2542 2544 +2 add_serverid_and_clientid_options 46 48 +2 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 7/0 up/down: 49/0) Total: 49 bytes Signed-off-by: Denys Vlasenko --- networking/udhcp/common.c | 29 ++++++++++++++++++++++------- networking/udhcp/common.h | 6 +++++- networking/udhcp/d6_dhcpc.c | 5 +++-- networking/udhcp/dhcpc.c | 6 +++--- networking/udhcp/dhcpd.c | 2 +- 5 files changed, 34 insertions(+), 14 deletions(-) diff --git a/networking/udhcp/common.c b/networking/udhcp/common.c index 31e525cb0..8e9b93655 100644 --- a/networking/udhcp/common.c +++ b/networking/udhcp/common.c @@ -404,14 +404,29 @@ void FAST_FUNC udhcp_add_simple_option(struct dhcp_packet *packet, uint8_t code, #endif /* Find option 'code' in opt_list */ -struct option_set* FAST_FUNC udhcp_find_option(struct option_set *opt_list, uint8_t code) +struct option_set* FAST_FUNC udhcp_find_option(struct option_set *opt_list, uint8_t code, bool dhcpv6) { - while (opt_list && opt_list->data[OPT_CODE] < code) - opt_list = opt_list->next; + IF_NOT_UDHCPC6(bool dhcpv6 = 0;) + uint8_t cur_code; - if (opt_list && opt_list->data[OPT_CODE] == code) - return opt_list; - return NULL; + for (;;) { + if (!opt_list) + return opt_list; /* NULL */ + if (!dhcpv6) { + cur_code = opt_list->data[OPT_CODE]; + } else { +//FIXME: add support for code > 0xff + if (opt_list->data[D6_OPT_CODE] != 0) + return NULL; + cur_code = opt_list->data[D6_OPT_CODE + 1]; + } + if (cur_code >= code) { + if (cur_code == code) + return opt_list; + return NULL; + } + opt_list = opt_list->next; + } } /* Parse string to IP in network order */ @@ -499,7 +514,7 @@ static NOINLINE void attach_option( } #endif - existing = udhcp_find_option(*opt_list, optflag->code); + existing = udhcp_find_option(*opt_list, optflag->code, dhcpv6); if (!existing) { /* make a new option */ uint8_t *p = udhcp_insert_new_option(opt_list, optflag->code, length, dhcpv6); diff --git a/networking/udhcp/common.h b/networking/udhcp/common.h index e374771cb..5882238e3 100644 --- a/networking/udhcp/common.h +++ b/networking/udhcp/common.h @@ -245,7 +245,11 @@ void udhcp_add_simple_option(struct dhcp_packet *packet, uint8_t code, uint32_t char *dname_dec(const uint8_t *cstr, int clen, const char *pre) FAST_FUNC; uint8_t *dname_enc(/*const uint8_t *cstr, int clen,*/ const char *src, int *retlen) FAST_FUNC; #endif -struct option_set *udhcp_find_option(struct option_set *opt_list, uint8_t code) FAST_FUNC; +#if !ENABLE_UDHCPC6 +#define udhcp_find_option(opt_list, code, dhcpv6) \ + udhcp_find_option(opt_list, code) +#endif +struct option_set *udhcp_find_option(struct option_set *opt_list, uint8_t code, bool dhcpv6) FAST_FUNC; // RFC 2131 Table 5: Fields and options used by DHCP clients // diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c index 8d11a7539..9d2a8f5d3 100644 --- a/networking/udhcp/d6_dhcpc.c +++ b/networking/udhcp/d6_dhcpc.c @@ -888,7 +888,8 @@ int send_d6_release(struct in6_addr *server_ipv6, struct in6_addr *our_cur_ipv6) if (client6_data.ia_pd) opt_ptr = mempcpy(opt_ptr, client6_data.ia_pd, client6_data.ia_pd->len + 2+2); /* Client-id */ - ci = udhcp_find_option(client_data.options, D6_OPT_CLIENTID); +///vda + ci = udhcp_find_option(client_data.options, D6_OPT_CLIENTID, /*dhcpv6:*/ 1); if (ci) opt_ptr = mempcpy(opt_ptr, ci->data, D6_OPT_DATA + 2+2 + 6); @@ -1272,7 +1273,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) } clientid_mac_ptr = NULL; - if (!udhcp_find_option(client_data.options, D6_OPT_CLIENTID)) { + if (!udhcp_find_option(client_data.options, D6_OPT_CLIENTID, /*dhcpv6:*/ 1)) { /* not set, set the default client ID */ clientid_mac_ptr = udhcp_insert_new_option( &client_data.options, D6_OPT_CLIENTID, diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index 331f13a8c..c757fb37c 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c @@ -658,7 +658,7 @@ static void add_client_options(struct dhcp_packet *packet) // This will be needed if we remove -V VENDOR_STR in favor of // -x vendor:VENDOR_STR - //if (!udhcp_find_option(packet.options, DHCP_VENDOR)) + //if (!udhcp_find_option(packet.options, DHCP_VENDOR, /*dhcpv6:*/ 0)) // /* not set, set the default vendor ID */ // ...add (DHCP_VENDOR, "udhcp "BB_VER) opt... } @@ -676,7 +676,7 @@ static void add_serverid_and_clientid_options(struct dhcp_packet *packet, uint32 * If the client used a 'client identifier' when it obtained the lease, * it MUST use the same 'client identifier' in the DHCPRELEASE message. */ - ci = udhcp_find_option(client_data.options, DHCP_CLIENT_ID); + ci = udhcp_find_option(client_data.options, DHCP_CLIENT_ID, /*dhcpv6:*/ 0); if (ci) udhcp_add_binary_option(packet, ci->data); } @@ -1328,7 +1328,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) } clientid_mac_ptr = NULL; - if (!(opt & OPT_C) && !udhcp_find_option(client_data.options, DHCP_CLIENT_ID)) { + if (!(opt & OPT_C) && !udhcp_find_option(client_data.options, DHCP_CLIENT_ID, /*dhcpv6:*/ 0)) { /* not suppressed and not set, create default client ID */ clientid_mac_ptr = udhcp_insert_new_option( &client_data.options, DHCP_CLIENT_ID, diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c index 0f5edb75c..66750e2e6 100644 --- a/networking/udhcp/dhcpd.c +++ b/networking/udhcp/dhcpd.c @@ -935,7 +935,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) bb_simple_info_msg("started, v"BB_VER); - option = udhcp_find_option(server_data.options, DHCP_LEASE_TIME); + option = udhcp_find_option(server_data.options, DHCP_LEASE_TIME, /*dhcpv6:*/ 0); server_data.max_lease_sec = DEFAULT_LEASE_TIME; if (option) { move_from_unaligned32(server_data.max_lease_sec, option->data + OPT_DATA); From bugzilla at busybox.net Sun Dec 12 21:19:28 2021 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Sun, 12 Dec 2021 21:19:28 +0000 Subject: [Bug 14441] syntax error: unexpected end of file (expecting "fi") In-Reply-To: References: Message-ID: https://bugs.busybox.net/show_bug.cgi?id=14441 --- Comment #1 from Denys Vlasenko --- The script contains nothing but comments in the first 6 lines: #!/bin/sh # # $Id: //WIFI_SOC/MP/SDK_4_2_0_0/RT288x_SDK/source/user/rt2880_app/scripts/lan.sh#1 $ # # usage: wan.sh # so it's very unusual. Do you have a semi-reliable way to trigger this? E.g. running it in a loop until it happens? What machine/architecture does this happen on? Is it reproducible on a x86 machine? Is it reproducible with busybox binary which you yourself compiled (and therefore can recompile, to add debugging and such)? What is the .config? -- You are receiving this mail because: You are on the CC list for the bug. From bugzilla at busybox.net Sun Dec 12 21:19:45 2021 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Sun, 12 Dec 2021 21:19:45 +0000 Subject: [Bug 14436] syntax error: unexpected "fi" (expecting "then") In-Reply-To: References: Message-ID: https://bugs.busybox.net/show_bug.cgi?id=14436 Denys Vlasenko changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution|--- |DUPLICATE --- Comment #1 from Denys Vlasenko --- *** This bug has been marked as a duplicate of bug 14441 *** -- You are receiving this mail because: You are on the CC list for the bug. From bugzilla at busybox.net Sun Dec 12 21:19:45 2021 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Sun, 12 Dec 2021 21:19:45 +0000 Subject: [Bug 14441] syntax error: unexpected end of file (expecting "fi") In-Reply-To: References: Message-ID: https://bugs.busybox.net/show_bug.cgi?id=14441 --- Comment #2 from Denys Vlasenko --- *** Bug 14436 has been marked as a duplicate of this bug. *** -- You are receiving this mail because: You are on the CC list for the bug. From vda.linux at googlemail.com Sun Dec 12 22:34:43 2021 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Sun, 12 Dec 2021 23:34:43 +0100 Subject: [git commit] libarchive/get_header_ar.c: fix extraction of archives from binutils in deterministic mode Message-ID: <20211212222955.C96918375F@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=cb91a818c8f7730d8f3b30b5b4e75fd21496609f branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master GNU binutils in deterministic mode (ar rD or built with --enable-deterministic-archives) hard codes file mode to 0644 (NOT 0100644) since https://github.com/bminor/binutils-gdb/commit/36e4dce69dd2 This confuses busybox ar x (data_extract_all): touch a; ar rD a.ar a ar: creating a.ar busybox ar x a.ar ar: unrecognized file type hexdump -C a.ar 00000000 21 3c 61 72 63 68 3e 0a 61 2f 20 20 20 20 20 20 |!.a/ | 00000010 20 20 20 20 20 20 20 20 30 20 20 20 20 20 20 20 | 0 | 00000020 20 20 20 20 30 20 20 20 20 20 30 20 20 20 20 20 | 0 0 | 00000030 36 34 34 20 20 20 20 20 30 20 20 20 20 20 20 20 |644 0 | 00000040 20 20 60 0a | `.| As a workaround, force the mode bits to S_IFREG, as nothing else makes sense for ar. function old new delta get_header_ar 539 542 +3 Signed-off-by: Peter Korsgaard Signed-off-by: Denys Vlasenko --- archival/libarchive/get_header_ar.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/archival/libarchive/get_header_ar.c b/archival/libarchive/get_header_ar.c index 3a19d6ff7..6bd897392 100644 --- a/archival/libarchive/get_header_ar.c +++ b/archival/libarchive/get_header_ar.c @@ -92,8 +92,12 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle) /* Only size is always present, the rest may be missing in * long filename pseudo file. Thus we decode the rest * after dealing with long filename pseudo file. + * + * GNU binutils in deterministic mode hard codes mode to 0644 (NOT + * 0100644). AR archives can only contain files, so force file + * mode. */ - typed->mode = read_num(ar.formatted.mode, 8, sizeof(ar.formatted.mode)); + typed->mode = read_num(ar.formatted.mode, 8, sizeof(ar.formatted.mode)) | S_IFREG; typed->gid = read_num(ar.formatted.gid, 10, sizeof(ar.formatted.gid)); typed->uid = read_num(ar.formatted.uid, 10, sizeof(ar.formatted.uid)); typed->mtime = read_num(ar.formatted.date, 10, sizeof(ar.formatted.date)); From bugzilla at busybox.net Mon Dec 13 18:13:17 2021 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Mon, 13 Dec 2021 18:13:17 +0000 Subject: [Bug 14441] syntax error: unexpected end of file (expecting "fi") In-Reply-To: References: Message-ID: https://bugs.busybox.net/show_bug.cgi?id=14441 --- Comment #3 from Mihaela Gentner --- Created attachment 9191 --> https://bugs.busybox.net/attachment.cgi?id=9191&action=edit The .config file -- You are receiving this mail because: You are on the CC list for the bug. From bugzilla at busybox.net Mon Dec 13 18:22:28 2021 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Mon, 13 Dec 2021 18:22:28 +0000 Subject: [Bug 14441] syntax error: unexpected end of file (expecting "fi") In-Reply-To: References: Message-ID: https://bugs.busybox.net/show_bug.cgi?id=14441 --- Comment #4 from Mihaela Gentner --- (In reply to Denys Vlasenko from comment #1) Running the script in a loop in order to reproduce the issue faster is an idea worth trying. The architecture of the system is MIPS 32Bit LE. I don't know if the issue is reproducible on a x86 machine. Yes, the issue reproduces with a busybox binary which is compiled by me. Currently waiting for the issue to reproduce on an image with increased debugging verbosity. Attached the .config file in the previous comment. I have to mention that in this project there are a lot of scripts which are large in size (up to 32K), and a lot of include of scripts inside them. Could that be an issue? Is there a specific configuration value that should be turned on, in order to support big files? -- You are receiving this mail because: You are on the CC list for the bug. From bugzilla at busybox.net Tue Dec 14 15:35:34 2021 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Tue, 14 Dec 2021 15:35:34 +0000 Subject: [Bug 14456] New: DHCP Client: DHCPNAK behavior Message-ID: https://bugs.busybox.net/show_bug.cgi?id=14456 Bug ID: 14456 Summary: DHCP Client: DHCPNAK behavior Product: Busybox Version: unspecified Hardware: All OS: Linux Status: NEW Severity: normal Priority: P5 Component: Networking Assignee: unassigned at busybox.net Reporter: viordash at mail.ru CC: busybox-cvs at busybox.net Target Milestone: --- Hi! Faced with the issue of not responding to DHCPNAK from another server, I then compared the behavior between busybox udhcp client and isc dhclient when receiving DHCPNAK. And behaviors are different. Your client checks for server_id matching, this check was introduced for the fix, Bug 4267. But in isc dhclient there is no check for server_id and it seems to me correct, because in rfc2131 I did not find requirements for matching server_id in the request for the client, but I found the following text: --------------- RFC 2131 [Page 17] If the client receives a DHCPNAK message, the client restarts the configuration process. --------------- Here is another piece of text from rfc2131, which I believe points to the key moment of using server_id in the client: --------------- RFC 2131 [Page 23] DHCP clients MUST use the IP address provided in the 'server identifier' option for any unicast requests to the DHCP server. --------------- this is also consistent with rfc2132: --------------- RFC 2132 [Page 27] DHCP clients use the contents of the 'server identifier' field as the destination address for any DHCP messages unicast to the DHCP server. --------------- -- You are receiving this mail because: You are on the CC list for the bug. From vda.linux at googlemail.com Fri Dec 17 19:37:58 2021 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Fri, 17 Dec 2021 20:37:58 +0100 Subject: [git commit] httpd: don't send Content-Length in error pages header Message-ID: <20211217193316.2D3F78257C@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=70683faf380681a11e16a85090162581aed55d73 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta send_headers 701 713 +12 Signed-off-by: Denys Vlasenko --- networking/httpd.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/networking/httpd.c b/networking/httpd.c index 31c8489d3..4def1b6fc 100644 --- a/networking/httpd.c +++ b/networking/httpd.c @@ -1125,7 +1125,7 @@ static void send_headers(unsigned responseNum) "Connection: close\r\n", responseNum, responseString #if ENABLE_FEATURE_HTTPD_DATE - ,date_str + , date_str #endif ); } @@ -1222,17 +1222,29 @@ static void send_headers(unsigned responseNum) // (NB: standards do not define "Transfer-Length:" _header_, // transfer-length above is just a concept). +#if ENABLE_FEATURE_HTTPD_RANGES \ + || ENABLE_FEATURE_HTTPD_LAST_MODIFIED \ + || ENABLE_FEATURE_HTTPD_ETAG len += sprintf(iobuf + len, -#if ENABLE_FEATURE_HTTPD_RANGES +# if ENABLE_FEATURE_HTTPD_RANGES "Accept-Ranges: bytes\r\n" -#endif -#if ENABLE_FEATURE_HTTPD_LAST_MODIFIED +# endif +# if ENABLE_FEATURE_HTTPD_LAST_MODIFIED "Last-Modified: %s\r\n" -#endif -#if ENABLE_FEATURE_HTTPD_ETAG +# endif +# if ENABLE_FEATURE_HTTPD_ETAG "ETag: %s\r\n" +# endif +# if ENABLE_FEATURE_HTTPD_LAST_MODIFIED + , date_str +# endif +# if ENABLE_FEATURE_HTTPD_ETAG + , G.etag +# endif #endif - + ); + if (!infoString) { + len += sprintf(iobuf + len, /* Because of 4.4 (5), we can forgo sending of "Content-Length" * since we close connection afterwards, but it helps clients * to e.g. estimate download times, show progress bars etc. @@ -1240,14 +1252,9 @@ static void send_headers(unsigned responseNum) * but de-facto standard is to send it (see comment below). */ "Content-Length: %"OFF_FMT"u\r\n", -#if ENABLE_FEATURE_HTTPD_LAST_MODIFIED - date_str, -#endif -#if ENABLE_FEATURE_HTTPD_ETAG - G.etag, -#endif file_size - ); + ); + } } /* This should be "Transfer-Encoding", not "Content-Encoding": From vda.linux at googlemail.com Fri Dec 17 20:02:16 2021 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Fri, 17 Dec 2021 21:02:16 +0100 Subject: [git commit] httpd: do not send Last-Modified / ETag / Content-Length for error pages Message-ID: <20211217195821.0D709824F3@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=b720629dfec0e8e991e75b751dad215af2bc657f branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta send_headers 713 701 -12 send_headers_and_exit 20 34 +14 Signed-off-by: Denys Vlasenko --- networking/httpd.c | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/networking/httpd.c b/networking/httpd.c index 4def1b6fc..1ba1d1063 100644 --- a/networking/httpd.c +++ b/networking/httpd.c @@ -1222,29 +1222,17 @@ static void send_headers(unsigned responseNum) // (NB: standards do not define "Transfer-Length:" _header_, // transfer-length above is just a concept). -#if ENABLE_FEATURE_HTTPD_RANGES \ - || ENABLE_FEATURE_HTTPD_LAST_MODIFIED \ - || ENABLE_FEATURE_HTTPD_ETAG len += sprintf(iobuf + len, -# if ENABLE_FEATURE_HTTPD_RANGES +#if ENABLE_FEATURE_HTTPD_RANGES "Accept-Ranges: bytes\r\n" -# endif -# if ENABLE_FEATURE_HTTPD_LAST_MODIFIED +#endif +#if ENABLE_FEATURE_HTTPD_LAST_MODIFIED "Last-Modified: %s\r\n" -# endif -# if ENABLE_FEATURE_HTTPD_ETAG +#endif +#if ENABLE_FEATURE_HTTPD_ETAG "ETag: %s\r\n" -# endif -# if ENABLE_FEATURE_HTTPD_LAST_MODIFIED - , date_str -# endif -# if ENABLE_FEATURE_HTTPD_ETAG - , G.etag -# endif #endif - ); - if (!infoString) { - len += sprintf(iobuf + len, + /* Because of 4.4 (5), we can forgo sending of "Content-Length" * since we close connection afterwards, but it helps clients * to e.g. estimate download times, show progress bars etc. @@ -1252,9 +1240,14 @@ static void send_headers(unsigned responseNum) * but de-facto standard is to send it (see comment below). */ "Content-Length: %"OFF_FMT"u\r\n", +#if ENABLE_FEATURE_HTTPD_LAST_MODIFIED + date_str, +#endif +#if ENABLE_FEATURE_HTTPD_ETAG + G.etag, +#endif file_size - ); - } + ); } /* This should be "Transfer-Encoding", not "Content-Encoding": @@ -1297,6 +1290,7 @@ static void send_headers_and_exit(int responseNum) NORETURN; static void send_headers_and_exit(int responseNum) { IF_FEATURE_HTTPD_GZIP(content_gzip = 0;) + file_size = -1; /* no Last-Modified:, ETag:, Content-Length: */ send_headers(responseNum); log_and_exit(); } From vda.linux at googlemail.com Fri Dec 17 20:13:26 2021 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Fri, 17 Dec 2021 21:13:26 +0100 Subject: [git commit] printf: allow 0 as a flag and allow multiple flags Message-ID: <20211217200956.D68E282287@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=7105e4afddbf47b494accce40e2a701b8833e6ce branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master The '%' character in a format specification may be followed by one or more flags from the list "+- #0". BusyBox printf didn't support the '0' flag or allow multiple flags to be provided. As a result the formats '%0*d' and '%0 d' were considered to be invalid. The lack of support for '0' was pointed out by Andrew Snyder on the musl mailing list: https://www.openwall.com/lists/musl/2021/12/14/2 function old new delta printf_main 860 891 +31 .rodata 99281 99282 +1 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 32/0) Total: 32 bytes Signed-off-by: Ron Yorston Signed-off-by: Denys Vlasenko --- coreutils/printf.c | 2 +- testsuite/printf.tests | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/coreutils/printf.c b/coreutils/printf.c index dd94c8ade..2e672d15f 100644 --- a/coreutils/printf.c +++ b/coreutils/printf.c @@ -313,7 +313,7 @@ static char **print_formatted(char *f, char **argv, int *conv_err) } break; } - if (*f && strchr("-+ #", *f)) { + while (*f && strchr("-+ #0", *f)) { ++f; ++direc_length; } diff --git a/testsuite/printf.tests b/testsuite/printf.tests index 050edef71..728bbf4bf 100755 --- a/testsuite/printf.tests +++ b/testsuite/printf.tests @@ -143,4 +143,14 @@ testing "printf aborts on %r" \ "printf: %r: invalid format\n""1\n" \ "" "" +testing "printf treats leading 0 as flag" \ + "${bb}printf '%0*d\n' 2 1 2>&1; echo \$?" \ + "01\n""0\n" \ + "" "" + +testing "printf handles multiple flags" \ + "${bb}printf '%0 d\n' 2 2>&1; echo \$?" \ + " 2\n""0\n" \ + "" "" + exit $FAILCOUNT From vda.linux at googlemail.com Fri Dec 17 20:38:02 2021 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Fri, 17 Dec 2021 21:38:02 +0100 Subject: [git commit] docs/embedded-scripts.txt: whitespace fix Message-ID: <20211217203253.4A31B8257F@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=00d10cb6eb47e73bd88ab7e884562b555462815f branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master Signed-off-by: Denys Vlasenko --- docs/embedded-scripts.txt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/embedded-scripts.txt b/docs/embedded-scripts.txt index 7a273d698..f6f107d4e 100644 --- a/docs/embedded-scripts.txt +++ b/docs/embedded-scripts.txt @@ -55,19 +55,19 @@ Next we need the configuration data. This is very similar to the example code for the native applet: //config:config MU -//config: bool "MU" -//config: default y -//config: help -//config: Returns an indeterminate value. +//config: bool "MU" +//config: default y +//config: help +//config: Returns an indeterminate value. //applet:IF_MU(APPLET_SCRIPTED(mu, scripted, BB_DIR_USR_BIN, BB_SUID_DROP, mu)) //usage:#define mu_trivial_usage -//usage: "[-abcde] FILE..." +//usage: "[-abcde] FILE..." //usage:#define mu_full_usage -//usage: "Returns an indeterminate value\n" -//usage: "\n -a First function" -//usage: "\n -b Second function" +//usage: "Returns an indeterminate value\n" +//usage: "\n -a First function" +//usage: "\n -b Second function" The only difference is that the applet is specified as being of type APPLET_SCRIPTED. It would also be useful to include details of any From vda.linux at googlemail.com Fri Dec 17 20:33:15 2021 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Fri, 17 Dec 2021 21:33:15 +0100 Subject: [git commit] find: implement -samefile Message-ID: <20211217203253.412DE821F3@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=aaade69ce9faac6c05ab8b800fc9e9d4dee8ed54 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta parse_params 1461 1606 +145 func_samefile - 42 +42 packed_usage 34079 34102 +23 static.params 261 271 +10 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 3/0 up/down: 220/0) Total: 220 bytes Signed-off-by: Aaro Koskinen Signed-off-by: Denys Vlasenko --- findutils/find.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/findutils/find.c b/findutils/find.c index fdc5c152d..bb6ad31e5 100644 --- a/findutils/find.c +++ b/findutils/find.c @@ -155,6 +155,13 @@ //config: default y //config: depends on FIND //config: +//config:config FEATURE_FIND_SAMEFILE +//config: bool "Enable -samefile: reference file matching" +//config: default y +//config: depends on FIND +//config: help +//config: Support the 'find -samefile' option for searching by a reference file. +//config: //config:config FEATURE_FIND_EXEC //config: bool "Enable -exec: execute commands" //config: default y @@ -350,6 +357,9 @@ //usage: IF_FEATURE_FIND_INUM( //usage: "\n -inum N File has inode number N" //usage: ) +//usage: IF_FEATURE_FIND_SAMEFILE( +//usage: "\n -samefile FILE File is same as FILE" +//usage: ) //usage: IF_FEATURE_FIND_USER( //usage: "\n -user NAME/ID File is owned by given user" //usage: ) @@ -444,6 +454,7 @@ IF_FEATURE_FIND_MTIME( ACTS(mtime, unsigned char time_type; unsigned char mtime IF_FEATURE_FIND_MMIN( ACTS(mmin, unsigned char time_type; unsigned char mmin_char; unsigned mmin_mins;)) IF_FEATURE_FIND_NEWER( ACTS(newer, time_t newer_mtime;)) IF_FEATURE_FIND_INUM( ACTS(inum, ino_t inode_num;)) +IF_FEATURE_FIND_SAMEFILE(ACTS(samefile, ino_t inode_num; dev_t device;)) IF_FEATURE_FIND_USER( ACTS(user, uid_t uid;)) IF_FEATURE_FIND_SIZE( ACTS(size, char size_char; off_t size;)) IF_FEATURE_FIND_CONTEXT(ACTS(context, security_context_t context;)) @@ -731,6 +742,13 @@ ACTF(inum) return (statbuf->st_ino == ap->inode_num); } #endif +#if ENABLE_FEATURE_FIND_SAMEFILE +ACTF(samefile) +{ + return statbuf->st_ino == ap->inode_num && + statbuf->st_dev == ap->device; +} +#endif #if ENABLE_FEATURE_FIND_EXEC static int do_exec(action_exec *ap, const char *fileName) { @@ -1125,6 +1143,7 @@ static action*** parse_params(char **argv) IF_FEATURE_FIND_CMIN( PARM_cmin ,) IF_FEATURE_FIND_NEWER( PARM_newer ,) IF_FEATURE_FIND_INUM( PARM_inum ,) + IF_FEATURE_FIND_SAMEFILE(PARM_samefile ,) IF_FEATURE_FIND_USER( PARM_user ,) IF_FEATURE_FIND_GROUP( PARM_group ,) IF_FEATURE_FIND_SIZE( PARM_size ,) @@ -1173,6 +1192,7 @@ static action*** parse_params(char **argv) IF_FEATURE_FIND_CMIN( "-cmin\0" ) IF_FEATURE_FIND_NEWER( "-newer\0" ) IF_FEATURE_FIND_INUM( "-inum\0" ) + IF_FEATURE_FIND_SAMEFILE("-samefile\0") IF_FEATURE_FIND_USER( "-user\0" ) IF_FEATURE_FIND_GROUP( "-group\0" ) IF_FEATURE_FIND_SIZE( "-size\0" ) @@ -1511,6 +1531,21 @@ static action*** parse_params(char **argv) ap->inode_num = xatoul(arg1); } #endif +#if ENABLE_FEATURE_FIND_SAMEFILE + else if (parm == PARM_samefile) { + action_samefile *ap; + struct stat stbuf; + dbg("%d", __LINE__); + if (G.recurse_flags & (ACTION_FOLLOWLINKS | + ACTION_FOLLOWLINKS_L0)) + xstat(arg1, &stbuf); + else if (lstat(arg1, &stbuf)) + bb_perror_msg_and_die("can't stat '%s'", arg1); + ap = ALLOC_ACTION(samefile); + ap->inode_num = stbuf.st_ino; + ap->device = stbuf.st_dev; + } +#endif #if ENABLE_FEATURE_FIND_USER else if (parm == PARM_user) { action_user *ap; From vda.linux at googlemail.com Fri Dec 17 21:07:06 2021 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Fri, 17 Dec 2021 22:07:06 +0100 Subject: [git commit] cmp: add support for -n Message-ID: <20211217210758.BCC0C82143@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=579894bfd28ffb38f7dabc7862d4e7ebfade2865 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master Add support to for "-n" to cmp in order to compare at most n bytes. function old new delta cmp_main 552 589 +37 .rodata 104198 104203 +5 packed_usage 34102 34074 -28 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/1 up/down: 42/-28) Total: 14 bytes Signed-off-by: Walter Lozano Signed-off-by: Denys Vlasenko --- editors/cmp.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/editors/cmp.c b/editors/cmp.c index e106d814e..9eaff2b8e 100644 --- a/editors/cmp.c +++ b/editors/cmp.c @@ -18,12 +18,13 @@ //kbuild:lib-$(CONFIG_CMP) += cmp.o //usage:#define cmp_trivial_usage -//usage: "[-ls] FILE1 [FILE2" IF_DESKTOP(" [SKIP1 [SKIP2]]") "]" +//usage: "[-ls] [-n NUM] FILE1 [FILE2" IF_DESKTOP(" [SKIP1 [SKIP2]]") "]" //usage:#define cmp_full_usage "\n\n" //usage: "Compare FILE1 with FILE2 (or stdin)\n" //usage: "\n -l Write the byte numbers (decimal) and values (octal)" //usage: "\n for all differing bytes" //usage: "\n -s Quiet" +//usage: "\n -n NUM Compare at most NUM bytes" /* BB_AUDIT SUSv3 (virtually) compliant -- uses nicer GNU format for -l. */ /* http://www.opengroup.org/onlinepubs/007904975/utilities/cmp.html */ @@ -35,9 +36,10 @@ static const char fmt_differ[] ALIGN1 = "%s %s differ: char %"OFF_FMT"u, line %u // This fmt_l_opt uses gnu-isms. SUSv3 would be "%.0s%.0s%"OFF_FMT"u %o %o\n" static const char fmt_l_opt[] ALIGN1 = "%.0s%.0s%"OFF_FMT"u %3o %3o\n"; -#define OPT_STR "sl" +#define OPT_STR "sln:" #define CMP_OPT_s (1<<0) #define CMP_OPT_l (1<<1) +#define CMP_OPT_n (1<<2) int cmp_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int cmp_main(int argc UNUSED_PARAM, char **argv) @@ -50,13 +52,15 @@ int cmp_main(int argc UNUSED_PARAM, char **argv) int c1, c2; unsigned opt; int retval = 0; + int max_count = -1; opt = getopt32(argv, "^" OPT_STR - "\0" "-1" + "\0" "-1:n+" IF_DESKTOP(":?4") IF_NOT_DESKTOP(":?2") - ":l--s:s--l" + ":l--s:s--l", + &max_count ); argv += optind; @@ -95,6 +99,8 @@ int cmp_main(int argc UNUSED_PARAM, char **argv) while (skip2) { getc(fp2); skip2--; } } do { + if (max_count >= 0 && --max_count < 0) + break; c1 = getc(fp1); c2 = getc(fp2); ++char_pos; From vda.linux at googlemail.com Fri Dec 17 21:35:25 2021 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Fri, 17 Dec 2021 22:35:25 +0100 Subject: [git commit] ed: add support for -p command-line option as mandated by POSIX Message-ID: <20211217213022.8A6AB7F9D3@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=bfd8738154747d16f66ccfde3036dc21d39c7cec branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master The POSIX.1-2008 specification of ed(1) mandates two command-line options: -p (for specifying a prompt string) and -s (to suppress writing of byte counts). This commit adds support for the former. Furthermore, it also changes the default prompt string to an empty string (instead of ": ") since this is also mandated by POSIX: -p??string Use string as the prompt string when in command mode. By default, there shall be no prompt string. function old new delta ed_main 112 144 +32 packed_usage 34074 34097 +23 doCommands 1889 1887 -2 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/1 up/down: 55/-2) Total: 53 bytes Signed-off-by: S??ren Tempel Signed-off-by: Denys Vlasenko --- editors/ed.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/editors/ed.c b/editors/ed.c index 14540e566..18faba5a4 100644 --- a/editors/ed.c +++ b/editors/ed.c @@ -18,7 +18,7 @@ //applet:IF_ED(APPLET(ed, BB_DIR_BIN, BB_SUID_DROP)) -//usage:#define ed_trivial_usage "[FILE]" +//usage:#define ed_trivial_usage "[-p PROMPT] [FILE]" //usage:#define ed_full_usage "" #include "libbb.h" @@ -48,6 +48,7 @@ struct globals { char *bufBase; char *bufPtr; char *fileName; + const char *prompt; LINE lines; smallint dirty; int marks[26]; @@ -57,6 +58,7 @@ struct globals { #define bufBase (G.bufBase ) #define bufPtr (G.bufPtr ) #define fileName (G.fileName ) +#define prompt (G.prompt ) #define curNum (G.curNum ) #define lastNum (G.lastNum ) #define bufUsed (G.bufUsed ) @@ -793,7 +795,7 @@ static void doCommands(void) * 0 on ctrl-C, * >0 length of input string, including terminating '\n' */ - len = read_line_input(NULL, ": ", buf, sizeof(buf)); + len = read_line_input(NULL, prompt, buf, sizeof(buf)); if (len <= 0) return; while (len && isspace(buf[--len])) @@ -1005,8 +1007,12 @@ int ed_main(int argc UNUSED_PARAM, char **argv) lines.next = &lines; lines.prev = &lines; - if (argv[1]) { - fileName = xstrdup(argv[1]); + prompt = ""; /* no prompt by default */ + getopt32(argv, "p:", &prompt); + argv += optind; + + if (argv[0]) { + fileName = xstrdup(argv[0]); if (!readLines(fileName, 1)) { return EXIT_SUCCESS; } From vda.linux at googlemail.com Fri Dec 17 21:43:45 2021 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Fri, 17 Dec 2021 22:43:45 +0100 Subject: [git commit] cmp: code shrink Message-ID: <20211217213842.3F0EB801BA@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=c1eac153e8b89cfc9d550991735c09bad1579201 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta .rodata 104203 104201 -2 Signed-off-by: Denys Vlasenko --- editors/cmp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/editors/cmp.c b/editors/cmp.c index 9eaff2b8e..6d2b0c6c3 100644 --- a/editors/cmp.c +++ b/editors/cmp.c @@ -36,7 +36,7 @@ static const char fmt_differ[] ALIGN1 = "%s %s differ: char %"OFF_FMT"u, line %u // This fmt_l_opt uses gnu-isms. SUSv3 would be "%.0s%.0s%"OFF_FMT"u %o %o\n" static const char fmt_l_opt[] ALIGN1 = "%.0s%.0s%"OFF_FMT"u %3o %3o\n"; -#define OPT_STR "sln:" +#define OPT_STR "sln:+" #define CMP_OPT_s (1<<0) #define CMP_OPT_l (1<<1) #define CMP_OPT_n (1<<2) @@ -56,7 +56,7 @@ int cmp_main(int argc UNUSED_PARAM, char **argv) opt = getopt32(argv, "^" OPT_STR - "\0" "-1:n+" + "\0" "-1" IF_DESKTOP(":?4") IF_NOT_DESKTOP(":?2") ":l--s:s--l", From vda.linux at googlemail.com Fri Dec 17 22:11:17 2021 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Fri, 17 Dec 2021 23:11:17 +0100 Subject: [git commit] timeout: add support for "timeout -k KILL_SECS" Message-ID: <20211217220613.B4D6F81331@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=7d49fedc86bec300d22f44f93ec95825320dd1c1 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta timeout_main 307 373 +66 timeout_wait - 42 +42 .rodata 104201 104203 +2 packed_usage 34097 34096 -1 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 2/1 up/down: 110/-1) Total: 109 bytes Signed-off-by: Matthew Slowe Signed-off-by: Denys Vlasenko --- coreutils/timeout.c | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/coreutils/timeout.c b/coreutils/timeout.c index 8485e1e7d..06108f315 100644 --- a/coreutils/timeout.c +++ b/coreutils/timeout.c @@ -39,13 +39,29 @@ //kbuild:lib-$(CONFIG_TIMEOUT) += timeout.o //usage:#define timeout_trivial_usage -//usage: "[-s SIG] SECS PROG ARGS" +//usage: "[-s SIG] [-k KILL_SECS] SECS PROG ARGS" //usage:#define timeout_full_usage "\n\n" //usage: "Run PROG. Send SIG to it if it is not gone in SECS seconds.\n" //usage: "Default SIG: TERM." +//usage: "If it still exists in KILL_SECS seconds, send KILL.\n" #include "libbb.h" +static NOINLINE int timeout_wait(int timeout, pid_t pid) +{ + /* Just sleep(HUGE_NUM); kill(parent) may kill wrong process! */ + while (1) { + sleep1(); + if (--timeout <= 0) + break; + if (kill(pid, 0)) { + /* process is gone */ + return EXIT_SUCCESS; + } + } + return EXIT_FAILURE; +} + int timeout_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int timeout_main(int argc UNUSED_PARAM, char **argv) { @@ -53,23 +69,29 @@ int timeout_main(int argc UNUSED_PARAM, char **argv) int status; int parent = 0; int timeout; + int kill_timeout; pid_t pid; #if !BB_MMU char *sv1, *sv2; #endif const char *opt_s = "TERM"; + char *opt_k = NULL; /* -p option is not documented, it is needed to support NOMMU. */ /* -t SECONDS; -p PARENT_PID */ /* '+': stop at first non-option */ - getopt32(argv, "+s:" USE_FOR_NOMMU("p:+"), &opt_s, &parent); + getopt32(argv, "+s:k:" USE_FOR_NOMMU("p:+"), &opt_s, &opt_k, &parent); /*argv += optind; - no, wait for bb_daemonize_or_rexec! */ signo = get_signum(opt_s); if (signo < 0) bb_error_msg_and_die("unknown signal '%s'", opt_s); + kill_timeout = 0; + if (opt_k) + kill_timeout = parse_duration_str(opt_k); + if (!argv[optind]) bb_show_usage(); timeout = parse_duration_str(argv[optind++]); @@ -103,17 +125,16 @@ int timeout_main(int argc UNUSED_PARAM, char **argv) bb_daemonize_or_rexec(0, argv); /* Here we are grandchild. Sleep, then kill grandparent */ grandchild: - /* Just sleep(HUGE_NUM); kill(parent) may kill wrong process! */ - while (1) { - sleep1(); - if (--timeout <= 0) - break; - if (kill(parent, 0)) { - /* process is gone */ + if (timeout_wait(timeout, parent) == EXIT_SUCCESS) + return EXIT_SUCCESS; + kill(parent, signo); + + if (kill_timeout > 0) { + if (timeout_wait(kill_timeout, parent) == EXIT_SUCCESS) return EXIT_SUCCESS; - } + kill(parent, SIGKILL); } - kill(parent, signo); + return EXIT_SUCCESS; } From bugzilla at busybox.net Sun Dec 19 12:46:31 2021 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Sun, 19 Dec 2021 12:46:31 +0000 Subject: [Bug 14466] New: mount doesn't support -o X-mount.mkdir[=mode] Message-ID: https://bugs.busybox.net/show_bug.cgi?id=14466 Bug ID: 14466 Summary: mount doesn't support -o X-mount.mkdir[=mode] Product: Busybox Version: 1.33.x Hardware: All OS: Linux Status: NEW Severity: normal Priority: P5 Component: Other Assignee: unassigned at busybox.net Reporter: yuanjp89 at 163.com CC: busybox-cvs at busybox.net Target Milestone: --- I build my embeded linux system use busybox and has a /etc/fstab file: none /tmp tmpfs defaults,noatime,nosuid,nodev,mode=1777,size=64M 0 0 none /run tmpfs defaults,noatime,nosuid,nodev,mode=1777,size=4M 0 0 none /proc proc defaults 0 0 udev /dev devtmpfs defaults 0 0 none /dev/pts devpts defaults 0 0 none /sys sysfs defaults 0 0 nodev /sys/kernel/debug debugfs defaults 0 0 but mount /dev/pts will failed, because no directory /dev/pts. When I 'man mount', I found a mount option X-mount.mkdir but it seems not supported by busybox. -- You are receiving this mail because: You are on the CC list for the bug. From vda.linux at googlemail.com Sun Dec 19 22:16:02 2021 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Sun, 19 Dec 2021 23:16:02 +0100 Subject: [git commit] ed: fix current line number for file passed via the command-line Message-ID: <20211219221305.475478183F@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=f26eb796e228cbec754e9e24545f5b0a8a50aac1 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master POSIX.1-2008 mandates the following regarding the file command-line argument: If the file argument is given, ed shall simulate an e command on the file named by the pathname [???] The specification for the e command mandates the following behaviour regarding the current line number in POSIX.1-2008: The current line number shall be set to the address of the last line of the buffer. However, without this commit, busybox ed will set the current line number to 1 if a file is given on the command-line and this file is not empty (lastNum != 0). This is incorrect and fixed in this commit by not modifying the current line number in ed_main(). As such, the current line number will be zero for empty files and otherwise be set to the address of the last line of the buffer. function old new delta ed_main 144 128 -16 Signed-off-by: S??ren Tempel Signed-off-by: Denys Vlasenko --- editors/ed.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/editors/ed.c b/editors/ed.c index 18faba5a4..fed10c470 100644 --- a/editors/ed.c +++ b/editors/ed.c @@ -1016,8 +1016,6 @@ int ed_main(int argc UNUSED_PARAM, char **argv) if (!readLines(fileName, 1)) { return EXIT_SUCCESS; } - if (lastNum) - setCurNum(1); dirty = FALSE; } From vda.linux at googlemail.com Sun Dec 19 22:17:52 2021 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Sun, 19 Dec 2021 23:17:52 +0100 Subject: [git commit] ed: align output of read command with POSIX.1-2008 Message-ID: <20211219221305.50A0181840@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=a05a3d5932b5002d0513adfa817b931dcc1686c0 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master POSIX.1-2008 mandates the following regarding the read command: If the read is successful, and -s was not specified, the number of bytes read shall be written to standard output in the following format: "%d\n", This commit aligns the output of busybox ed with POSIX.1-2008 by removing the file name from the output for the read command. This slipped through in 4836a0708fd0aaeb82871a3762b40fcf4b61e812. function old new delta .rodata 104203 104196 -7 readLines 409 388 -21 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-28) Total: -28 bytes Signed-off-by: S??ren Tempel Signed-off-by: Denys Vlasenko --- editors/ed.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/editors/ed.c b/editors/ed.c index fed10c470..dfe0f1a77 100644 --- a/editors/ed.c +++ b/editors/ed.c @@ -402,9 +402,6 @@ static int readLines(const char *file, int num) charCount = 0; cc = 0; - printf("\"%s\", ", file); - fflush_all(); - do { cp = memchr(bufPtr, '\n', bufUsed); From bugzilla at busybox.net Sat Dec 25 01:03:50 2021 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Sat, 25 Dec 2021 01:03:50 +0000 Subject: [Bug 14241] uudecode doesn't recognise the special decode_pathname /dev/stdout In-Reply-To: References: Message-ID: https://bugs.busybox.net/show_bug.cgi?id=14241 --- Comment #8 from Christoph Anton Mitterer --- I should perhaps add one thing: IMO it's okay to make features configurable, but only if the tool in question fails kinda gracefully if it was disabled. "Gracefully" in the sense, that the failure is not expected by POSIX, but still detectable by checking the exit status So for example: if busybox' tr supports disabling character classes, fine, but only if tr then fails with some non-zero exit status whenever it encounters such character class. The same would go here: If busybox' uuencode was compiled without support for the symbol "/dev/stdout" it should then fail whnever that string is used. Otherwise one cannot reliably use it, when one cannot know how it was compiled. -- You are receiving this mail because: You are on the CC list for the bug. From vda.linux at googlemail.com Sat Dec 25 03:20:28 2021 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Sat, 25 Dec 2021 04:20:28 +0100 Subject: [git commit] sed: do not ignore 'g' modifier when match starts with ^ Message-ID: <20211225031525.3ADBA8269E@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=4fe954c14851d2f913c41c581cbe49300b0984e4 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master It is perfectly valid to start a regex with ^ and have other patterns with \| that can match more than once, e.g. the following example should print ca, as illustrated with gnu sed: $ echo 'abca' | sed -e 's/^a\|b//g' ca busybox before patch: $ echo 'abca' | busybox sed -e 's/^a\|b//g' bca busybox after patch: $ echo 'abca' | ./busybox sed -e 's/^a\|b//g' ca regcomp handles ^ perfectly well as illustrated with the second 'a' that did not match in the example, we ca leave the non-repeating to it if appropriate. The check had been added before using regcomp and was required at the time (f36635cec6da) but no longer makes sense now. (tested with glibc and musl libc) function old new delta add_cmd 1189 1176 -13 Signed-off-by: Dominique Martinet Signed-off-by: Denys Vlasenko --- editors/sed.c | 3 +-- testsuite/sed.tests | 6 ++++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/editors/sed.c b/editors/sed.c index a6845a979..e8c82ac63 100644 --- a/editors/sed.c +++ b/editors/sed.c @@ -435,8 +435,7 @@ static int parse_subst_cmd(sed_cmd_t *sed_cmd, const char *substr) switch (substr[idx]) { /* Replace all occurrences */ case 'g': - if (match[0] != '^') - sed_cmd->which_match = 0; + sed_cmd->which_match = 0; break; /* Print pattern space */ case 'p': diff --git a/testsuite/sed.tests b/testsuite/sed.tests index 67ff87e93..2b78c9b12 100755 --- a/testsuite/sed.tests +++ b/testsuite/sed.tests @@ -399,6 +399,12 @@ testing "sed uses previous regexp" \ "" \ "q\nw\ne\nr\n" +testing "sed ^ OR not^" \ + "sed -e 's/^a\|b//g'" \ + "ca\n" \ + "" \ + "abca\n" + # testing "description" "commands" "result" "infile" "stdin" exit $FAILCOUNT From vda.linux at googlemail.com Sun Dec 26 13:29:37 2021 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Sun, 26 Dec 2021 14:29:37 +0100 Subject: [git commit] httpd: fix compile failure if !FEATURE_HTTPD_RANGES Message-ID: <20211226132444.94A4381D55@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=97c00ae13439ad8114ad7d2150c8dde464f04eb1 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master Signed-off-by: Denys Vlasenko --- networking/httpd.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/networking/httpd.c b/networking/httpd.c index 1ba1d1063..33045163f 100644 --- a/networking/httpd.c +++ b/networking/httpd.c @@ -1880,9 +1880,13 @@ static NOINLINE void send_file_and_exit(const char *url, int what) #if ENABLE_FEATURE_USE_SENDFILE { off_t offset; +# if ENABLE_FEATURE_HTTPD_RANGES if (range_start < 0) range_start = 0; offset = range_start; +# else + offset = 0; +# endif while (1) { /* sz is rounded down to 64k */ ssize_t sz = MAXINT(ssize_t) - 0xffff; From vda.linux at googlemail.com Sun Dec 26 16:55:58 2021 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Sun, 26 Dec 2021 17:55:58 +0100 Subject: [git commit] Bump version to 1.35.0 Message-ID: <20211226173315.5771282B53@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=e512aeb0fb3c585948ae6517cfdf4a53cf99774d branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master Signed-off-by: Denys Vlasenko --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 1216c94a5..edaa3c148 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ VERSION = 1 PATCHLEVEL = 35 SUBLEVEL = 0 -EXTRAVERSION = .git +EXTRAVERSION = NAME = Unnamed # *DOCUMENTATION* From vda.linux at googlemail.com Sun Dec 26 17:34:51 2021 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Sun, 26 Dec 2021 18:34:51 +0100 Subject: [git commit] Announce 1.35.0 Message-ID: <20211226173334.0248382B58@busybox.osuosl.org> commit: https://git.busybox.net/busybox-website/commit/?id=42e3dc46391315084260c112f255ec9d3adce410 branch: https://git.busybox.net/busybox-website/commit/?id=refs/heads/master Signed-off-by: Denys Vlasenko --- news.html | 171 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 171 insertions(+) diff --git a/news.html b/news.html index fc1f8fb..33c628a 100644 --- a/news.html +++ b/news.html @@ -34,6 +34,177 @@

+
  • 26 December 2021 -- BusyBox 1.35.0 (unstable) +

    BusyBox 1.35.0. + (git, + patches, + how to add a patch)

    + +

    Sizes of busybox-1.34.0 and busybox-1.35.0 (with equivalent config, static uclibc build):

    +   text	   data	    bss	    dec	    hex	filename
    +1042344	    908	  14336	1057588	 102334	busybox-1.34.0
    +1044070	    908	  14328	1059306	 1029ea	busybox-1.35.0
    +
    +

    + +

    Changes since previous release: +

    Aaro Koskinen:
    +      find: implement -samefile
    +
    +Alin Mr:
    +      ash.c: speedup ${s:} substring (no quotes)
    +
    +Andrej Valek:
    +      mktemp: add --tmpdir option
    +
    +Ariadne Conill:
    +      cpio: add support for --ignore-devno like GNU cpio
    +      cpio: add support for --renumber-inodes like GNU cpio
    +
    +Bernhard Reutner-Fischer:
    +      chrt: silence analyzer warning
    +      libarchive: remove duplicate forward declaration
    +
    +Daniel Thau:
    +      awk: fix printf %%
    +
    +Denys Vlasenko:
    +      config system: move some options closer to relevalnt tool subdirectories
    +      libbb.h: fix logic selecting incorrect BB_STRTOOFF for !LFS configs
    +      libbb/lineedit: do not escape %^=+}]:, escape ~? in tab completion
    +      libbb: clarify what bb_mode_string() generates
    +      libbb: code shrink bb_parse_mode
    +      libbb: code shrink in des encryption, in setup_salt()
    +      libbb: code shrink in main() and scripted_main()
    +      libbb: eliminate a static data array in bb_mode_string()
    +      libbb: make bb_lookup_port() abort on bad port names
    +      libbb: reuse "bad port" error message string
    +      shell/ash_test/run-all: unset locale/language variables
    +      shell: do not read user database for every prompt - only for those which need it
    +      shell: enable more tests which are passing now
    +      shell: fix arithmentic evaluation of "++7" and such (it is + + 7, i.e. 7)
    +      shell: fix parsing of $(( (v)++ + NUM ))
    +      shell: fix script's comm field if ENABLE_FEATURE_PREFER_APPLETS=y
    +      shell: use more compact SHELL_ASH / HUSH config defines. no code changes
    +      ash: LINENO starts from 0 in -c SCRIPT mode
    +      ash: eval: Check nflag in evaltree instead of cmdloop
    +      ash: eval: Do not cache value of eflag in evaltree
    +      ash: eval: Prevent recursive PS4 expansion
    +      ash: fix LINENO in functions
    +      ash: fix compile breakage in !ENABLE_ASH_ALIAS config
    +      ash: introduce bash-like $FUNCNAME
    +      ash: parser: Fix alias expansion after heredoc or newlines
    +      ash: parser: Fix handling of empty aliases
    +      ash: parser: Get rid of PEOA
    +      ash: parser: Save and restore heredoclist in expandstr
    +      ash: speed up ${x//\*/|} too, make it independent of ASH_OPTIMIZE_FOR_SIZE
    +      ash: support testsuite for !FEATURE_SUID_CONFIG_QUIET configs
    +      ash: use pgetc_eatbnl() in more places, take 3
    +      hush: fix set -n to act immediately, not just after run_list()
    +      hush: fix var_LINENO3.tests failure
    +      hush: speed up ${x//\*/|} too
    +      awk: code shrink: avoid duplicate NUL checks and strlen()
    +      awk: never return NULL from awk_printf()
    +      basename: implement -a and -s SUFFIX
    +      blkdiscard: accept -f (force) as no-op
    +      bzip: make ftab[] and crc32table[] member arrays of EState, do not allocate
    +      chat: hopefully fix infinite spinning on input EOF
    +      chmod: correctly report changed modes
    +      df: "support" -H as an alias of -h
    +      dhcprelay: change two more variables to unsigned
    +      find: code shrink -{m,a,c}{time,min}
    +      httpd: do not send Last-Modified / ETag / Content-Length for error pages
    +      httpd: fix config deps
    +      httpd: if range is not specified, correctly fall back to read/write loop
    +      httpd: fix compile failure if !FEATURE_HTTPD_RANGES
    +      mount: "mount -o rw ...." should not fall back to RO mount
    +      mount: with -w, do not fall back to read-only mounts
    +      ps: fix -o pid=PID,args interpreting entire "PID,args" as header
    +      resize: use tcgetattr(TCSAFLUSH) instead of TCSANOW, closes 13811
    +      shuf: in -i RANGE, accept numbers up to width of pointers
    +      shuf: make -i 99999999990-100000000000 work even on 32 bits
    +      shuf: with -i LOW-HIGH, do not allow any argv's
    +      tar,smemcap: commonalyze checksumming code for tar header
    +      tar: prevent malicious archives with enormous long name sizes OOMing the machine
    +      tls: "server cert is not RSA" is a fatal error
    +      tls: replace "26-bit" P256 code with 32-bit one
    +      tls: x25519: code shrink by factoring out common code
    +      udhcp: fix build breakage on MIPS
    +      udhcpc6: fix udhcp_find_option to actually find DHCP6 options
    +      udhcpd: check config file for bad IP ranges (start > end)
    +      uudecode: special-case "/dev/stdout", closes 14241
    +      xxd: fix -p -r, closes 13881
    +
    +Dominique Martinet:
    +      sed: do not ignore 'g' modifier when match starts with ^
    +
    +Ildar Shaimordanov:
    +      wget: allow end-users to customize Content-Type for --post-data and --post-file
    +
    +Ismael Luceno:
    +      less: Ignore -X
    +      config: find: Fix mtime/mmin description
    +      find: Unify time comparisons
    +      find: implement -amin, -atime, -cmin, and -ctime
    +
    +Martin Kaiser:
    +      Makefile.flags: use all cflags for crypt and rt checks
    +
    +Matthew Slowe:
    +      timeout: add support for "timeout -k KILL_SECS"
    +
    +Nicholas Niro:
    +      ip: added support for setting netns on devices
    +
    +Peter Korsgaard:
    +      libarchive/get_header_ar.c: fix extraction of archives from binutils in deterministic mode
    +
    +Roberto A. Foglietta:
    +      ash: add bash-like ERR trap and set -E
    +
    +Ron Yorston:
    +      libbb: better coreutils compatibility for realpath
    +      libbb: code shrink parse_datestr
    +      libbb: ensure mode_string is NUL terminated
    +      ash: fix ignoreeof option
    +      ash: let ignoreeof only affect interactive shells
    +      ash: regressions in process substitution
    +      ash: stopped jobs should only prevent exit from interactive shell
    +      awk: fix read beyond end of buffer
    +      cal: implement -m
    +      date,touch: allow timezone offsets in dates
    +      getopt: code shrink
    +      printf: allow 0 as a flag and allow multiple flags
    +      rev: correct output for long input lines
    +      shuf: speed-up when limited output is requested
    +      tar,smemcap: silence compiler warning
    +      vi: changes to handling of -c and EXINIT
    +      vi: code shrink print_literal()
    +      vi: don't right shift empty lines
    +      vi: further changes to colon addresses
    +      vi: searches in colon commands should wrap
    +      vi: support ~/.exrc
    +      wget: implement --post-file
    +
    +Sergey Ponomarev:
    +      httpd,telnetd: make default port configurable
    +
    +S??ren Tempel:
    +      ed: align output of read/write commands with POSIX-1.2008
    +      ed: add support for -p command-line option as mandated by POSIX
    +      ed: fix current line number for file passed via the command-line
    +      ed: align output of read command with POSIX.1-2008
    +
    +Walter Lozano:
    +      cmp: add support for -n
    +
    +YU Jincheng:
    +      *: generalize "const trick"
    +      Make const ptr assign as function call in clang
    +
    +

    +
  • +
  • 30 November 2021 -- BusyBox 1.33.2 (stable)

    BusyBox 1.33.2. (git)

    From vda at busybox.net Sun Dec 26 16:55:58 2021 From: vda at busybox.net (Denys Vlasenko) Date: Sun, 26 Dec 2021 17:55:58 +0100 Subject: [tag/1_35_0] new tag created Message-ID: <20211226173352.0513182B5D@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=e512aeb0fb3c585948ae6517cfdf4a53cf99774d tag: https://git.busybox.net/busybox/commit/?id=refs/tags/1_35_0 Bump version to 1.35.0 From vda at busybox.net Sun Dec 26 16:55:58 2021 From: vda at busybox.net (Denys Vlasenko) Date: Sun, 26 Dec 2021 17:55:58 +0100 Subject: [branch/1_35_stable] new branch created Message-ID: <20211226173415.3CEF782B5E@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=e512aeb0fb3c585948ae6517cfdf4a53cf99774d branch: https://git.busybox.net/busybox/commit/?id=refs/heads/1_35_stable From vda.linux at googlemail.com Sun Dec 26 17:40:55 2021 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Sun, 26 Dec 2021 18:40:55 +0100 Subject: [git commit] Start 1.36.0 development cycle Message-ID: <20211226173527.BC3FB82B5E@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=44075929a8b9c1861d15564fa6ac4562abb724d7 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master Signed-off-by: Denys Vlasenko --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index edaa3c148..b2ce46c7c 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ VERSION = 1 -PATCHLEVEL = 35 +PATCHLEVEL = 36 SUBLEVEL = 0 -EXTRAVERSION = +EXTRAVERSION = .git NAME = Unnamed # *DOCUMENTATION* From vda.linux at googlemail.com Tue Dec 28 08:05:12 2021 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Tue, 28 Dec 2021 09:05:12 +0100 Subject: [git commit] libbb: cose shrink in sha1 Message-ID: <20211228075950.7AC9682A06@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=f1d06462e872270f38c497e36f8cd018ee7415bf branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta sha1_process_block64 356 342 -14 Signed-off-by: Denys Vlasenko --- libbb/hash_md5_sha.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/libbb/hash_md5_sha.c b/libbb/hash_md5_sha.c index e0db8ce67..a468397e3 100644 --- a/libbb/hash_md5_sha.c +++ b/libbb/hash_md5_sha.c @@ -523,9 +523,6 @@ static void FAST_FUNC sha1_process_block64(sha1_ctx_t *ctx) work = (work & b) ^ d; if (j <= 3) goto ge16; - /* Used to do SWAP_BE32 here, but this - * requires ctx (see comment above) */ - work += W[cnt]; } else { if (i == 2) work = ((b | c) & d) | (b & c); @@ -533,14 +530,14 @@ static void FAST_FUNC sha1_process_block64(sha1_ctx_t *ctx) work ^= b; ge16: W[cnt] = W[cnt+16] = rotl32(W[cnt+13] ^ W[cnt+8] ^ W[cnt+2] ^ W[cnt], 1); - work += W[cnt]; } + work += W[cnt]; work += e + rotl32(a, 5) + rconsts[i]; /* Rotate by one for next time */ e = d; d = c; - c = /* b = */ rotl32(b, 30); + c = rotl32(b, 30); b = a; a = work; cnt = (cnt + 1) & 15; From vda.linux at googlemail.com Tue Dec 28 20:05:59 2021 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Tue, 28 Dec 2021 21:05:59 +0100 Subject: [git commit] scripts/echo.c: fix NUL handling in "abc\0 def" Message-ID: <20211228200151.A4EFA82BA1@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=0fcc7f5f738e38766cde59ffd193643458c26cba branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master Signed-off-by: Denys Vlasenko --- scripts/echo.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/scripts/echo.c b/scripts/echo.c index 7474ccdd4..e3a07adf0 100644 --- a/scripts/echo.c +++ b/scripts/echo.c @@ -153,25 +153,32 @@ int main(int argc, char **argv) if (!eflag) { /* optimization for very common case */ fputs(arg, stdout); - } else while ((c = *arg++)) { - if (c == eflag) { /* Check for escape seq. */ + } else + while ((c = *arg++) != '\0') { + if (c == eflag) { + /* This is an "\x" sequence */ + if (*arg == 'c') { - /* '\c' means cancel newline and + /* "\c" means cancel newline and * ignore all subsequent chars. */ goto ret; } - { - /* Since SUSv3 mandates a first digit of 0, 4-digit octals - * of the form \0### are accepted. */ - if (*arg == '0') { - /* NB: don't turn "...\0" into "...\" */ - if (arg[1] && ((unsigned char)(arg[1]) - '0') < 8) { - arg++; - } + /* Since SUSv3 mandates a first digit of 0, 4-digit octals + * of the form \0### are accepted. */ + if (*arg == '0') { + if ((unsigned char)(arg[1] - '0') < 8) { + /* 2nd char is 0..7: skip leading '0' */ + arg++; } - /* bb_process_escape_sequence handles NUL correctly - * ("...\" case. */ - c = bb_process_escape_sequence(&arg); + } + /* bb_process_escape_sequence handles NUL correctly + * ("...\" case). */ + { + /* optimization: don't force arg to be on-stack, + * use another variable for that. ~30 bytes win */ + const char *z = arg; + c = bb_process_escape_sequence(&z); + arg = z; } } putchar(c); From vda.linux at googlemail.com Wed Dec 29 06:26:23 2021 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Wed, 29 Dec 2021 07:26:23 +0100 Subject: [git commit] echo: add FIXME comment Message-ID: <20211229062112.41273826D2@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=0e2cb6d1e2553675bba2999829bbc29219aea987 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master Signed-off-by: Denys Vlasenko --- coreutils/echo.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/coreutils/echo.c b/coreutils/echo.c index 82f0358b6..44b2eb5d0 100644 --- a/coreutils/echo.c +++ b/coreutils/echo.c @@ -321,6 +321,8 @@ int echo_main(int argc, char **argv) if (*arg == '0' && (unsigned char)(arg[1] - '0') < 8) { arg++; } +//FIXME? we also accept non-0 starting sequences (see echo-prints-slash_41 test) +// echo -ne '-\41-' prints "-!-". bash 5.0.17 does not (prints "-\41-"). /* bb_process_escape_sequence can handle nul correctly */ c = bb_process_escape_sequence( (void*) &arg); } From bugzilla at busybox.net Wed Dec 29 17:47:48 2021 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Wed, 29 Dec 2021 17:47:48 +0000 Subject: [Bug 14391] sha1sum slow on x64 and possibly others In-Reply-To: References: Message-ID: https://bugs.busybox.net/show_bug.cgi?id=14391 --- Comment #1 from Denys Vlasenko --- Unrolling outer loop only does not help noticeably. Full unrolling of all 80 iterations increases size by ~3600 bytes. If you want, you can submit a patch where unrolling is done depending on .config option, following this example in libbb/Config.src: config MD5_SMALL int "MD5: Trade bytes for speed (0:fast, 3:slow)" default 1 # all "fast or small" options default to small range 0 3 help Trade binary size versus speed for the md5sum algorithm. Approximate values running uClibc and hashing linux-2.4.4.tar.bz2 were: value user times (sec) text size (386) 0 (fastest) 1.1 6144 1 1.4 5392 2 3.0 5088 3 (smallest) 5.1 4912 -- You are receiving this mail because: You are on the CC list for the bug. From vda.linux at googlemail.com Wed Dec 29 18:01:32 2021 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Wed, 29 Dec 2021 19:01:32 +0100 Subject: [git commit] ed: add support for -s command-line option as mandated by POSIX Message-ID: <20211229175547.7690A82AB7@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=9173c9cce48dc4c867fb06bb72e8c762740c5c86 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master Apart from the -p option, POSIX also mandates an -s option which suppresses the output of byte counts for the e, E, r, and w command. >From these commands, Busybox ed presently only implements the r and w commands. This commit ensures that these two command do not output any bytes counts when the -s option is passed. The shell escape command, also effected by the -s option, is not implemented by Busybox at the moment. function old new delta packed_usage 34096 34115 +19 doCommands 1887 1900 +13 readLines 388 397 +9 .rodata 104196 104200 +4 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 4/0 up/down: 45/0) Total: 45 bytes Signed-off-by: S??ren Tempel Signed-off-by: Denys Vlasenko --- editors/ed.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/editors/ed.c b/editors/ed.c index dfe0f1a77..209ce9942 100644 --- a/editors/ed.c +++ b/editors/ed.c @@ -18,7 +18,7 @@ //applet:IF_ED(APPLET(ed, BB_DIR_BIN, BB_SUID_DROP)) -//usage:#define ed_trivial_usage "[-p PROMPT] [FILE]" +//usage:#define ed_trivial_usage "[-p PROMPT] [-s] [FILE]" //usage:#define ed_full_usage "" #include "libbb.h" @@ -71,6 +71,11 @@ struct globals { SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ } while (0) +#define OPTION_STR "sp:" +enum { + OPT_s = (1 << 0), +}; + static int bad_nums(int num1, int num2, const char *for_what) { if ((num1 < 1) || (num2 > lastNum) || (num1 > num2)) { @@ -458,7 +463,8 @@ static int readLines(const char *file, int num) * in the following format: * "%d\n", */ - printf("%u\n", charCount); + if (!(option_mask32 & OPT_s)) + printf("%u\n", charCount); return TRUE; } @@ -510,7 +516,8 @@ static int writeLines(const char *file, int num1, int num2) * unless the -s option was specified, in the following format: * "%d\n", */ - printf("%u\n", charCount); + if (!(option_mask32 & OPT_s)) + printf("%u\n", charCount); return TRUE; } @@ -1005,7 +1012,7 @@ int ed_main(int argc UNUSED_PARAM, char **argv) lines.prev = &lines; prompt = ""; /* no prompt by default */ - getopt32(argv, "p:", &prompt); + getopt32(argv, OPTION_STR, &prompt); argv += optind; if (argv[0]) { From bugzilla at busybox.net Wed Dec 29 21:23:29 2021 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Wed, 29 Dec 2021 21:23:29 +0000 Subject: [Bug 14391] sha1sum slow on x64 and possibly others In-Reply-To: References: Message-ID: https://bugs.busybox.net/show_bug.cgi?id=14391 --- Comment #2 from B?a?ej Roszkowski --- I'm not sure which is 'outer' loop. In busybox code the outermost loop is for (i = 0; i < 4; i++). In my opinion unrolling it is also worth it (but unrolling full 80 stages is more drastic performance and size jump). I unrolled it in busybox messily (there still is one if with goto in stage 1) by copy pasting entire body of the loop 4 times and deleting parts not relevant to given i value for that copy. Time for 1 GB went from 5.3 to 4.7 (I'm eyeballing but it's 100% noticeable even with random fluctuations of 0.1-0.3 between runs) sha1_process_block64 size went from 361 to 672. Executable size stayed at 976568. I'm guessing it's because code is denser when generated per stage (constant inlined, no ifs and jumps). Here's a commit I also made to test rolling my 80 steps back into 4 for loops of 20: https://github.com/FRex/blasha1/commit/c5a3e5d5d6d0e85f73934e2446fa56fcbc95adeb 1 GB file on Fedora VM takes (in order: my code, my rolled code, busybox, busybox unrolled 4 for loops): 2.4, 4, 5.3, 4.7 On Windows (I didn't test unrolled 4 for loop busybox): 2.4, 3.6, 5.5 -- You are receiving this mail because: You are on the CC list for the bug. From vda.linux at googlemail.com Thu Dec 30 12:17:16 2021 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Thu, 30 Dec 2021 13:17:16 +0100 Subject: [git commit] libbb/sha1: add config-selectable fully unrolled version, closes 14391 Message-ID: <20211230121231.EF9B482DA1@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=25aadc893d21b35f7d34a9d1edc843632e7abd8f branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta sha1_process_block64 364 4167 +3803 static.rconsts 16 - -16 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 1/0 up/down: 3803/-16) Total: 3787 bytes Signed-off-by: Denys Vlasenko --- libbb/Config.src | 25 +++++++++++----- libbb/hash_md5_sha.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 95 insertions(+), 14 deletions(-) diff --git a/libbb/Config.src b/libbb/Config.src index 24b31fad9..13188ef03 100644 --- a/libbb/Config.src +++ b/libbb/Config.src @@ -42,21 +42,32 @@ config MD5_SMALL default 1 # all "fast or small" options default to small range 0 3 help - Trade binary size versus speed for the md5sum algorithm. + Trade binary size versus speed for the md5 algorithm. Approximate values running uClibc and hashing linux-2.4.4.tar.bz2 were: - value user times (sec) text size (386) - 0 (fastest) 1.1 6144 - 1 1.4 5392 - 2 3.0 5088 - 3 (smallest) 5.1 4912 + value user times (sec) text size (386) + 0 (fastest) 1.1 6144 + 1 1.4 5392 + 2 3.0 5088 + 3 (smallest) 5.1 4912 + +config SHA1_SMALL + int "SHA1: Trade bytes for speed (0:fast, 3:slow)" + default 3 # all "fast or small" options default to small + range 0 3 + help + Trade binary size versus speed for the sha1 algorithm. + throughput MB/s size of sha1_process_block64 + value 486 x86-64 486 x86-64 + 0 339 374 4149 4167 + 1,2,3 200 195 358 380 config SHA3_SMALL int "SHA3: Trade bytes for speed (0:fast, 1:slow)" default 1 # all "fast or small" options default to small range 0 1 help - Trade binary size versus speed for the sha3sum algorithm. + Trade binary size versus speed for the sha3 algorithm. SHA3_SMALL=0 compared to SHA3_SMALL=1 (approximate): 64-bit x86: +270 bytes of code, 45% faster 32-bit x86: +450 bytes of code, 75% faster diff --git a/libbb/hash_md5_sha.c b/libbb/hash_md5_sha.c index a468397e3..75673e334 100644 --- a/libbb/hash_md5_sha.c +++ b/libbb/hash_md5_sha.c @@ -390,7 +390,6 @@ static void FAST_FUNC md5_process_block64(md5_ctx_t *ctx) OP(FI, D, A, B, C, 11, 10, 0xbd3af235); OP(FI, C, D, A, B, 2, 15, 0x2ad7d2bb); OP(FI, B, C, D, A, 9, 21, 0xeb86d391); -# undef OP # endif /* Add checksum to the starting values */ ctx->hash[0] += A; @@ -399,6 +398,7 @@ static void FAST_FUNC md5_process_block64(md5_ctx_t *ctx) ctx->hash[3] += D; #endif } +#undef OP #undef FF #undef FG #undef FH @@ -490,18 +490,87 @@ unsigned FAST_FUNC md5_end(md5_ctx_t *ctx, void *resbuf) * then rebuild and compare "shaNNNsum bigfile" results. */ +#if CONFIG_SHA1_SMALL == 0 +/* Fast, fully-unrolled SHA1. +3800 bytes of code on x86. + * It seems further speedup can be achieved by handling more than + * 64 bytes per one function call (coreutils does that). + */ +static void FAST_FUNC sha1_process_block64(sha1_ctx_t *ctx) +{ + static const uint32_t rconsts[] ALIGN4 = { + 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xCA62C1D6 + }; + uint32_t W[16]; + uint32_t a, b, c, d, e; + + a = ctx->hash[0]; + b = ctx->hash[1]; + c = ctx->hash[2]; + d = ctx->hash[3]; + e = ctx->hash[4]; + +#undef OP +#define OP(A,B,C,D,E, n) \ + do { \ + uint32_t work = EXPR(B, C, D); \ + if (n <= 15) \ + work += W[n & 0xf] = SWAP_BE32(((uint32_t*)ctx->wbuffer)[n]); \ + if (n >= 16) \ + work += W[n & 0xf] = rotl32(W[(n+13) & 0xf] ^ W[(n+8) & 0xf] ^ W[(n+2) & 0xf] ^ W[n & 0xf], 1); \ + E += work + rotl32(A, 5) + rconsts[n / 20]; \ + B = rotl32(B, 30); \ + } while (0) +#define OP20(n) \ + OP(a,b,c,d,e, (n+ 0)); OP(e,a,b,c,d, (n+ 1)); OP(d,e,a,b,c, (n+ 2)); OP(c,d,e,a,b, (n+ 3)); OP(b,c,d,e,a, (n+ 4)); \ + OP(a,b,c,d,e, (n+ 5)); OP(e,a,b,c,d, (n+ 6)); OP(d,e,a,b,c, (n+ 7)); OP(c,d,e,a,b, (n+ 8)); OP(b,c,d,e,a, (n+ 9)); \ + OP(a,b,c,d,e, (n+10)); OP(e,a,b,c,d, (n+11)); OP(d,e,a,b,c, (n+12)); OP(c,d,e,a,b, (n+13)); OP(b,c,d,e,a, (n+14)); \ + OP(a,b,c,d,e, (n+15)); OP(e,a,b,c,d, (n+16)); OP(d,e,a,b,c, (n+17)); OP(c,d,e,a,b, (n+18)); OP(b,c,d,e,a, (n+19)) + + /* 4 rounds of 20 operations each */ +#define EXPR(b,c,d) (((c ^ d) & b) ^ d) + OP20(0); +#undef EXPR +#define EXPR(b,c,d) (c ^ d ^ b) + OP20(20); +#undef EXPR +#define EXPR(b,c,d) (((b | c) & d) | (b & c)) + OP20(40); +#undef EXPR +#define EXPR(b,c,d) (c ^ d ^ b) + OP20(60); + +#undef EXPR +#undef OP +#undef OP20 + + ctx->hash[0] += a; + ctx->hash[1] += b; + ctx->hash[2] += c; + ctx->hash[3] += d; + ctx->hash[4] += e; +} +#else +/* TODO: for CONFIG_SHA1_SMALL == 1, have a partially unrolled version? */ + +/* Compact version, almost twice as slow as fully unrolled */ static void FAST_FUNC sha1_process_block64(sha1_ctx_t *ctx) { static const uint32_t rconsts[] ALIGN4 = { 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xCA62C1D6 }; int i, j; - int cnt; + int n; uint32_t W[16+16]; uint32_t a, b, c, d, e; /* On-stack work buffer frees up one register in the main loop - * which otherwise will be needed to hold ctx pointer */ + * which otherwise will be needed to hold ctx pointer. + * + * The compiler is not smart enough to realize it, though. :( + * If __attribute__((optimize("2"))) is added to the function, + * only then gcc-9.3.1 spills "ctx" to stack and uses the freed + * register (making code 6 bytes smaller, not just faster). + */ for (i = 0; i < 16; i++) W[i] = W[i+16] = SWAP_BE32(((uint32_t*)ctx->wbuffer)[i]); @@ -512,7 +581,7 @@ static void FAST_FUNC sha1_process_block64(sha1_ctx_t *ctx) e = ctx->hash[4]; /* 4 rounds of 20 operations each */ - cnt = 0; + n = 0; for (i = 0; i < 4; i++) { j = 19; do { @@ -529,9 +598,9 @@ static void FAST_FUNC sha1_process_block64(sha1_ctx_t *ctx) else /* i = 1 or 3 */ work ^= b; ge16: - W[cnt] = W[cnt+16] = rotl32(W[cnt+13] ^ W[cnt+8] ^ W[cnt+2] ^ W[cnt], 1); + W[n] = W[n+16] = rotl32(W[n+13] ^ W[n+8] ^ W[n+2] ^ W[n], 1); } - work += W[cnt]; + work += W[n]; work += e + rotl32(a, 5) + rconsts[i]; /* Rotate by one for next time */ @@ -540,7 +609,7 @@ static void FAST_FUNC sha1_process_block64(sha1_ctx_t *ctx) c = rotl32(b, 30); b = a; a = work; - cnt = (cnt + 1) & 15; + n = (n + 1) & 15; } while (--j >= 0); } @@ -550,6 +619,7 @@ static void FAST_FUNC sha1_process_block64(sha1_ctx_t *ctx) ctx->hash[3] += d; ctx->hash[4] += e; } +#endif /* Constants for SHA512 from FIPS 180-2:4.2.3. * SHA256 constants from FIPS 180-2:4.2.2 From bugzilla at busybox.net Thu Dec 30 12:18:39 2021 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Thu, 30 Dec 2021 12:18:39 +0000 Subject: [Bug 14391] sha1sum slow on x64 and possibly others In-Reply-To: References: Message-ID: https://bugs.busybox.net/show_bug.cgi?id=14391 Denys Vlasenko changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution|--- |FIXED --- Comment #3 from Denys Vlasenko --- Fixed in git, please test. -- You are receiving this mail because: You are on the CC list for the bug. From bugzilla at busybox.net Thu Dec 30 15:52:18 2021 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Thu, 30 Dec 2021 15:52:18 +0000 Subject: [Bug 14481] New: mdev -s doesn't coldplug devices Message-ID: https://bugs.busybox.net/show_bug.cgi?id=14481 Bug ID: 14481 Summary: mdev -s doesn't coldplug devices Product: Busybox Version: unspecified Hardware: All OS: Linux Status: NEW Severity: normal Priority: P5 Component: Other Assignee: unassigned at busybox.net Reporter: axel at axelfontaine.com CC: busybox-cvs at busybox.net Target Milestone: --- Linux Kernel 5.15.11 (mainline) Busybox 1.34.1 x64 static build When executing mdev -s within the init of an initramfs devices aren't picked up and modules aren't being loaded. Instead one must execute find /sys/ -name modalias | xargs sort -u | xargs -n 1 modprobe to ensure all hardware is found and the relevant modules are loaded. How to reproduce: 1. create a minimal x64 QEMU machine 2. Launch a VM with a minimal Busybox-based initramfs where /init is a reqular shell script 3. Mount /proc and /sys then execute mdev -s as part of this script -- You are receiving this mail because: You are on the CC list for the bug. From bugzilla at busybox.net Thu Dec 30 16:59:26 2021 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Thu, 30 Dec 2021 16:59:26 +0000 Subject: [Bug 14241] uudecode doesn't recognise the special decode_pathname /dev/stdout In-Reply-To: References: Message-ID: https://bugs.busybox.net/show_bug.cgi?id=14241 Denys Vlasenko changed: What |Removed |Added ---------------------------------------------------------------------------- Resolution|--- |FIXED Status|REOPENED |RESOLVED --- Comment #9 from Denys Vlasenko --- > cause it seems ENABLE_DESKTOP is not enabled per default ENABLE_DESKTOP is enabled per default. I think this bug is closed. -- You are receiving this mail because: You are on the CC list for the bug. From vda.linux at googlemail.com Thu Dec 30 17:54:02 2021 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Thu, 30 Dec 2021 18:54:02 +0100 Subject: [git commit] libbb/sha1: add config-selectable partially unrolled version Message-ID: <20211230174832.D0E1B82B5A@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=0b62a08777e29c34f947c791a1eded5b97e05699 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta sha1_process_block64 364 732 +368 static.rconsts 16 - -16 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 1/0 up/down: 368/-16) Total: 352 bytes Signed-off-by: Denys Vlasenko --- libbb/Config.src | 3 +- libbb/hash_md5_sha.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 98 insertions(+), 5 deletions(-) diff --git a/libbb/Config.src b/libbb/Config.src index 13188ef03..c793f5939 100644 --- a/libbb/Config.src +++ b/libbb/Config.src @@ -60,7 +60,8 @@ config SHA1_SMALL throughput MB/s size of sha1_process_block64 value 486 x86-64 486 x86-64 0 339 374 4149 4167 - 1,2,3 200 195 358 380 + 1 224 229 654 732 + 2,3 200 195 358 380 config SHA3_SMALL int "SHA3: Trade bytes for speed (0:fast, 1:slow)" diff --git a/libbb/hash_md5_sha.c b/libbb/hash_md5_sha.c index 75673e334..053ebe291 100644 --- a/libbb/hash_md5_sha.c +++ b/libbb/hash_md5_sha.c @@ -514,9 +514,9 @@ static void FAST_FUNC sha1_process_block64(sha1_ctx_t *ctx) do { \ uint32_t work = EXPR(B, C, D); \ if (n <= 15) \ - work += W[n & 0xf] = SWAP_BE32(((uint32_t*)ctx->wbuffer)[n]); \ + work += W[n & 15] = SWAP_BE32(((uint32_t*)ctx->wbuffer)[n]); \ if (n >= 16) \ - work += W[n & 0xf] = rotl32(W[(n+13) & 0xf] ^ W[(n+8) & 0xf] ^ W[(n+2) & 0xf] ^ W[n & 0xf], 1); \ + work += W[n & 15] = rotl32(W[(n+13) & 15] ^ W[(n+8) & 15] ^ W[(n+2) & 15] ^ W[n & 15], 1); \ E += work + rotl32(A, 5) + rconsts[n / 20]; \ B = rotl32(B, 30); \ } while (0) @@ -549,9 +549,101 @@ static void FAST_FUNC sha1_process_block64(sha1_ctx_t *ctx) ctx->hash[3] += d; ctx->hash[4] += e; } -#else -/* TODO: for CONFIG_SHA1_SMALL == 1, have a partially unrolled version? */ +#elif CONFIG_SHA1_SMALL == 1 +/* Middle-sized version, +300 bytes of code on x86. */ +static void FAST_FUNC sha1_process_block64(sha1_ctx_t *ctx) +{ + static const uint32_t rconsts[] ALIGN4 = { + 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xCA62C1D6 + }; + int j; + int n; + uint32_t W[16+16]; + uint32_t a, b, c, d, e; + + a = ctx->hash[0]; + b = ctx->hash[1]; + c = ctx->hash[2]; + d = ctx->hash[3]; + e = ctx->hash[4]; + + /* 1st round of 20 operations */ + n = 0; + do { + uint32_t work = ((c ^ d) & b) ^ d; + W[n] = W[n+16] = SWAP_BE32(((uint32_t*)ctx->wbuffer)[n]); + work += W[n]; + work += e + rotl32(a, 5) + rconsts[0]; + /* Rotate by one for next time */ + e = d; + d = c; + c = rotl32(b, 30); + b = a; + a = work; + n = (n + 1) & 15; + } while (n != 0); + do { + uint32_t work = ((c ^ d) & b) ^ d; + W[n] = W[n+16] = rotl32(W[n+13] ^ W[n+8] ^ W[n+2] ^ W[n], 1); + work += W[n]; + work += e + rotl32(a, 5) + rconsts[0]; + e = d; + d = c; + c = rotl32(b, 30); + b = a; + a = work; + n = (n + 1) & 15; + } while (n != 4); + /* 2nd round of 20 operations */ + j = 19; + do { + uint32_t work = c ^ d ^ b; + W[n] = W[n+16] = rotl32(W[n+13] ^ W[n+8] ^ W[n+2] ^ W[n], 1); + work += W[n]; + work += e + rotl32(a, 5) + rconsts[1]; + e = d; + d = c; + c = rotl32(b, 30); + b = a; + a = work; + n = (n + 1) & 15; + } while (--j >= 0); + /* 3rd round */ + j = 19; + do { + uint32_t work = ((b | c) & d) | (b & c); + W[n] = W[n+16] = rotl32(W[n+13] ^ W[n+8] ^ W[n+2] ^ W[n], 1); + work += W[n]; + work += e + rotl32(a, 5) + rconsts[2]; + e = d; + d = c; + c = rotl32(b, 30); + b = a; + a = work; + n = (n + 1) & 15; + } while (--j >= 0); + /* 4th round */ + j = 19; + do { + uint32_t work = c ^ d ^ b; + W[n] = W[n+16] = rotl32(W[n+13] ^ W[n+8] ^ W[n+2] ^ W[n], 1); + work += W[n]; + work += e + rotl32(a, 5) + rconsts[3]; + e = d; + d = c; + c = rotl32(b, 30); + b = a; + a = work; + n = (n + 1) & 15; + } while (--j >= 0); + ctx->hash[0] += a; + ctx->hash[1] += b; + ctx->hash[2] += c; + ctx->hash[3] += d; + ctx->hash[4] += e; +} +#else /* Compact version, almost twice as slow as fully unrolled */ static void FAST_FUNC sha1_process_block64(sha1_ctx_t *ctx) { From bugzilla at busybox.net Thu Dec 30 21:36:24 2021 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Thu, 30 Dec 2021 21:36:24 +0000 Subject: [Bug 14391] sha1sum slow on x64 and possibly others In-Reply-To: References: Message-ID: https://bugs.busybox.net/show_bug.cgi?id=14391 --- Comment #4 from B?a?ej Roszkowski --- Yes, CONFIG_SHA1_SMALL 0 and 1 improve performance as expected. Thank you. -- You are receiving this mail because: You are on the CC list for the bug. From vda.linux at googlemail.com Fri Dec 31 16:07:47 2021 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Fri, 31 Dec 2021 17:07:47 +0100 Subject: [git commit] libbb/sha1: shrink and speed up fully unrolled version Message-ID: <20211231160514.3BE9F82C6C@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=f09d088fdf6eeeba902fb5627930145a3058a5f0 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta sha1_process_block64 4149 3950 -199 Signed-off-by: Denys Vlasenko --- libbb/Config.src | 2 +- libbb/hash_md5_sha.c | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/libbb/Config.src b/libbb/Config.src index c793f5939..d2054dc63 100644 --- a/libbb/Config.src +++ b/libbb/Config.src @@ -59,7 +59,7 @@ config SHA1_SMALL Trade binary size versus speed for the sha1 algorithm. throughput MB/s size of sha1_process_block64 value 486 x86-64 486 x86-64 - 0 339 374 4149 4167 + 0 360 374 3950 4167 1 224 229 654 732 2,3 200 195 358 380 diff --git a/libbb/hash_md5_sha.c b/libbb/hash_md5_sha.c index 053ebe291..faf485df5 100644 --- a/libbb/hash_md5_sha.c +++ b/libbb/hash_md5_sha.c @@ -509,6 +509,27 @@ static void FAST_FUNC sha1_process_block64(sha1_ctx_t *ctx) d = ctx->hash[3]; e = ctx->hash[4]; +/* From kernel source comments: + * """ + * If you have 32 registers or more, the compiler can (and should) + * try to change the array[] accesses into registers. However, on + * machines with less than ~25 registers, that won't really work, + * and at least gcc will make an unholy mess of it. + * + * So to avoid that mess which just slows things down, we force + * the stores to memory to actually happen (we might be better off + * with a 'W(t)=(val);asm("":"+m" (W(t))' there instead, as + * suggested by Artur Skawina - that will also make gcc unable to + * try to do the silly "optimize away loads" part because it won't + * see what the value will be). + * """ + */ +#if defined(__i386__) +# define DO_NOT_TRY_PROPAGATING(m) asm("":"+m"(m)) +#else +# define DO_NOT_TRY_PROPAGATING(m) ((void)0) +#endif + #undef OP #define OP(A,B,C,D,E, n) \ do { \ @@ -517,6 +538,7 @@ static void FAST_FUNC sha1_process_block64(sha1_ctx_t *ctx) work += W[n & 15] = SWAP_BE32(((uint32_t*)ctx->wbuffer)[n]); \ if (n >= 16) \ work += W[n & 15] = rotl32(W[(n+13) & 15] ^ W[(n+8) & 15] ^ W[(n+2) & 15] ^ W[n & 15], 1); \ + DO_NOT_TRY_PROPAGATING(W[n & 15]); \ E += work + rotl32(A, 5) + rconsts[n / 20]; \ B = rotl32(B, 30); \ } while (0)