From lists at kaiser.cx Mon Nov 8 16:36:43 2021 From: lists at kaiser.cx (Martin Kaiser) Date: Mon, 8 Nov 2021 17:36:43 +0100 Subject: [PATCH] Makefile.flags: use all cflags for crypt and rt checks Message-ID: <20211108163642.10645-1-lists@kaiser.cx> From: Martin Kaiser 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 --- 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 -- 2.20.1 From nekokun at firemail.cc Tue Nov 9 06:42:39 2021 From: nekokun at firemail.cc (Nekun) Date: Tue, 09 Nov 2021 06:42:39 +0000 Subject: Broken init documentation on website Message-ID: <0b5fd8ea97c10eaae7fcb81d0a553380@firemail.cc> Hi all, Online documentation contains just a single line for init: "Init is the parent of all processes" https://busybox.net/downloads/BusyBox.html From vda.linux at googlemail.com Tue Nov 9 14:00:55 2021 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Tue, 9 Nov 2021 15:00:55 +0100 Subject: [PATCH] ls: recognize "never" for LS_COLORS In-Reply-To: References: Message-ID: On Thu, Oct 21, 2021 at 1:40 PM roger peppe wrote: > This patch was made to commit 836b79211df3aeaba1b8b65c6db5ee6193172cc0. > > The standard `ls` command uses the value "never" (not "none") to signify that the output should not be colorized. This change lets the same value apply consistently to `busybox ls` too. Er... no it does not? I ran a few experiments and it seems there is no value of LS_COLORS environment variable which simply switches off coloring. Well, "none" and "never" do switch it off, but only because any invalid value does it: $ LS_COLORS=none ls -l --color ls: unparsable value for LS_COLORS environment variable $ LS_COLORS=never ls -l --color ls: unparsable value for LS_COLORS environment variable Even "always" does it too: $ LS_COLORS=always ls -l --color ls: unparsable value for LS_COLORS environment variable Empty value is not switching coloring off. So, our behavior is not matching coreutils (we accept LS_COLORS=none), and your patch does not improve that. From vda.linux at googlemail.com Tue Nov 9 15:01:07 2021 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Tue, 9 Nov 2021 16:01:07 +0100 Subject: which -a In-Reply-To: <20211026125259.1edc84c5@devuan> References: <20211026125259.1edc84c5@devuan> Message-ID: Fixed in git. On Tue, Oct 26, 2021 at 12:53 PM tito wrote: > > Hi, > today I noticed that the which command doesn't > show the -a command line option in its usage. > > Ciao, > Tito > _______________________________________________ > busybox mailing list > busybox at busybox.net > http://lists.busybox.net/mailman/listinfo/busybox From ncopa at alpinelinux.org Thu Nov 11 10:44:15 2021 From: ncopa at alpinelinux.org (Natanael Copa) Date: Thu, 11 Nov 2021 11:44:15 +0100 Subject: Backporting security fixes for 1_31_stable, 1_32_stable and 1_33_stable Message-ID: <20211111114415.4e5b2394@ncopa-desktop.lan> Hi! There are a number of security issues published that affects busybox older than 1.34. https://jfrog.com/blog/unboxing-busybox-14-new-vulnerabilities-uncovered-by-claroty-and-jfrog/ I am interested in backporting the fixes to alpine linux stable branches, which means that I'd like to backport the fixes for: - 1_33_stable - 1_32_stable - 1_31_stable So I am trying to find the exact commits that fixes each CVE so I can document that we fix everything. But I need some help with identifying the exact commit that fixes each CVE. I believe others are interested in this as well so I'm sharing my findings here. CVE-2021-42373: A NULL pointer dereference in man leads to denial of service when a section name is supplied but no page argument is given man 1.33.0-1.33.1 This issue does not affect alpine linux because we don't have `man` applet enabled. The upstream fix seems to be: commit 4d4fc5ca5ee4f (man: fix segfault in "man 1") CVE-2021-42374: An out-of-bounds heap read in unlzma leads to information leak and denial of service when crafted LZMA-compressed input is decompressed. This can be triggered by any applet/format that internally supports LZMA compression. lzma/unlzma and more 1.27.0 * 1.33.1 Upstream fix seems to be commit 04f052c56ded (unlzma: fix a case where we could read before beginning of buffer) CVE-2021-42375: An incorrect handling of a special element in ash leads to denial of service when processing a crafted shell command, due to the shell mistaking specific characters for reserved characters. This may be used for DoS under rare conditions of filtered command input. ash 1.33.1 Anyone knows which commit fixes this? It should be one of those, but I have no clue which: 76ef4391548ded8db511e2f7f8f35a3010be7ec5 ash: regressions in process substitution 53d45c934f54b7931cc736eba42903cb1f6d4632 ash: speed up ${v//pattern/repl} 1310d7b1d106d7ab0ec84ce88c12302cca934230 ash: speed up ${v//pattern/repl} if !ASH_OPTIMIZE_FOR_SIZE 53a7a9cd8c15d64fcc2278cf8981ba526dfbe0d2 ash: parser: Fix VSLENGTH parsing with trailing garbage ad57e4e4b23926002ce72979729b017520bef1d0 ash: revert accidental change (should have been separate) 96436fb36a5fa0ac8e993fb093b4788fb5448afe e2fsprogs/*: remove ioctl calling obfuscation 1f60d88cf6f5ad3efcad6e7ef1501ce334046e40 *: more --help tweaks e2b9215868a3d72691e5bc0f887354254606447b *: --help tweaks 457825f77a7c7286647ee888a1000a6bb12ca8fc shells: do not allow bare "read" in non-bash compat configs a1b0d3856d9a0419cb74bf4c87525265871b5868 ash: add process substitution in bash-compatibility mode 33745b1fc8cc6d41f4e708d67800d296668af2ce ash: placate -Werror=format-security 2b7c1aa92c68524559a2067609d09309d5c09adc ash: match bash behavior for ${empty_var/*/repl} 4e039bab375a273344b6c847daa04f13d8317c04 ash: improve --help 85158b600d161bea3fc9d62df8e4ecf4d642fbf0 ash: code shrink 3c13da3dab539eac948de48640d8862857d0c8d0 libbb: introduce and use xgettimeofday(), do not truncate 64-bit time_t in shells I would guess it is "ash: parser: Fix VSLENGTH parsing with trailing garbage". Can someone confirm that? We don't use hush in alpine linux, but someone else might be interested in backporting those. CVE-2021-42376: A NULL pointer dereference in hush leads to denial of service when processing a crafted shell command, due to missing validation after a \x03 delimiter character. This may be used for DoS under very rare conditions of filtered command input. hush 1.16-1.31.1 I guess this is commit 1b7a9b68d0e9 (hush: fix handling of \^C and "^C")? CVE-2021-42377: An attacker-controlled pointer free in hush leads to denial of service and possible code execution when processing a crafted shell command, due to the shell mishandling the &&& string. This may be used for remote code execution under rare conditions of filtered command input. hush 1.33.0-1.33.1 I guess this is commit 83a4967e5042 (hush: fix handling of "cmd && &")? The list of awk fixes is a bit more complicated. I have no clue which of the following commits fixes which CVE: $ git log --format=oneline 1_33_0..1_34_0 -- editors/awk.c dabbeeb79356eef78528acd55e1f143ae80372f7 awk: whitespace and debugging tweaks d3480dd58211d9d8c06ec7ef00089262603003ff awk: disallow break/continue outside of loops d62627487a44d9175b05d49846aeef83fed97019 awk: tighten parsing - disallow extra semicolons ab755e3717cefc06fd28ce8db56f0402412afaa3 awk: in parsing, remove superfluous NEWLINE check; optimize builtin arg evaluation 8d269ef85984f6476e7fdbec2c5a70f3b5c48a72 awk: fix printf "%-10c", 0 caa93ecdd3a9b998a69dcbfafdddbc9c58887ec3 awk: fix corner case in awk_printf 39aabfe8f033c9c62acf676b660dc979714d26a7 awk: unbreak "cmd" | getline 4ef8841b21e27e7c7f58d3c9901c833b4fa5a862 awk: unbreak "printf('%c') can output NUL" testcase 3d57a8490738d9febaa4496eba791e4fbfc91826 awk: undo TI_PRINT, it introduced a bug (print with any redirect acting as printf) 49c3ce64f092fd5434fc67056f312bd32f82bae3 awk: rollback_token() + chain_group() == chain_until_rbrace() e2e3802987266c98df0efdf40ad5da4b07df0113 awk: fix printf buffer overflow 08ca313d7edb99687068b93b5d2435b59f3db23a awk: simplify tests for operation class cb042b05828c4c89320bc9c7454c04c2761bbb9a awk: restore strdup elision optimization in assignment 90404ed2f62a872ffd9a555660b7ce17fae372d8 awk: match(): code shrink 0e3ef4efb061366bfa4b9609fe3a03f3a1e40f0e awk: rand(): 64-bit constants should be ULL 2211fa70ccad29fc7bccd34c13141850ebb199da awk: do not use a copy of g_progname for node->l.new_progname e1e7ad6b6005b2265667040fc9d7f69b73b0d5b0 awk: support %F %a %A in printf 1f765709ed9c9595647853ac2cd7905f218c3044 awk: open-code TS_OPTERM, no logic changes 2b65e73db3254a7228802886546152c72217017d awk: tighten rules in action parsing 717200eb43c9420773c0f8b751aadabba3052027 awk: rename GRPSTART/END to L/RBRACE, no code changes b705bf55395bf338f9b9888d87e418f67d4f1a29 awk: move match() code out-of-line 646429e05e2f62250da80aa8d98111f3a9818e9a awk: use smaller regmatch_t arrays, they had 2 elements for no apparent reason a5d7b0f4f4e9728c3eb7a06d38227d9f3351e677 awk: fix detection of VAR=VAL arguments 4d902ea9def573cd15271177abbfa50fbf30c84f awk: fix beavior of "exit" without parameter 8bb03da906e1f8f750123214b15a19d7d4e166c1 awk: rand() could return 1.0, fix this - should be in [0,1) 37ae8cdc6e428e68ad76f6b446881ecff305ebd3 awk: beautify builtins table, no code changes 47d9133896f0de6b17393309193051e4bd52015e awk: enforce simple builtins' argument number 786ca197ad1305607efaccb067c19931d9e765b1 awk: make builtin definitions more understandable, no code changes 640212ae0ea8a1b47cd73a080d77b25b9f3ccd40 awk: do not special-case "delete" ef5463cf16f88c0992b2073a30ab6081c86fdf23 awk: shuffle globals for smaller offsets 966cafcc77d8cda5d1a95bc73080e9a9b9010a45 awk: use "static" tmpvars in main and exit 1193c68fa718ff16c47aba23f8532bf1568f294e awk: when parsing length(), simplify eating of LPAREN 40573556f2a67b11319785e0479b7087d02c060e awk: shuffle functions to reduce forward declarations, no code changes 8b4c429025c233640bd5c5838552f34683a06fc0 awk: use static tmpvars instead of nvalloc(1)ed ones 1573487e2100892d06e3628828690692313a48d5 awk: rename temp variables, no code changes d7354df169603807fe2ac4f8a0f9f72c9703184f awk: evaluate all, even superfluous function args ca9278ee5855a91a5521960d3743809f47ed27b8 awk: rewrite "print" logic a bit to make it clearer d1507101695f6bad35a61c4770b7d3913597ac16 awk: allow empty fuinctions with no arguments, disallow function redefinitions 86fc2872b33224cfa5442700c2a8abd020cbf900 awk: replace incorrect use of union in undefined function check (no code changes) 6cf6f1eaee1f6be2b936c2ff0e5852c00740edb4 awk: remove custom pool allocator for temporary awk variables 3aff3b9cb81c1f574aaafaf3981e755c6639e2bc awk: assorted optimizations b3c91a127f8baecee0265ba92898ae1e718bdb31 awk: free unused parsing structures after parse is done 21fbee2e87ddf7b47bb501b6529b63ac2b3af0bd awk: document which hashes are used at what state (parse/execute) 6872c193a935df47facf717c15a32f93b43c6bcf awk: fix parsing of expressions such as "v (a)" 686287b5da98508dd03fb295745c82d00440131e awk: deindent a block, no code changes 216d3d8ad9b7d0346cf439ccaca18d0a263e7608 awk: code shrink 4f27503a1ecab8dfe373a349df3d8fe3c22e2160 awk: get rid of "move name one char back" trick in next_token() f414fb4411e65662b44f038ed3175789172edc20 awk: when parsing TC_FUNCTION token, eat its opening '(' cb6061a4e9860bf3d529109b34103ce3bde6d735 awk: g_buf[] does not need a separate allocation 926420795b4191e045d4a316bfed19f84275a185 awk: simplify parsing of function declaration 9782cb7774f00a3e777e3d764ccce15055a29977 awk: rename TC_SEQSTART/END to L/RPAREN, no code changes a493441ca52adca7df3976c668f2e7c48d1b67a1 awk: deindent code block, no code changes adcd9a6f349f3f2715a586b45fb27350b37cf1e5 awk: use TS_foo for combined token classes. No code changes 832cb4fcb98d2845bd3f9d244593fc1b5f362ca0 awk: make ltclass ("last token class") local to next_token() af0172369eb024fff3c8c2cd2c8765a7fde5a9f5 awk: remove redundant check 78645d8371e69ce82841b66aa5ef69c02055f5bc awk: move locals deeper into scopes where they are used, no logic changes 8c5da0323bf2da02c40c587c5694b22e3ec623fb awk: more efficient -f FILE, document what "some trick in next_token" is ac4786ba002620eb4c046c847e69d6a12ea0e322 qwk: make code clearer, no actual code changes fd217c1cbf7a702ad632bb21f7757433de1755b7 awk: after preinc/dec, only allow variable, field ref, array ref, or another preinc/dec a885ce1af05c4eaa5ebcf883cb3da3433ca1c48b awk: fix use-after-free in "$BIGNUM1 $BIGGERNUM2" concat op e8fe9f96356a6b19ec907ea30cffc829c539a7ff awk: allow printf('%c') to output NUL, closes 13486 CVE-2021-42378: A use-after-free in awk leads to denial of service and possibly code execution when processing a crafted awk pattern in the getvar_i function awk 1.16-1.33.1 CVE-2021-42379: A use-after-free in awk leads to denial of service and possibly code execution when processing a crafted awk pattern in the next_input_file function awk 1.18-1.33.1 CVE-2021-42380: A use-after-free in awk leads to denial of service and possibly code execution when processing a crafted awk pattern in the clrvar function awk 1.28-1.33.1 CVE-2021-42381: A use-after-free in awk leads to denial of service and possibly code execution when processing a crafted awk pattern in the hash_init function awk 1.21-1.33.1 CVE-2021-42382: A use-after-free in awk leads to denial of service and possibly code execution when processing a crafted awk pattern in the getvar_s function awk 1.26-1.33.1 CVE-2021-42383: A use-after-free in awk leads to denial of service and possibly code execution when processing a crafted awk pattern in the evaluate function awk 1.33.1 NOTE: I think this is a bit peculiar. It is claimed that 1.33.0 is not affected (compare with CVE-2021-42377), which means that 1.33.1 would introduce this problem. However. There are no changes in awk between 1.33.0 and 1.33.1. CVE-2021-42384: A use-after-free in awk leads to denial of service and possibly code execution when processing a crafted awk pattern in the handle_special function awk 1.18-1.33.1 CVE-2021-42385: A use-after-free in awk leads to denial of service and possibly code execution when processing a crafted awk pattern in the evaluate function awk 1.16-1.33.1 CVE-2021-42386: A use-after-free in awk leads to denial of service and possibly code execution when processing a crafted awk pattern in the nvalloc function awk 1.16-1.33.1 If I get some help identifying exactly what commits fixes each issue I'll try cherry pick them to 1_31_stable - 1_33_stable branches and submit patches to they can be applied upstream in those branches. From xiechengliang1 at huawei.com Thu Nov 11 12:33:28 2021 From: xiechengliang1 at huawei.com (xiechengliang) Date: Thu, 11 Nov 2021 12:33:28 +0000 Subject: =?gb2312?B?tPC4tDogQmFja3BvcnRpbmcgc2VjdXJpdHkgZml4ZXMgZm9yIDFfMzFfc3Rh?= =?gb2312?B?YmxlLCAxXzMyX3N0YWJsZSBhbmQgMV8zM19zdGFibGU=?= In-Reply-To: <20211111114415.4e5b2394@ncopa-desktop.lan> References: <20211111114415.4e5b2394@ncopa-desktop.lan> Message-ID: <124a5751106245f2a7dcbd96e6ebaba7@huawei.com> I asked one of the disclosers of these vulnerabilities by email, he gave me the following results. CVE fix CVE-2021-42373 commit 4d4fc5ca5ee4f (man: fix segfault in "man 1") CVE-2021-42374 commit 04f052c56ded (unlzma: fix a case where we could read before beginning of buffer) CVE-2021-42375 commit 53a7a9cd8c15 (ash: parser: Fix VSLENGTH parsing with trailing garbage) CVE-2021-42376 commit 1b7a9b68d0e9 (hush: fix handling of \^C and "^C") CVE-2021-42377 commit 83a4967e5042 (hush: fix handling of "cmd && &") CVE-2021-42378-- CVE-2021-42386, For the CVE related to the awk, he also doesn't know which patch is for each CVE. The following is part of the original text of his email: " BusyBox maintainers fixed our reported issues across multiple commits, especially for the awk utility, so it?s not straight forward to find all of the fix commits easily." Can anyone point out the repair commit of awk related CVE ? -----????----- ???: busybox [mailto:busybox-bounces at busybox.net] ?? Natanael Copa ????: 2021?11?11? 18:44 ???: busybox at busybox.net ??: Backporting security fixes for 1_31_stable, 1_32_stable and 1_33_stable Hi! There are a number of security issues published that affects busybox older than 1.34. https://jfrog.com/blog/unboxing-busybox-14-new-vulnerabilities-uncovered-by-claroty-and-jfrog/ I am interested in backporting the fixes to alpine linux stable branches, which means that I'd like to backport the fixes for: - 1_33_stable - 1_32_stable - 1_31_stable So I am trying to find the exact commits that fixes each CVE so I can document that we fix everything. But I need some help with identifying the exact commit that fixes each CVE. I believe others are interested in this as well so I'm sharing my findings here. CVE-2021-42373: A NULL pointer dereference in man leads to denial of service when a section name is supplied but no page argument is given man 1.33.0-1.33.1 This issue does not affect alpine linux because we don't have `man` applet enabled. The upstream fix seems to be: commit 4d4fc5ca5ee4f (man: fix segfault in "man 1") CVE-2021-42374: An out-of-bounds heap read in unlzma leads to information leak and denial of service when crafted LZMA-compressed input is decompressed. This can be triggered by any applet/format that internally supports LZMA compression. lzma/unlzma and more 1.27.0 * 1.33.1 Upstream fix seems to be commit 04f052c56ded (unlzma: fix a case where we could read before beginning of buffer) CVE-2021-42375: An incorrect handling of a special element in ash leads to denial of service when processing a crafted shell command, due to the shell mistaking specific characters for reserved characters. This may be used for DoS under rare conditions of filtered command input. ash 1.33.1 Anyone knows which commit fixes this? It should be one of those, but I have no clue which: 76ef4391548ded8db511e2f7f8f35a3010be7ec5 ash: regressions in process substitution 53d45c934f54b7931cc736eba42903cb1f6d4632 ash: speed up ${v//pattern/repl} 1310d7b1d106d7ab0ec84ce88c12302cca934230 ash: speed up ${v//pattern/repl} if !ASH_OPTIMIZE_FOR_SIZE 53a7a9cd8c15d64fcc2278cf8981ba526dfbe0d2 ash: parser: Fix VSLENGTH parsing with trailing garbage ad57e4e4b23926002ce72979729b017520bef1d0 ash: revert accidental change (should have been separate) 96436fb36a5fa0ac8e993fb093b4788fb5448afe e2fsprogs/*: remove ioctl calling obfuscation 1f60d88cf6f5ad3efcad6e7ef1501ce334046e40 *: more --help tweaks e2b9215868a3d72691e5bc0f887354254606447b *: --help tweaks 457825f77a7c7286647ee888a1000a6bb12ca8fc shells: do not allow bare "read" in non-bash compat configs a1b0d3856d9a0419cb74bf4c87525265871b5868 ash: add process substitution in bash-compatibility mode 33745b1fc8cc6d41f4e708d67800d296668af2ce ash: placate -Werror=format-security 2b7c1aa92c68524559a2067609d09309d5c09adc ash: match bash behavior for ${empty_var/*/repl} 4e039bab375a273344b6c847daa04f13d8317c04 ash: improve --help 85158b600d161bea3fc9d62df8e4ecf4d642fbf0 ash: code shrink 3c13da3dab539eac948de48640d8862857d0c8d0 libbb: introduce and use xgettimeofday(), do not truncate 64-bit time_t in shells I would guess it is "ash: parser: Fix VSLENGTH parsing with trailing garbage". Can someone confirm that? We don't use hush in alpine linux, but someone else might be interested in backporting those. CVE-2021-42376: A NULL pointer dereference in hush leads to denial of service when processing a crafted shell command, due to missing validation after a \x03 delimiter character. This may be used for DoS under very rare conditions of filtered command input. hush 1.16-1.31.1 I guess this is commit 1b7a9b68d0e9 (hush: fix handling of \^C and "^C")? CVE-2021-42377: An attacker-controlled pointer free in hush leads to denial of service and possible code execution when processing a crafted shell command, due to the shell mishandling the &&& string. This may be used for remote code execution under rare conditions of filtered command input. hush 1.33.0-1.33.1 I guess this is commit 83a4967e5042 (hush: fix handling of "cmd && &")? The list of awk fixes is a bit more complicated. I have no clue which of the following commits fixes which CVE: $ git log --format=oneline 1_33_0..1_34_0 -- editors/awk.c dabbeeb79356eef78528acd55e1f143ae80372f7 awk: whitespace and debugging tweaks d3480dd58211d9d8c06ec7ef00089262603003ff awk: disallow break/continue outside of loops d62627487a44d9175b05d49846aeef83fed97019 awk: tighten parsing - disallow extra semicolons ab755e3717cefc06fd28ce8db56f0402412afaa3 awk: in parsing, remove superfluous NEWLINE check; optimize builtin arg evaluation 8d269ef85984f6476e7fdbec2c5a70f3b5c48a72 awk: fix printf "%-10c", 0 caa93ecdd3a9b998a69dcbfafdddbc9c58887ec3 awk: fix corner case in awk_printf 39aabfe8f033c9c62acf676b660dc979714d26a7 awk: unbreak "cmd" | getline 4ef8841b21e27e7c7f58d3c9901c833b4fa5a862 awk: unbreak "printf('%c') can output NUL" testcase 3d57a8490738d9febaa4496eba791e4fbfc91826 awk: undo TI_PRINT, it introduced a bug (print with any redirect acting as printf) 49c3ce64f092fd5434fc67056f312bd32f82bae3 awk: rollback_token() + chain_group() == chain_until_rbrace() e2e3802987266c98df0efdf40ad5da4b07df0113 awk: fix printf buffer overflow 08ca313d7edb99687068b93b5d2435b59f3db23a awk: simplify tests for operation class cb042b05828c4c89320bc9c7454c04c2761bbb9a awk: restore strdup elision optimization in assignment 90404ed2f62a872ffd9a555660b7ce17fae372d8 awk: match(): code shrink 0e3ef4efb061366bfa4b9609fe3a03f3a1e40f0e awk: rand(): 64-bit constants should be ULL 2211fa70ccad29fc7bccd34c13141850ebb199da awk: do not use a copy of g_progname for node->l.new_progname e1e7ad6b6005b2265667040fc9d7f69b73b0d5b0 awk: support %F %a %A in printf 1f765709ed9c9595647853ac2cd7905f218c3044 awk: open-code TS_OPTERM, no logic changes 2b65e73db3254a7228802886546152c72217017d awk: tighten rules in action parsing 717200eb43c9420773c0f8b751aadabba3052027 awk: rename GRPSTART/END to L/RBRACE, no code changes b705bf55395bf338f9b9888d87e418f67d4f1a29 awk: move match() code out-of-line 646429e05e2f62250da80aa8d98111f3a9818e9a awk: use smaller regmatch_t arrays, they had 2 elements for no apparent reason a5d7b0f4f4e9728c3eb7a06d38227d9f3351e677 awk: fix detection of VAR=VAL arguments 4d902ea9def573cd15271177abbfa50fbf30c84f awk: fix beavior of "exit" without parameter 8bb03da906e1f8f750123214b15a19d7d4e166c1 awk: rand() could return 1.0, fix this - should be in [0,1) 37ae8cdc6e428e68ad76f6b446881ecff305ebd3 awk: beautify builtins table, no code changes 47d9133896f0de6b17393309193051e4bd52015e awk: enforce simple builtins' argument number 786ca197ad1305607efaccb067c19931d9e765b1 awk: make builtin definitions more understandable, no code changes 640212ae0ea8a1b47cd73a080d77b25b9f3ccd40 awk: do not special-case "delete" ef5463cf16f88c0992b2073a30ab6081c86fdf23 awk: shuffle globals for smaller offsets 966cafcc77d8cda5d1a95bc73080e9a9b9010a45 awk: use "static" tmpvars in main and exit 1193c68fa718ff16c47aba23f8532bf1568f294e awk: when parsing length(), simplify eating of LPAREN 40573556f2a67b11319785e0479b7087d02c060e awk: shuffle functions to reduce forward declarations, no code changes 8b4c429025c233640bd5c5838552f34683a06fc0 awk: use static tmpvars instead of nvalloc(1)ed ones 1573487e2100892d06e3628828690692313a48d5 awk: rename temp variables, no code changes d7354df169603807fe2ac4f8a0f9f72c9703184f awk: evaluate all, even superfluous function args ca9278ee5855a91a5521960d3743809f47ed27b8 awk: rewrite "print" logic a bit to make it clearer d1507101695f6bad35a61c4770b7d3913597ac16 awk: allow empty fuinctions with no arguments, disallow function redefinitions 86fc2872b33224cfa5442700c2a8abd020cbf900 awk: replace incorrect use of union in undefined function check (no code changes) 6cf6f1eaee1f6be2b936c2ff0e5852c00740edb4 awk: remove custom pool allocator for temporary awk variables 3aff3b9cb81c1f574aaafaf3981e755c6639e2bc awk: assorted optimizations b3c91a127f8baecee0265ba92898ae1e718bdb31 awk: free unused parsing structures after parse is done 21fbee2e87ddf7b47bb501b6529b63ac2b3af0bd awk: document which hashes are used at what state (parse/execute) 6872c193a935df47facf717c15a32f93b43c6bcf awk: fix parsing of expressions such as "v (a)" 686287b5da98508dd03fb295745c82d00440131e awk: deindent a block, no code changes 216d3d8ad9b7d0346cf439ccaca18d0a263e7608 awk: code shrink 4f27503a1ecab8dfe373a349df3d8fe3c22e2160 awk: get rid of "move name one char back" trick in next_token() f414fb4411e65662b44f038ed3175789172edc20 awk: when parsing TC_FUNCTION token, eat its opening '(' cb6061a4e9860bf3d529109b34103ce3bde6d735 awk: g_buf[] does not need a separate allocation 926420795b4191e045d4a316bfed19f84275a185 awk: simplify parsing of function declaration 9782cb7774f00a3e777e3d764ccce15055a29977 awk: rename TC_SEQSTART/END to L/RPAREN, no code changes a493441ca52adca7df3976c668f2e7c48d1b67a1 awk: deindent code block, no code changes adcd9a6f349f3f2715a586b45fb27350b37cf1e5 awk: use TS_foo for combined token classes. No code changes 832cb4fcb98d2845bd3f9d244593fc1b5f362ca0 awk: make ltclass ("last token class") local to next_token() af0172369eb024fff3c8c2cd2c8765a7fde5a9f5 awk: remove redundant check 78645d8371e69ce82841b66aa5ef69c02055f5bc awk: move locals deeper into scopes where they are used, no logic changes 8c5da0323bf2da02c40c587c5694b22e3ec623fb awk: more efficient -f FILE, document what "some trick in next_token" is ac4786ba002620eb4c046c847e69d6a12ea0e322 qwk: make code clearer, no actual code changes fd217c1cbf7a702ad632bb21f7757433de1755b7 awk: after preinc/dec, only allow variable, field ref, array ref, or another preinc/dec a885ce1af05c4eaa5ebcf883cb3da3433ca1c48b awk: fix use-after-free in "$BIGNUM1 $BIGGERNUM2" concat op e8fe9f96356a6b19ec907ea30cffc829c539a7ff awk: allow printf('%c') to output NUL, closes 13486 CVE-2021-42378: A use-after-free in awk leads to denial of service and possibly code execution when processing a crafted awk pattern in the getvar_i function awk 1.16-1.33.1 CVE-2021-42379: A use-after-free in awk leads to denial of service and possibly code execution when processing a crafted awk pattern in the next_input_file function awk 1.18-1.33.1 CVE-2021-42380: A use-after-free in awk leads to denial of service and possibly code execution when processing a crafted awk pattern in the clrvar function awk 1.28-1.33.1 CVE-2021-42381: A use-after-free in awk leads to denial of service and possibly code execution when processing a crafted awk pattern in the hash_init function awk 1.21-1.33.1 CVE-2021-42382: A use-after-free in awk leads to denial of service and possibly code execution when processing a crafted awk pattern in the getvar_s function awk 1.26-1.33.1 CVE-2021-42383: A use-after-free in awk leads to denial of service and possibly code execution when processing a crafted awk pattern in the evaluate function awk 1.33.1 NOTE: I think this is a bit peculiar. It is claimed that 1.33.0 is not affected (compare with CVE-2021-42377), which means that 1.33.1 would introduce this problem. However. There are no changes in awk between 1.33.0 and 1.33.1. CVE-2021-42384: A use-after-free in awk leads to denial of service and possibly code execution when processing a crafted awk pattern in the handle_special function awk 1.18-1.33.1 CVE-2021-42385: A use-after-free in awk leads to denial of service and possibly code execution when processing a crafted awk pattern in the evaluate function awk 1.16-1.33.1 CVE-2021-42386: A use-after-free in awk leads to denial of service and possibly code execution when processing a crafted awk pattern in the nvalloc function awk 1.16-1.33.1 If I get some help identifying exactly what commits fixes each issue I'll try cherry pick them to 1_31_stable - 1_33_stable branches and submit patches to they can be applied upstream in those branches. _______________________________________________ busybox mailing list busybox at busybox.net http://lists.busybox.net/mailman/listinfo/busybox From ncopa at alpinelinux.org Thu Nov 11 13:18:37 2021 From: ncopa at alpinelinux.org (Natanael Copa) Date: Thu, 11 Nov 2021 14:18:37 +0100 Subject: Backporting security fixes for 1_31_stable, 1_32_stable and 1_33_stable In-Reply-To: <124a5751106245f2a7dcbd96e6ebaba7@huawei.com> References: <20211111114415.4e5b2394@ncopa-desktop.lan> <124a5751106245f2a7dcbd96e6ebaba7@huawei.com> Message-ID: <20211111141837.29cf8a4c@ncopa-desktop.lan> On Thu, 11 Nov 2021 12:33:28 +0000 xiechengliang wrote: > I asked one of the disclosers of these vulnerabilities by email, he gave me the following results. > > CVE fix > CVE-2021-42373 commit 4d4fc5ca5ee4f (man: fix segfault in "man 1") > CVE-2021-42374 commit 04f052c56ded (unlzma: fix a case where we could read before beginning of buffer) > CVE-2021-42375 commit 53a7a9cd8c15 (ash: parser: Fix VSLENGTH parsing with trailing garbage) This confirms my own investigation of CVE-2021-42375, thanks! > CVE-2021-42376 commit 1b7a9b68d0e9 (hush: fix handling of \^C and "^C") > CVE-2021-42377 commit 83a4967e5042 (hush: fix handling of "cmd && &") > > CVE-2021-42378-- CVE-2021-42386, For the CVE related to the awk, he > also doesn't know which patch is for each CVE. Yeah, the above were the "easy" ones. awk seems significantly more difficult to find a correct match. > The following is part of the original text of his email: > " BusyBox maintainers fixed our reported issues across multiple > commits, especially for the awk utility, so it*s not straight forward > to find all of the fix commits easily." > > Can anyone point out the repair commit of awk related CVE ? +1 -nc From David.Laight at ACULAB.COM Thu Nov 11 15:09:10 2021 From: David.Laight at ACULAB.COM (David Laight) Date: Thu, 11 Nov 2021 15:09:10 +0000 Subject: Add 'IRIX mode' to top. Message-ID: Add 'IRIX mode' to top. On a multi-cpu system 'IRIX mode' displays a singled threaded process that is spinning as using 100% cpu. This is generally more useful than the current 'Solaris mode' that reports 100/num_cpu% cpu. A multi-threaded program that is busy on multiple cpu will show a cpu use > 100%. Enabled by -I on the command line or 'i' on stdin. Remove some (uint16_t) casts from the 'delta jiffies' value. With enough cpu, fast enough HZ, and long enough delay I think 64k can be exceeded. I doubt intended efficiency of 16x16 multiple makes any difference. Signed-off-by: David Laight --- It might be worth adding an extra column for processes with a lot of busy threads on systems with a lot of cpu. Note that this is a normal diff from an installed tree. I don't have the git tree. --- top.c.1.33 2021-11-11 09:49:08.165982660 +0000 +++ top.c 2021-11-11 11:28:50.155674293 +0000 @@ -166,6 +166,7 @@ #endif #if ENABLE_FEATURE_TOP_SMP_CPU smallint smp_cpu_info; /* one/many cpu info lines? */ + smallint irix_mode; /* 100% => one cpu busy */ #endif unsigned lines; /* screen height */ #if ENABLE_FEATURE_TOP_INTERACTIVE @@ -202,6 +203,7 @@ #define sort_field (G.sort_field ) #define inverted (G.inverted ) #define smp_cpu_info (G.smp_cpu_info ) +#define irix_mode (G.irix_mode ) #define initial_settings (G.initial_settings ) #define sort_function (G.sort_function ) #define prev_hist (G.prev_hist ) @@ -223,8 +225,9 @@ OPT_n = (1 << 1), OPT_b = (1 << 2), OPT_H = (1 << 3), - OPT_m = (1 << 4), - OPT_EOF = (1 << 5), /* pseudo: "we saw EOF in stdin" */ + OPT_I = (1 << 4), + OPT_m = (1 << 5), + OPT_EOF = (1 << 6), /* pseudo: "we saw EOF in stdin" */ }; #define OPT_BATCH_MODE (option_mask32 & OPT_b) @@ -314,6 +317,13 @@ return; #else if (!smp_cpu_info) { + if (irix_mode && !num_cpus) { + jiffy_counts_t dummy_jif; + while (read_cpu_jiffy(fp, &dummy_jif) >= 4) + num_cpus++; + if (!num_cpus) + irix_mode = 0; + } fclose(fp); return; } @@ -328,8 +338,10 @@ break; num_cpus++; } - if (num_cpus == 0) /* /proc/stat with only "cpu ..." line?! */ + if (num_cpus == 0) { /* /proc/stat with only "cpu ..." line?! */ smp_cpu_info = 0; + irix_mode = 0; + } cpu_prev_jif = xzalloc(sizeof(cpu_prev_jif[0]) * num_cpus); @@ -602,6 +614,28 @@ return meminfo[MI_MEMTOTAL]; } +#if ENABLE_FEATURE_TOP_DECIMALS +# define UPSCALE 1000 +# define FMT "%s" +# define SHOW_STAT(name, buf_id) fmt_proc_pc(name, buf_id) +static NOINLINE const char *fmt_proc_pc(unsigned value, unsigned buf_id) +{ + static char bufs[2][16]; + char *buf = bufs[buf_id]; + + if (value >= 1000) + snprintf(buf, 16, "%5u", value/10); + else + snprintf(buf, 16, "%3u.%c", value/10, '0' + (value % 10)); + return buf; +} + +#else +# define UPSCALE 100 +# define FMT "%4u%%" +# define SHOW_STAT(name, buf_id) name +#endif + static NOINLINE void display_process_list(int lines_rem, int scr_width) { enum { @@ -627,17 +661,6 @@ " COMMAND"); lines_rem--; -#if ENABLE_FEATURE_TOP_DECIMALS -# define UPSCALE 1000 -# define CALC_STAT(name, val) div_t name = div((val), 10) -# define SHOW_STAT(name) name.quot, '0'+name.rem -# define FMT "%3u.%c" -#else -# define UPSCALE 100 -# define CALC_STAT(name, val) unsigned name = (val) -# define SHOW_STAT(name) name -# define FMT "%4u%%" -#endif /* * %VSZ = s->vsz/MemTotal */ @@ -664,14 +687,18 @@ * we assume that unsigned is at least 32-bit. */ pcpu_shift = 6; - pcpu_scale = UPSCALE*64 * (uint16_t)busy_jifs; + pcpu_scale = UPSCALE*64 * busy_jifs; if (pcpu_scale == 0) pcpu_scale = 1; while (pcpu_scale < (1U << (BITS_PER_INT-2))) { pcpu_scale *= 4; pcpu_shift += 2; } - tmp_unsigned = (uint16_t)(cur_jif.total - prev_jif.total) * total_pcpu; + tmp_unsigned = (cur_jif.total - prev_jif.total) * total_pcpu; +#if ENABLE_FEATURE_TOP_SMP_CPU + if (irix_mode && num_cpus) + tmp_unsigned /= num_cpus; +#endif if (tmp_unsigned != 0) pcpu_scale /= tmp_unsigned; /* we want (s->pcpu * pcpu_scale) to never overflow */ @@ -692,9 +719,9 @@ char vsz_str_buf[8]; unsigned col; - CALC_STAT(pmem, (s->vsz*pmem_scale + pmem_half) >> pmem_shift); + unsigned pmem = (s->vsz*pmem_scale + pmem_half) >> pmem_shift; #if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE - CALC_STAT(pcpu, (s->pcpu*pcpu_scale + pcpu_half) >> pcpu_shift); + unsigned pcpu = (s->pcpu*pcpu_scale + pcpu_half) >> pcpu_shift; #endif smart_ulltoa5(s->vsz, vsz_str_buf, " mgtpezy"); @@ -706,9 +733,9 @@ " ", s->pid, s->ppid, get_cached_username(s->uid), s->state, vsz_str_buf, - SHOW_STAT(pmem) + SHOW_STAT(pmem, 0) IF_FEATURE_TOP_SMP_PROCESS(, s->last_seen_on_cpu) - IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE(, SHOW_STAT(pcpu)) + IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE(, SHOW_STAT(pcpu, 1)) ); if ((int)(scr_width - col) > 1) read_cmdline(line_buf + col, scr_width - col, s->pid, s->comm); @@ -1034,6 +1061,10 @@ get_jiffy_counts(); continue; } + if (c == 'i') { + irix_mode ^= 1; + continue; + } # endif # endif break; /* unknown key -> force refresh */ @@ -1120,7 +1151,7 @@ /* all args are options; -n NUM */ make_all_argv_opts(argv); /* options can be specified w/o dash */ - col = getopt32(argv, "d:n:bHm", &str_interval, &str_iterations); + col = getopt32(argv, "d:n:bHIm", &str_interval, &str_iterations); /* NB: -m and -H are accepted even if not configured */ #if ENABLE_FEATURE_TOPMEM if (col & OPT_m) /* -m (busybox specific) */ @@ -1145,6 +1176,10 @@ scan_mask |= PSSCAN_TASKS; } #endif +#if ENABLE_FEATURE_TOP_SMP_CPU + if (col & OPT_I) + irix_mode = 1; +#endif /* change to /proc */ xchdir("/proc"); - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales) From ncopa at alpinelinux.org Thu Nov 11 16:09:03 2021 From: ncopa at alpinelinux.org (Natanael Copa) Date: Thu, 11 Nov 2021 17:09:03 +0100 Subject: Request for 1.33.2 release Message-ID: <20211111170903.49ac42f6@ncopa-desktop.lan> Hi! I think it would be nice with a 1.33.2 release, with fixes for all the recent CVEs. Those commits should be cherry-picked to 1_33_stable: 4d4fc5ca5ee4f (man: fix segfault in "man 1") CVE-2021-42373 04f052c56ded5 (unlzma: fix a case where we could read before beginning of buffer) CVE-2021-42374 53a7a9cd8c15d (ash: parser: Fix VSLENGTH parsing with trailing garbage) CVE-2021-42375 1b7a9b68d0e9 (hush: fix handling of \^C and "^C") CVE-2021-42376 83a4967e5042 (hush: fix handling of "cmd && &") CVE-2021-42377 We can cherry-pick all 61 commits to be sure to cover the CVE-2021-42378 to CVE-2021-42386: for i in $(git log --format=oneline 1_33_0..1_34_0 -- editors/awk.c \ | awk '{print $1}' | tac); do git cherry-pick -x $i|| break; done In other words, run: git checkout 1_33_stable git cherry-pick -x 4d4fc5ca5ee4f 04f052c56ded5 53a7a9cd8c15d 1b7a9b68d0e9 83a4967e5042 for i in $(git log --format=oneline 1_33_0..1_34_0 -- editors/awk.c \ | awk '{print $1}' | tac); do git cherry-pick -x $i|| break; done git tag 1_33_2 and push that. Hopefully there will be no regressions in awk, but at least it will be less risky than upgrade the entire busybox to 1.34. Thanks! -nc PS. would be great if we also could get similar 1.32.2 and 1.31.1 releases. From David.Laight at ACULAB.COM Fri Nov 12 12:51:35 2021 From: David.Laight at ACULAB.COM (David Laight) Date: Fri, 12 Nov 2021 12:51:35 +0000 Subject: [PATCH v2 0/2] top: Add 'IRIX mode' Message-ID: The busybox top always runs in 'Solaris mode' where the cpu% for a process is a percentage across all the cpu. So a single threaded process in an infinite loop on a 16cpu system only reports 8% cpu use. In 'IRIX mode' it will report 100% - much more useful. In IRIX mode a multi-threaded process can report over 100%. When threads are displayed (-H) IRIX mode probably ought to be the default - but I've not changed that. Patch 1/2 removes a lot of 'cruft' from the process display that was there to avoid two integer divides. I actually doubt that was ever worth-while, the loop is probably dominated by the system calls to read the process arguments. Patch 2/2 adds IRIX mode. Changes from v1 - add patch 1/2. Both patches are diffs against the 1.33 release install. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales) From David.Laight at ACULAB.COM Fri Nov 12 12:51:38 2021 From: David.Laight at ACULAB.COM (David Laight) Date: Fri, 12 Nov 2021 12:51:38 +0000 Subject: [PATCH v2 1/2] top: remove 'cruft' the process display code. Message-ID: <19a7eedb1dd641b6a5b91ed340b4845d@AcuMS.aculab.com> Simplify process cpu% and vsz% calculations. Remove the code that avoided integer divides when generating the cpu%. The loop will be dominated by the system calls to read the command line. So even if the division is a code loop it is probably noise. On Linux the process cpu time values are in 'jiffies' so there is no need to re-scale the values based on the sum of the process times. (This was already assumed because of issues with short lived processes.) Signed-off-by: David Laight --- --- a/top.c 2021-11-11 09:49:08.165982660 +0000 +++ b/top.c 2021-11-12 11:25:43.849264597 +0000 @@ -139,7 +139,6 @@ unsigned long long usr, nic, sys, idle; unsigned long long iowait, irq, softirq, steal; unsigned long long total; - unsigned long long busy; } jiffy_counts_t; /* This structure stores some critical information from one frame to @@ -292,8 +291,6 @@ if (ret >= 4) { p_jif->total = p_jif->usr + p_jif->nic + p_jif->sys + p_jif->idle + p_jif->iowait + p_jif->irq + p_jif->softirq + p_jif->steal; - /* procps 2.x does not count iowait as busy time */ - p_jif->busy = p_jif->total - p_jif->idle - p_jif->iowait; } return ret; @@ -604,19 +601,10 @@ static NOINLINE void display_process_list(int lines_rem, int scr_width) { - enum { - BITS_PER_INT = sizeof(int) * 8 - }; - top_status_t *s; unsigned long total_memory = display_header(scr_width, &lines_rem); /* or use total_vsz? */ - /* xxx_shift and xxx_scale variables allow us to replace - * expensive divides with multiply and shift */ - unsigned pmem_shift, pmem_scale, pmem_half; #if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE - unsigned tmp_unsigned; - unsigned pcpu_shift, pcpu_scale, pcpu_half; - unsigned busy_jifs; + unsigned delta_jifs; #endif /* what info of the processes is shown */ @@ -638,49 +626,10 @@ # define SHOW_STAT(name) name # define FMT "%4u%%" #endif - /* - * %VSZ = s->vsz/MemTotal - */ - pmem_shift = BITS_PER_INT-11; - pmem_scale = UPSCALE*(1U<<(BITS_PER_INT-11)) / total_memory; - /* s->vsz is in kb. we want (s->vsz * pmem_scale) to never overflow */ - while (pmem_scale >= 512) { - pmem_scale /= 4; - pmem_shift -= 2; - } - pmem_half = (1U << pmem_shift) / (ENABLE_FEATURE_TOP_DECIMALS ? 20 : 2); -#if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE - busy_jifs = cur_jif.busy - prev_jif.busy; - /* This happens if there were lots of short-lived processes - * between two top updates (e.g. compilation) */ - if (total_pcpu < busy_jifs) total_pcpu = busy_jifs; - /* - * CPU% = s->pcpu/sum(s->pcpu) * busy_cpu_ticks/total_cpu_ticks - * (pcpu is delta of sys+user time between samples) - */ - /* (cur_jif.xxx - prev_jif.xxx) and s->pcpu are - * in 0..~64000 range (HZ*update_interval). - * we assume that unsigned is at least 32-bit. - */ - pcpu_shift = 6; - pcpu_scale = UPSCALE*64 * (uint16_t)busy_jifs; - if (pcpu_scale == 0) - pcpu_scale = 1; - while (pcpu_scale < (1U << (BITS_PER_INT-2))) { - pcpu_scale *= 4; - pcpu_shift += 2; - } - tmp_unsigned = (uint16_t)(cur_jif.total - prev_jif.total) * total_pcpu; - if (tmp_unsigned != 0) - pcpu_scale /= tmp_unsigned; - /* we want (s->pcpu * pcpu_scale) to never overflow */ - while (pcpu_scale >= 1024) { - pcpu_scale /= 4; - pcpu_shift -= 2; - } - pcpu_half = (1U << pcpu_shift) / (ENABLE_FEATURE_TOP_DECIMALS ? 20 : 2); - /* printf(" pmem_scale=%u pcpu_scale=%u ", pmem_scale, pcpu_scale); */ +#if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE + /* s->pcpu is in jiffies */ + delta_jifs = cur_jif.total - prev_jif.total; #endif /* Ok, all preliminary data is ready, go through the list */ @@ -692,9 +641,9 @@ char vsz_str_buf[8]; unsigned col; - CALC_STAT(pmem, (s->vsz*pmem_scale + pmem_half) >> pmem_shift); + CALC_STAT(pmem, (s->vsz * UPSCALE + total_memory/2) / total_memory); #if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE - CALC_STAT(pcpu, (s->pcpu*pcpu_scale + pcpu_half) >> pcpu_shift); + CALC_STAT(pcpu, (s->pcpu * UPSCALE + delta_jifs/2) / delta_jifs); #endif smart_ulltoa5(s->vsz, vsz_str_buf, " mgtpezy"); - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales) From David.Laight at ACULAB.COM Fri Nov 12 12:51:41 2021 From: David.Laight at ACULAB.COM (David Laight) Date: Fri, 12 Nov 2021 12:51:41 +0000 Subject: [PATCH v2 2/2] top: Add 'IRIX mode' Message-ID: <39474d8b6b3e4ef4b80a9006498a0b80@AcuMS.aculab.com> Add IRIX mode to process cpu% calculation. For historic reasons top has two different ways of calculation the process cpu% in a multi-cpu system. Add 'IRIX mode' where a single-threaded process in an infinite loop shows 100% and a multi-threaded program can exceed 100%. The default remains 'Solaris mode' (even for -H) where the maximum cpu% for a single thread is 100/num_cpus. Signed-off-by: David Laight --- --- b/top.c 2021-11-12 11:25:43.849264597 +0000 +++ c/top.c 2021-11-12 11:36:49.510234350 +0000 @@ -165,6 +165,7 @@ #endif #if ENABLE_FEATURE_TOP_SMP_CPU smallint smp_cpu_info; /* one/many cpu info lines? */ + smallint irix_mode; /* 100% => one cpu busy */ #endif unsigned lines; /* screen height */ #if ENABLE_FEATURE_TOP_INTERACTIVE @@ -201,6 +202,7 @@ #define sort_field (G.sort_field ) #define inverted (G.inverted ) #define smp_cpu_info (G.smp_cpu_info ) +#define irix_mode (G.irix_mode ) #define initial_settings (G.initial_settings ) #define sort_function (G.sort_function ) #define prev_hist (G.prev_hist ) @@ -222,8 +224,9 @@ OPT_n = (1 << 1), OPT_b = (1 << 2), OPT_H = (1 << 3), - OPT_m = (1 << 4), - OPT_EOF = (1 << 5), /* pseudo: "we saw EOF in stdin" */ + OPT_I = (1 << 4), + OPT_m = (1 << 5), + OPT_EOF = (1 << 6), /* pseudo: "we saw EOF in stdin" */ }; #define OPT_BATCH_MODE (option_mask32 & OPT_b) @@ -311,6 +314,13 @@ return; #else if (!smp_cpu_info) { + if (irix_mode && !num_cpus) { + jiffy_counts_t dummy_jif; + while (read_cpu_jiffy(fp, &dummy_jif) >= 4) + num_cpus++; + if (!num_cpus) + irix_mode = 0; + } fclose(fp); return; } @@ -599,6 +609,27 @@ return meminfo[MI_MEMTOTAL]; } +#if ENABLE_FEATURE_TOP_DECIMALS +# define UPSCALE 1000 +# define STAT_BUF(buf_name) char buf_name[8]; +# define SHOW_STAT(name, buf) fmt_proc_pc(name, buf) +# define FMT "%s" +static NOINLINE const char *fmt_proc_pc(unsigned value, char *buf) +{ + if (value >= 1000) + snprintf(buf, 16, "%5u", value/10); + else + snprintf(buf, 16, "%3u.%c", value/10, '0' + (value % 10)); + return buf; +} + +#else +# define UPSCALE 100 +# define STAT_BUF(buf_name) +# define SHOW_STAT(name, buf) name +# define FMT "%4u%%" +#endif + static NOINLINE void display_process_list(int lines_rem, int scr_width) { top_status_t *s; @@ -615,21 +646,13 @@ " COMMAND"); lines_rem--; -#if ENABLE_FEATURE_TOP_DECIMALS -# define UPSCALE 1000 -# define CALC_STAT(name, val) div_t name = div((val), 10) -# define SHOW_STAT(name) name.quot, '0'+name.rem -# define FMT "%3u.%c" -#else -# define UPSCALE 100 -# define CALC_STAT(name, val) unsigned name = (val) -# define SHOW_STAT(name) name -# define FMT "%4u%%" -#endif - #if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE /* s->pcpu is in jiffies */ delta_jifs = cur_jif.total - prev_jif.total; +#if ENABLE_FEATURE_TOP_SMP_CPU + if (irix_mode && num_cpus) + delta_jifs /= num_cpus; +#endif #endif /* Ok, all preliminary data is ready, go through the list */ @@ -641,9 +664,11 @@ char vsz_str_buf[8]; unsigned col; - CALC_STAT(pmem, (s->vsz * UPSCALE + total_memory/2) / total_memory); + unsigned pmem = (s->vsz * UPSCALE + total_memory/2) / total_memory; + STAT_BUF(pmem_buf) #if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE - CALC_STAT(pcpu, (s->pcpu * UPSCALE + delta_jifs/2) / delta_jifs); + unsigned pcpu = (s->pcpu * UPSCALE + delta_jifs/2) / delta_jifs; + STAT_BUF(pcpu_buf) #endif smart_ulltoa5(s->vsz, vsz_str_buf, " mgtpezy"); @@ -655,9 +680,9 @@ " ", s->pid, s->ppid, get_cached_username(s->uid), s->state, vsz_str_buf, - SHOW_STAT(pmem) + SHOW_STAT(pmem, pmem_buf) IF_FEATURE_TOP_SMP_PROCESS(, s->last_seen_on_cpu) - IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE(, SHOW_STAT(pcpu)) + IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE(, SHOW_STAT(pcpu, pcpu_buf)) ); if ((int)(scr_width - col) > 1) read_cmdline(line_buf + col, scr_width - col, s->pid, s->comm); @@ -983,6 +1008,10 @@ get_jiffy_counts(); continue; } + if (c == 'i') { + irix_mode ^= 1; + continue; + } # endif # endif break; /* unknown key -> force refresh */ @@ -1069,7 +1098,7 @@ /* all args are options; -n NUM */ make_all_argv_opts(argv); /* options can be specified w/o dash */ - col = getopt32(argv, "d:n:bHm", &str_interval, &str_iterations); + col = getopt32(argv, "d:n:bHIm", &str_interval, &str_iterations); /* NB: -m and -H are accepted even if not configured */ #if ENABLE_FEATURE_TOPMEM if (col & OPT_m) /* -m (busybox specific) */ @@ -1094,6 +1123,10 @@ scan_mask |= PSSCAN_TASKS; } #endif +#if ENABLE_FEATURE_TOP_SMP_CPU + if (col & OPT_I) + irix_mode = 1; +#endif /* change to /proc */ xchdir("/proc"); - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales) From David.Laight at ACULAB.COM Mon Nov 15 11:05:22 2021 From: David.Laight at ACULAB.COM (David Laight) Date: Mon, 15 Nov 2021 11:05:22 +0000 Subject: [PATCH] Fix const pointer assignment trick on clang 9+ Message-ID: <409fc7ad81934748a790cb28755cb24a@AcuMS.aculab.com> If you are trying to tell the compiler that a pointer (or other value) might change and it mustn't reload it (etc) then this might work: #define LAUNDER(val_in, val_out) \ asm volatile ( "" : "&r" (val_out) : "0" (val_in)) That is (more or less) equivalent to: val_out = (typeof(val_out))val_in; except that the compiler can't track the value. (assuming it doesn't 'peek inside' the asm.) David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales) From soeren at soeren-tempel.net Wed Nov 17 14:08:53 2021 From: soeren at soeren-tempel.net (soeren at soeren-tempel.net) Date: Wed, 17 Nov 2021 15:08:53 +0100 Subject: [PATCH] ed: fix current line number for file passed via the command-line Message-ID: <20211117140853.20743-1-soeren@soeren-tempel.net> From: S?ren Tempel 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. Signed-off-by: S?ren Tempel --- editors/ed.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/editors/ed.c b/editors/ed.c index 14540e566..cb903bca7 100644 --- a/editors/ed.c +++ b/editors/ed.c @@ -1010,8 +1010,6 @@ int ed_main(int argc UNUSED_PARAM, char **argv) if (!readLines(fileName, 1)) { return EXIT_SUCCESS; } - if (lastNum) - setCurNum(1); dirty = FALSE; } From soeren at soeren-tempel.net Wed Nov 17 14:12:25 2021 From: soeren at soeren-tempel.net (soeren at soeren-tempel.net) Date: Wed, 17 Nov 2021 15:12:25 +0100 Subject: [PATCH] ed: align output of read command with POSIX.1-2008 Message-ID: <20211117141225.21136-1-soeren@soeren-tempel.net> From: S?ren Tempel 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. Signed-off-by: S?ren Tempel --- editors/ed.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/editors/ed.c b/editors/ed.c index cb903bca7..0d96d263c 100644 --- a/editors/ed.c +++ b/editors/ed.c @@ -400,9 +400,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 vda.linux at googlemail.com Thu Nov 18 17:49:46 2021 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Thu, 18 Nov 2021 18:49:46 +0100 Subject: Backporting security fixes for 1_31_stable, 1_32_stable and 1_33_stable In-Reply-To: <20211111114415.4e5b2394@ncopa-desktop.lan> References: <20211111114415.4e5b2394@ncopa-desktop.lan> Message-ID: On Thu, Nov 11, 2021 at 11:50 AM Natanael Copa wrote: > The list of awk fixes is a bit more complicated. I have no clue which > of the following commits fixes which CVE: > > $ git log --format=oneline 1_33_0..1_34_0 -- editors/awk.c > dabbeeb79356eef78528acd55e1f143ae80372f7 awk: whitespace and debugging tweaks > d3480dd58211d9d8c06ec7ef00089262603003ff awk: disallow break/continue outside of loops > d62627487a44d9175b05d49846aeef83fed97019 awk: tighten parsing - disallow extra semicolons > ab755e3717cefc06fd28ce8db56f0402412afaa3 awk: in parsing, remove superfluous NEWLINE check; optimize builtin arg evaluation > 8d269ef85984f6476e7fdbec2c5a70f3b5c48a72 awk: fix printf "%-10c", 0 > caa93ecdd3a9b998a69dcbfafdddbc9c58887ec3 awk: fix corner case in awk_printf > 39aabfe8f033c9c62acf676b660dc979714d26a7 awk: unbreak "cmd" | getline > 4ef8841b21e27e7c7f58d3c9901c833b4fa5a862 awk: unbreak "printf('%c') can output NUL" testcase > 3d57a8490738d9febaa4496eba791e4fbfc91826 awk: undo TI_PRINT, it introduced a bug (print with any redirect acting as printf) > 49c3ce64f092fd5434fc67056f312bd32f82bae3 awk: rollback_token() + chain_group() == chain_until_rbrace() > e2e3802987266c98df0efdf40ad5da4b07df0113 awk: fix printf buffer overflow > 08ca313d7edb99687068b93b5d2435b59f3db23a awk: simplify tests for operation class > cb042b05828c4c89320bc9c7454c04c2761bbb9a awk: restore strdup elision optimization in assignment > 90404ed2f62a872ffd9a555660b7ce17fae372d8 awk: match(): code shrink > 0e3ef4efb061366bfa4b9609fe3a03f3a1e40f0e awk: rand(): 64-bit constants should be ULL > 2211fa70ccad29fc7bccd34c13141850ebb199da awk: do not use a copy of g_progname for node->l.new_progname > e1e7ad6b6005b2265667040fc9d7f69b73b0d5b0 awk: support %F %a %A in printf > 1f765709ed9c9595647853ac2cd7905f218c3044 awk: open-code TS_OPTERM, no logic changes > 2b65e73db3254a7228802886546152c72217017d awk: tighten rules in action parsing > 717200eb43c9420773c0f8b751aadabba3052027 awk: rename GRPSTART/END to L/RBRACE, no code changes > b705bf55395bf338f9b9888d87e418f67d4f1a29 awk: move match() code out-of-line > 646429e05e2f62250da80aa8d98111f3a9818e9a awk: use smaller regmatch_t arrays, they had 2 elements for no apparent reason > a5d7b0f4f4e9728c3eb7a06d38227d9f3351e677 awk: fix detection of VAR=VAL arguments > 4d902ea9def573cd15271177abbfa50fbf30c84f awk: fix beavior of "exit" without parameter > 8bb03da906e1f8f750123214b15a19d7d4e166c1 awk: rand() could return 1.0, fix this - should be in [0,1) > 37ae8cdc6e428e68ad76f6b446881ecff305ebd3 awk: beautify builtins table, no code changes > 47d9133896f0de6b17393309193051e4bd52015e awk: enforce simple builtins' argument number > 786ca197ad1305607efaccb067c19931d9e765b1 awk: make builtin definitions more understandable, no code changes > 640212ae0ea8a1b47cd73a080d77b25b9f3ccd40 awk: do not special-case "delete" > ef5463cf16f88c0992b2073a30ab6081c86fdf23 awk: shuffle globals for smaller offsets > 966cafcc77d8cda5d1a95bc73080e9a9b9010a45 awk: use "static" tmpvars in main and exit > 1193c68fa718ff16c47aba23f8532bf1568f294e awk: when parsing length(), simplify eating of LPAREN > 40573556f2a67b11319785e0479b7087d02c060e awk: shuffle functions to reduce forward declarations, no code changes > 8b4c429025c233640bd5c5838552f34683a06fc0 awk: use static tmpvars instead of nvalloc(1)ed ones > 1573487e2100892d06e3628828690692313a48d5 awk: rename temp variables, no code changes > d7354df169603807fe2ac4f8a0f9f72c9703184f awk: evaluate all, even superfluous function args > ca9278ee5855a91a5521960d3743809f47ed27b8 awk: rewrite "print" logic a bit to make it clearer > d1507101695f6bad35a61c4770b7d3913597ac16 awk: allow empty fuinctions with no arguments, disallow function redefinitions > 86fc2872b33224cfa5442700c2a8abd020cbf900 awk: replace incorrect use of union in undefined function check (no code changes) > 6cf6f1eaee1f6be2b936c2ff0e5852c00740edb4 awk: remove custom pool allocator for temporary awk variables > 3aff3b9cb81c1f574aaafaf3981e755c6639e2bc awk: assorted optimizations > b3c91a127f8baecee0265ba92898ae1e718bdb31 awk: free unused parsing structures after parse is done > 21fbee2e87ddf7b47bb501b6529b63ac2b3af0bd awk: document which hashes are used at what state (parse/execute) > 6872c193a935df47facf717c15a32f93b43c6bcf awk: fix parsing of expressions such as "v (a)" > 686287b5da98508dd03fb295745c82d00440131e awk: deindent a block, no code changes > 216d3d8ad9b7d0346cf439ccaca18d0a263e7608 awk: code shrink > 4f27503a1ecab8dfe373a349df3d8fe3c22e2160 awk: get rid of "move name one char back" trick in next_token() > f414fb4411e65662b44f038ed3175789172edc20 awk: when parsing TC_FUNCTION token, eat its opening '(' > cb6061a4e9860bf3d529109b34103ce3bde6d735 awk: g_buf[] does not need a separate allocation > 926420795b4191e045d4a316bfed19f84275a185 awk: simplify parsing of function declaration > 9782cb7774f00a3e777e3d764ccce15055a29977 awk: rename TC_SEQSTART/END to L/RPAREN, no code changes > a493441ca52adca7df3976c668f2e7c48d1b67a1 awk: deindent code block, no code changes > adcd9a6f349f3f2715a586b45fb27350b37cf1e5 awk: use TS_foo for combined token classes. No code changes > 832cb4fcb98d2845bd3f9d244593fc1b5f362ca0 awk: make ltclass ("last token class") local to next_token() > af0172369eb024fff3c8c2cd2c8765a7fde5a9f5 awk: remove redundant check > 78645d8371e69ce82841b66aa5ef69c02055f5bc awk: move locals deeper into scopes where they are used, no logic changes > 8c5da0323bf2da02c40c587c5694b22e3ec623fb awk: more efficient -f FILE, document what "some trick in next_token" is > ac4786ba002620eb4c046c847e69d6a12ea0e322 qwk: make code clearer, no actual code changes > fd217c1cbf7a702ad632bb21f7757433de1755b7 awk: after preinc/dec, only allow variable, field ref, array ref, or another preinc/dec > a885ce1af05c4eaa5ebcf883cb3da3433ca1c48b awk: fix use-after-free in "$BIGNUM1 $BIGGERNUM2" concat op Use-after-free was fixed in the above commit. > e8fe9f96356a6b19ec907ea30cffc829c539a7ff awk: allow printf('%c') to output NUL, closes 13486 > > > > CVE-2021-42378: A use-after-free in awk leads to denial of > service and possibly code execution when processing a > crafted awk pattern in the getvar_i function > > awk 1.16-1.33.1 > > CVE-2021-42379: A use-after-free in awk leads to denial of > service and possibly code execution when processing a > crafted awk pattern in the next_input_file > function > > awk 1.18-1.33.1 > > CVE-2021-42380: A use-after-free in awk leads to denial of > service and possibly code execution when processing a > crafted awk pattern in the clrvar function > > awk 1.28-1.33.1 > > CVE-2021-42381: A use-after-free in awk leads to denial of > service and possibly code execution when processing a > crafted awk pattern in the hash_init function > > awk 1.21-1.33.1 > > CVE-2021-42382: A use-after-free in awk leads to denial of > service and possibly code execution when processing a > crafted awk pattern in the getvar_s function > > awk 1.26-1.33.1 > > CVE-2021-42383: A use-after-free in awk leads to denial of > service and possibly code execution when processing a > crafted awk pattern in the evaluate function > > awk 1.33.1 > > NOTE: I think this is a bit peculiar. It is claimed that > 1.33.0 is not affected (compare with CVE-2021-42377), > which means that 1.33.1 would introduce this problem. > However. There are no changes in awk between 1.33.0 and > 1.33.1. > > CVE-2021-42384: A use-after-free in awk leads to denial of > service and possibly code execution when processing a > crafted awk pattern in the handle_special > function > > awk 1.18-1.33.1 > > CVE-2021-42385: A use-after-free in awk leads to denial of > service and possibly code execution when processing a > crafted awk pattern in the evaluate function > > awk 1.16-1.33.1 > > CVE-2021-42386: A use-after-free in awk leads to denial of > service and possibly code execution when processing a > crafted awk pattern in the nvalloc function > > awk 1.16-1.33.1 A bug they IIRC did not mention was that printf could overflow the buffer. This is fixed now. From soeren at soeren-tempel.net Sat Nov 20 17:17:10 2021 From: soeren at soeren-tempel.net (soeren at soeren-tempel.net) Date: Sat, 20 Nov 2021 18:17:10 +0100 Subject: [PATCH] ed: add support for -p command-line option as mandated by POSIX Message-ID: <20211120171710.8921-1-soeren@soeren-tempel.net> From: S?ren Tempel 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. Support for the remaining -s option will be added in a separate commit since it requires a general restructuring of error handling in Busybox ed. Signed-off-by: S?ren Tempel --- editors/ed.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/editors/ed.c b/editors/ed.c index 0d96d263c..6473281a1 100644 --- a/editors/ed.c +++ b/editors/ed.c @@ -48,6 +48,7 @@ struct globals { char *bufBase; char *bufPtr; char *fileName; + 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 ) @@ -790,7 +792,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])) @@ -994,6 +996,8 @@ static void doCommands(void) int ed_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int ed_main(int argc UNUSED_PARAM, char **argv) { + int opt; + INIT_G(); bufSize = INITBUF_SIZE; @@ -1002,8 +1006,15 @@ int ed_main(int argc UNUSED_PARAM, char **argv) lines.next = &lines; lines.prev = &lines; - if (argv[1]) { - fileName = xstrdup(argv[1]); + opt = getopt32(argv, "p:", &prompt); + if (!(opt & 0x1)) + prompt = xstrdup(""); /* no prompt by default */ + + argc -= optind; + argv += optind; + + if (argc >= 1) { + fileName = xstrdup(argv[0]); if (!readLines(fileName, 1)) { return EXIT_SUCCESS; } From David.Laight at ACULAB.COM Sat Nov 20 21:42:46 2021 From: David.Laight at ACULAB.COM (David Laight) Date: Sat, 20 Nov 2021 21:42:46 +0000 Subject: [PATCH] ed: add support for -p command-line option as mandated by POSIX In-Reply-To: <20211120171710.8921-1-soeren@soeren-tempel.net> References: <20211120171710.8921-1-soeren@soeren-tempel.net> Message-ID: From: soeren at soeren-tempel.net > Sent: 20 November 2021 17:17 > > 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. > ... > - if (argv[1]) { > - fileName = xstrdup(argv[1]); > + opt = getopt32(argv, "p:", &prompt); > + if (!(opt & 0x1)) > + prompt = xstrdup(""); /* no prompt by default */ You shouldn't need the strdup(). I think you can even do: if (!(opt & 1)) prompt = ""; because (IIRC and for historic reasons) quoted strings are char[] not const char[]. OTOH an explicit local static or a zero byte in the data area might be more usual for busybox. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales) From explorer09 at gmail.com Sun Nov 21 07:12:26 2021 From: explorer09 at gmail.com (Kang-Che Sung) Date: Sun, 21 Nov 2021 15:12:26 +0800 Subject: [PATCH] ed: add support for -p command-line option as mandated by POSIX In-Reply-To: References: <20211120171710.8921-1-soeren@soeren-tempel.net> Message-ID: On Sunday, November 21, 2021, David Laight wrote: > From: soeren at soeren-tempel.net >> Sent: 20 November 2021 17:17 >> >> 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. >> > ... >> - if (argv[1]) { >> - fileName = xstrdup(argv[1]); >> + opt = getopt32(argv, "p:", &prompt); >> + if (!(opt & 0x1)) >> + prompt = xstrdup(""); /* no prompt by default */ > > You shouldn't need the strdup(). > I think you can even do: > if (!(opt & 1)) > prompt = ""; > because (IIRC and for historic reasons) quoted strings are char[] not const char[]. I don't know why you are messing up with the "constness" of the strings. C standard says string literal is of type const char[], and the const keyword didn't exist before C89. Note the compiler is free to merge string literals with identical content so they share the same buffer in the .rodata section (that's why they are const). -------------- next part -------------- An HTML attachment was scrubbed... URL: From harald at gigawatt.nl Sun Nov 21 11:00:39 2021 From: harald at gigawatt.nl (Harald van Dijk) Date: Sun, 21 Nov 2021 11:00:39 +0000 Subject: [PATCH] ed: add support for -p command-line option as mandated by POSIX In-Reply-To: References: <20211120171710.8921-1-soeren@soeren-tempel.net> Message-ID: <1105fb72-27c3-87f3-3fb2-ba724cf9b7ea@gigawatt.nl> On 21/11/2021 07:12, Kang-Che Sung wrote: > On Sunday, November 21, 2021, David Laight > wrote: > > From: soeren at soeren-tempel.net > >> Sent: 20 November 2021 17:17 > >> > >> 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. > >> > > ... > >> -? ? ?if (argv[1]) { > >> -? ? ? ? ? ? ?fileName = xstrdup(argv[1]); > >> +? ? ?opt = getopt32(argv, "p:", &prompt); > >> +? ? ?if (!(opt & 0x1)) > >> +? ? ? ? ? ? ?prompt = xstrdup(""); /* no prompt by default */ > > > > You shouldn't need the strdup(). > > I think you can even do: > > ? ? ? ? if (!(opt & 1)) > > ? ? ? ? ? ? ? ? prompt = ""; > > because (IIRC and for historic reasons) quoted strings are char[] not > const char[]. > > I don't know why you are messing up with the "constness" of the strings. > C standard says string literal is of type const char[], and the const > keyword didn't exist before C89. > Note the compiler is free to merge string literals with identical > content so they share the same buffer in the .rodata section (that's why > they are const). It does not say that, it says the opposite: The multibyte character sequence is then used to initialize an array of static storage duration and length just sufficient to contain the sequence. For character string literals, the array elements have type char, and are initialized with the individual bytes of the multibyte character sequence. Note the "char" as opposed to "const char". The C standard does go on to say If the program attempts to modify such an array, the behavior is undefined. but this is not reflected in the type system. However, busybox is built with -Wwrite-strings where supported, and -Wwrite-strings causes GCC and clang to switch to a non-standard mode in which string literals do have type const char[N], so for the purposes of busybox, what you thought the standard said does actually apply. Back to the patch, there is nothing preventing the prompt from being defined as const char *, is there? Does that not allow the xstrdup() to be avoided? Cheers, Harald van Dijk From soeren at soeren-tempel.net Sun Nov 21 11:24:45 2021 From: soeren at soeren-tempel.net (soeren at soeren-tempel.net) Date: Sun, 21 Nov 2021 12:24:45 +0100 Subject: [PATCH v2] ed: add support for -p command-line option as mandated by POSIX In-Reply-To: <1105fb72-27c3-87f3-3fb2-ba724cf9b7ea@gigawatt.nl> References: <1105fb72-27c3-87f3-3fb2-ba724cf9b7ea@gigawatt.nl> Message-ID: <20211121112445.19442-1-soeren@soeren-tempel.net> From: S?ren Tempel 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. Support for the remaining -s option will be added in a separate commit since it requires a general restructuring of error handling in Busybox ed. Signed-off-by: S?ren Tempel --- editors/ed.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/editors/ed.c b/editors/ed.c index 0d96d263c..a54a0b0a6 100644 --- a/editors/ed.c +++ b/editors/ed.c @@ -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 ) @@ -790,7 +792,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])) @@ -994,6 +996,8 @@ static void doCommands(void) int ed_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int ed_main(int argc UNUSED_PARAM, char **argv) { + int opt; + INIT_G(); bufSize = INITBUF_SIZE; @@ -1002,8 +1006,15 @@ int ed_main(int argc UNUSED_PARAM, char **argv) lines.next = &lines; lines.prev = &lines; - if (argv[1]) { - fileName = xstrdup(argv[1]); + opt = getopt32(argv, "p:", &prompt); + if (!(opt & 0x01)) + prompt = ""; /* no prompt by default */ + + argc -= optind; + argv += optind; + + if (argc >= 1) { + fileName = xstrdup(argv[0]); if (!readLines(fileName, 1)) { return EXIT_SUCCESS; } From explorer09 at gmail.com Sun Nov 21 14:52:06 2021 From: explorer09 at gmail.com (Kang-Che Sung) Date: Sun, 21 Nov 2021 22:52:06 +0800 Subject: [PATCH] ed: add support for -p command-line option as mandated by POSIX In-Reply-To: <1105fb72-27c3-87f3-3fb2-ba724cf9b7ea@gigawatt.nl> References: <20211120171710.8921-1-soeren@soeren-tempel.net> <1105fb72-27c3-87f3-3fb2-ba724cf9b7ea@gigawatt.nl> Message-ID: On Sunday, November 21, 2021, Harald van Dijk wrote: > On 21/11/2021 07:12, Kang-Che Sung wrote: >> >> On Sunday, November 21, 2021, David Laight > wrote: >> > >> > You shouldn't need the strdup(). >> > I think you can even do: >> > if (!(opt & 1)) >> > prompt = ""; >> > because (IIRC and for historic reasons) quoted strings are char[] not const char[]. >> >> I don't know why you are messing up with the "constness" of the strings. C standard says string literal is of type const char[], and the const keyword didn't exist before C89. >> Note the compiler is free to merge string literals with identical content so they share the same buffer in the .rodata section (that's why they are const). > > It does not say that, it says the opposite: > > The multibyte character sequence is then used to initialize an array > of static storage duration and length just sufficient to contain the > sequence. For character string literals, the array elements have type > char, and are initialized with the individual bytes of the multibyte > character sequence. > > Note the "char" as opposed to "const char". It refers to the initialization like this: char str[] = "abc"; str[0] = 'd'; // Vaild not this: char arr[5]; arr = "abc"; arr[0] = 'd'; // Undefined behavior nor this: char *ptr; ptr = "abc"; *ptr = 'd'; // Undefined behavior And messing with the "constness" is always a bad idea. The compiler actually treats the string literals of the latter two examples to have the type 'const char[]', so modifying the contents yields undefined behavior, matching what the standard says. -------------- next part -------------- An HTML attachment was scrubbed... URL: From harald at gigawatt.nl Sun Nov 21 15:22:39 2021 From: harald at gigawatt.nl (Harald van Dijk) Date: Sun, 21 Nov 2021 15:22:39 +0000 Subject: [PATCH] ed: add support for -p command-line option as mandated by POSIX In-Reply-To: References: <20211120171710.8921-1-soeren@soeren-tempel.net> <1105fb72-27c3-87f3-3fb2-ba724cf9b7ea@gigawatt.nl> Message-ID: <68669e4c-36fd-c0bc-cc03-b6eeab79be89@gigawatt.nl> On 21/11/2021 14:52, Kang-Che Sung wrote: > On Sunday, November 21, 2021, Harald van Dijk > wrote: > > On 21/11/2021 07:12, Kang-Che Sung wrote: > >> I don't know why you are messing up with the "constness" of the > strings. C standard says string literal is of type const char[], and the > const keyword didn't exist before C89. > >> Note the compiler is free to merge string literals with identical > content so they share the same buffer in the .rodata section (that's why > they are const). > > > > It does not say that, it says the opposite: > > > > ? The multibyte character sequence is then used to initialize an array > > ? of static storage duration and length just sufficient to contain the > > ? sequence. For character string literals, the array elements have type > > ? char, and are initialized with the individual bytes of the multibyte > > ? character sequence. > > > > Note the "char" as opposed to "const char". > > It refers to the initialization like this: > > ? ?char str[] = "abc"; > ? ?str[0] = 'd'; // Vaild No, it doesn't. I was quoting 6.4.5 String literals, which covers string literals. Initialisation is covered by 6.7.9 Initialization, reading An array of character type may be initialized by a character string literal or UTF?8 string literal, optionally enclosed in braces. Successive bytes of the string literal (including the terminating null character if there is room or if the array is of unknown size) initialize the elements of the array. But maybe you would like something more explicit: that section also contains in an example: On the other hand, the declaration char *p = "abc"; defines p with type "pointer to char" and initializes it to point to an object with type "array of char" with length 4 whose elements are initialized with a character string literal. If an attempt is made to use p to modify the contents of the array, the behavior is undefined. It explicitly says the string literal itself has type "array of char", not "array of const char". Modifying it is undefined, but that does not make the type const. Except, as noted, in the non-standard mode in which the compiler is invoked for busybox. Cheers, Harald van Dijk From David.Laight at ACULAB.COM Mon Nov 22 08:53:54 2021 From: David.Laight at ACULAB.COM (David Laight) Date: Mon, 22 Nov 2021 08:53:54 +0000 Subject: [PATCH v2] ed: add support for -p command-line option as mandated by POSIX In-Reply-To: <20211121112445.19442-1-soeren@soeren-tempel.net> References: <1105fb72-27c3-87f3-3fb2-ba724cf9b7ea@gigawatt.nl> <20211121112445.19442-1-soeren@soeren-tempel.net> Message-ID: <04aeb833f7df4697bf3793409c0acd76@AcuMS.aculab.com> From: soeren at soeren-tempel.net > Sent: 21 November 2021 11:25 > > 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. > > Support for the remaining -s option will be added in a separate commit > since it requires a general restructuring of error handling in Busybox > ed. ... > @@ -790,7 +792,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)); Actually it is probably cleaner to put the NULL test when prompt is used: len = read_line_input(NULL, prompt ? prompt : "", buf, sizeof(buf)); Saves all the faffing about. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales) From ariadne at dereferenced.org Tue Nov 23 00:40:59 2021 From: ariadne at dereferenced.org (Ariadne Conill) Date: Mon, 22 Nov 2021 18:40:59 -0600 Subject: [PATCH] pgrep: add support for matching against UID and RUID Message-ID: <20211123004059.28373-1-ariadne@dereferenced.org> This is standard functionality on every other pgrep implementation I found, namely the ones in Illumos, FreeBSD, Linux procps, and macOS. Additionally, real world scripts like pipewire-session are dependent on it being present. function old new delta pgrep_main 818 1007 +189 packed_usage 26001 26032 +31 .rodata 78544 78548 +4 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 224/0) Total: 224 bytes Signed-off-by: Ariadne Conill --- procps/pgrep.c | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/procps/pgrep.c b/procps/pgrep.c index 6d25c247e..6a12ac23b 100644 --- a/procps/pgrep.c +++ b/procps/pgrep.c @@ -42,6 +42,8 @@ //usage: "\n -x Match whole name (not substring)" //usage: "\n -s Match session ID (0 for current)" //usage: "\n -P Match parent process ID" +//usage: "\n -u EUID Match against effective UID" +//usage: "\n -U UID Match against UID" //usage: //usage:#define pkill_trivial_usage //usage: "[-l|-SIGNAL] [-xfvno] [-s SID|-P PPID|PATTERN]" @@ -55,6 +57,8 @@ //usage: "\n -v Negate the match" //usage: "\n -n Signal the newest process only" //usage: "\n -o Signal the oldest process only" +//usage: "\n -u EUID Match against effective UID" +//usage: "\n -U UID Match against UID" #include "libbb.h" #include "xregex.h" @@ -64,7 +68,7 @@ #define pkill (ENABLE_PKILL && (!ENABLE_PGREP || applet_name[1] == 'k')) enum { - /* "vlafxons:+P:+" */ + /* "vlafxonu:U:s:+P:+" */ OPTBIT_V = 0, /* must be first, we need OPT_INVERT = 0/1 */ OPTBIT_L, OPTBIT_A, @@ -72,6 +76,8 @@ enum { OPTBIT_X, OPTBIT_O, OPTBIT_N, + OPTBIT_U, + OPTBIT_UL, OPTBIT_S, OPTBIT_P, }; @@ -85,6 +91,8 @@ enum { #define OPT_LAST (opt & (1 << OPTBIT_N)) #define OPT_SID (opt & (1 << OPTBIT_S)) #define OPT_PPID (opt & (1 << OPTBIT_P)) +#define OPT_EUID (opt & (1 << OPTBIT_UL)) +#define OPT_RUID (opt & (1 << OPTBIT_U)) static void act(unsigned pid, char *cmd, int signo) { @@ -105,7 +113,8 @@ int pgrep_main(int argc UNUSED_PARAM, char **argv) unsigned opt; int scan_mask; int matched_pid; - int sid2match, ppid2match; + int sid2match, ppid2match, uid2match, euid2match; + char *uid_arg = NULL, *euid_arg = NULL; char *cmd_last; procps_status_t *proc; /* These are initialized to 0 */ @@ -131,7 +140,9 @@ int pgrep_main(int argc UNUSED_PARAM, char **argv) /* Parse remaining options */ ppid2match = -1; sid2match = -1; - opt = getopt32(argv, "vlafxons:+P:+", &sid2match, &ppid2match); + uid2match = -1; + euid2match = -1; + opt = getopt32(argv, "vlafxonu:U:s:+P:+", &euid_arg, &uid_arg, &sid2match, &ppid2match); argv += optind; if (pkill && OPT_LIST) { /* -l: print the whole signal list */ @@ -147,8 +158,18 @@ int pgrep_main(int argc UNUSED_PARAM, char **argv) if (OPT_FULL) scan_mask |= PSSCAN_ARGVN; + if (euid_arg) { + scan_mask |= PSSCAN_UIDGID; + euid2match = get_ug_id(euid_arg, xuname2uid); + } + + if (uid_arg) { + scan_mask |= PSSCAN_RUIDGID; + uid2match = get_ug_id(uid_arg, xuname2uid); + } + /* One pattern is required, if no -s and no -P */ - if ((sid2match & ppid2match) < 0 && (!argv[0] || argv[1])) + if ((sid2match & ppid2match) < 0 && uid2match < 0 && euid2match < 0 && (!argv[0] || argv[1])) bb_show_usage(); if (argv[0]) @@ -170,6 +191,10 @@ int pgrep_main(int argc UNUSED_PARAM, char **argv) continue; if (sid2match >= 0 && sid2match != proc->sid) continue; + if (euid2match >= 0 && euid2match != proc->uid) + continue; + if (uid2match >= 0 && uid2match != proc->ruid) + continue; } cmdlen = -1; @@ -202,6 +227,10 @@ int pgrep_main(int argc UNUSED_PARAM, char **argv) goto got_it; if (sid2match >= 0 && sid2match != proc->sid) goto got_it; + if (euid2match >= 0 && euid2match != proc->uid) + goto got_it; + if (uid2match >= 0 && uid2match != proc->ruid) + goto got_it; } match = !argv[0]; /* if no PATTERN, then it's a match, else... */ -- 2.34.0 From vda.linux at googlemail.com Wed Nov 24 13:31:57 2021 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Wed, 24 Nov 2021 14:31:57 +0100 Subject: Request for 1.33.2 release In-Reply-To: <20211111170903.49ac42f6@ncopa-desktop.lan> References: <20211111170903.49ac42f6@ncopa-desktop.lan> Message-ID: On Thu, Nov 11, 2021 at 5:09 PM Natanael Copa wrote: > Hi! > > I think it would be nice with a 1.33.2 release, with fixes for all the recent CVEs. > > Those commits should be cherry-picked to 1_33_stable: > > 4d4fc5ca5ee4f (man: fix segfault in "man 1") CVE-2021-42373 This is not a security bug. man segfaults "safely" by dereferencing NULL pointer (as opposed to dereferencing random value), it can't be used to see any secret information. > 04f052c56ded5 (unlzma: fix a case where we could read before beginning > of buffer) CVE-2021-42374 > 53a7a9cd8c15d (ash: parser: Fix VSLENGTH parsing with trailing > garbage) CVE-2021-42375 > 1b7a9b68d0e9 (hush: fix handling of \^C and "^C") CVE-2021-42376 > 83a4967e5042 (hush: fix handling of "cmd && &") CVE-2021-42377 These can be included. > We can cherry-pick all 61 commits to be sure to cover the > CVE-2021-42378 to CVE-2021-42386: > > for i in $(git log --format=oneline 1_33_0..1_34_0 -- editors/awk.c \ > | awk '{print $1}' | tac); do git cherry-pick -x $i|| break; done awk changes are too big for a stable release. From ncopa at alpinelinux.org Wed Nov 24 13:59:55 2021 From: ncopa at alpinelinux.org (Natanael Copa) Date: Wed, 24 Nov 2021 14:59:55 +0100 Subject: Request for 1.33.2 release In-Reply-To: References: <20211111170903.49ac42f6@ncopa-desktop.lan> Message-ID: <81A959EC-B2C4-4F52-BBB8-4AD6D43F9F5E@alpinelinux.org> > On 24 Nov 2021, at 14:31, Denys Vlasenko wrote: > > On Thu, Nov 11, 2021 at 5:09 PM Natanael Copa wrote: >> Hi! >> >> I think it would be nice with a 1.33.2 release, with fixes for all the recent CVEs. >> >> Those commits should be cherry-picked to 1_33_stable: >> >> 4d4fc5ca5ee4f (man: fix segfault in "man 1") CVE-2021-42373 > > This is not a security bug. man segfaults "safely" by dereferencing > NULL pointer (as opposed to dereferencing random value), it can't be used to > see any secret information. It got a CVE, regardless if it is a real security bug or not. The problem I am trying to solve is to turn all those security scanners to green. They don?t really care if its a real security threat or not. They just want green. And its much easier to just patch the bug than to put up a fight against a handful of scripted security scanners. > >> 04f052c56ded5 (unlzma: fix a case where we could read before beginning >> of buffer) CVE-2021-42374 >> 53a7a9cd8c15d (ash: parser: Fix VSLENGTH parsing with trailing >> garbage) CVE-2021-42375 >> 1b7a9b68d0e9 (hush: fix handling of \^C and "^C") CVE-2021-42376 >> 83a4967e5042 (hush: fix handling of "cmd && &") CVE-2021-42377 > > These can be included. > >> We can cherry-pick all 61 commits to be sure to cover the >> CVE-2021-42378 to CVE-2021-42386: >> >> for i in $(git log --format=oneline 1_33_0..1_34_0 -- editors/awk.c \ >> | awk '{print $1}' | tac); do git cherry-pick -x $i|| break; done > > awk changes are too big for a stable release. Since it is not really possible to confirm that all the listed CVEs are actually fixed without including everything up to the 1.34 release, added a patch for that for Alpine Linux. This is still better for downstream distros/vendors than upgrade to a new major busybox version. For busybox 1.33: https://git.alpinelinux.org/aports/tree/main/busybox/awk-fixes.patch?h=3.14-stable I also backported the patches for busybox 1.32: https://git.alpinelinux.org/aports/tree/main/busybox/awk-fixes.patch?h=3.13-stable And for busybox 1.31: https://git.alpinelinux.org/aports/tree/main/busybox/awk-fixes.patch?h=3.12-stable Those should help silence the security scanners. Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: From foo at mafoo.org.uk Thu Nov 25 08:59:15 2021 From: foo at mafoo.org.uk (Matthew Slowe) Date: Thu, 25 Nov 2021 08:59:15 +0000 Subject: [PATCH] timeout: Add support for "-k" parameter. In-Reply-To: References: Message-ID: I've just noticed that I did not include the required header in my original patch: Package: busybox Version: v1.33.2 (or whatever the current version is) Severity: wishlist On 2021-10-09 12:27, Matthew Slowe wrote: > Add support for GNU coreutils "-k" parameter to timeout applet. > > This patch moves the timing and process checking code into a separate > reusable function and adds a optional second timeout which will send a > SIGKILL to the process if it's still alive. > > The patch introduces a compiler warning about mismatched "const char *" > and "char *". I've left a FIXME. I have just re-built and tested against the latest 1.33.2 branch and the patch is still fine. -- Matthew Slowe From walter.lozano at collabora.com Thu Nov 25 16:11:32 2021 From: walter.lozano at collabora.com (Walter Lozano) Date: Thu, 25 Nov 2021 13:11:32 -0300 Subject: [PATCH] cmp: add support for -n Message-ID: <20211125161132.366897-1-walter.lozano@collabora.com> Add support to for "-n" to cmp in order to compare at most n bytes. Signed-off-by: Walter Lozano --- editors/cmp.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/editors/cmp.c b/editors/cmp.c index e106d814e..e219f589a 100644 --- a/editors/cmp.c +++ b/editors/cmp.c @@ -35,9 +35,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 +51,16 @@ int cmp_main(int argc UNUSED_PARAM, char **argv) int c1, c2; unsigned opt; int retval = 0; + char * n_arg = NULL; + int max_count = -1; opt = getopt32(argv, "^" OPT_STR "\0" "-1" IF_DESKTOP(":?4") IF_NOT_DESKTOP(":?2") - ":l--s:s--l" + ":l--s:s--l", + &n_arg ); argv += optind; @@ -90,6 +94,9 @@ int cmp_main(int argc UNUSED_PARAM, char **argv) else fmt = fmt_differ; + if (opt & CMP_OPT_n) + max_count = atoi(n_arg); + if (ENABLE_DESKTOP) { while (skip1) { getc(fp1); skip1--; } while (skip2) { getc(fp2); skip2--; } @@ -133,7 +140,7 @@ int cmp_main(int argc UNUSED_PARAM, char **argv) if (c1 == '\n') { ++line_pos; } - } while (c1 != EOF); + } while (c1 != EOF && (max_count == -1 || max_count >= 0 && char_pos < max_count)); die_if_ferror(fp1, filename1); die_if_ferror(fp2, filename2); -- 2.30.2 From alex_y_xu at yahoo.ca Thu Nov 25 23:22:49 2021 From: alex_y_xu at yahoo.ca (Alex Xu (Hello71)) Date: Thu, 25 Nov 2021 18:22:49 -0500 Subject: [PATCH 1/2] blkid: remove CONFIG_FEATURE_BLKID_TYPE=n References: <20211125232250.87522-1-alex_y_xu.ref@yahoo.ca> Message-ID: <20211125232250.87522-1-alex_y_xu@yahoo.ca> It complicates implementation of volume_id for mount and saves only ~20 bytes per filesystem type. In any case where 553 bytes is critical, filesystems will be individually selected. Suppose 3 filesystem types are enabled, then CONFIG_FEATURE_BLKID_TYPE=n saves only ~60 bytes, which is negligible. function old new delta .rodata 3269 3455 +186 volume_id_probe_ext 80 126 +46 volume_id_probe_sysv 172 207 +35 display_uuid_cache 117 145 +28 volume_id_probe_hfs_hfsplus 471 497 +26 add_to_uuid_cache 300 326 +26 volume_id_probe_linux_swap 271 294 +23 volume_id_probe_nilfs 86 102 +16 volume_id_probe_udf 613 626 +13 volume_id_probe_ntfs 274 287 +13 volume_id_probe_exfat 262 274 +12 volume_id_probe_xfs 110 121 +11 volume_id_probe_ubifs 68 79 +11 volume_id_probe_romfs 105 116 +11 volume_id_probe_ocfs2 119 130 +11 volume_id_probe_luks 96 107 +11 volume_id_probe_jfs 119 130 +11 volume_id_probe_f2fs 98 109 +11 volume_id_probe_erofs 80 91 +11 volume_id_probe_btrfs 159 170 +11 volume_id_probe_bcache 114 125 +11 volume_id_probe_minix 72 82 +10 volume_id_probe_vfat 903 912 +9 volume_id_probe_linux_raid 143 152 +9 volume_id_probe_iso9660 408 415 +7 volume_id_probe_cramfs 68 69 +1 volume_id_probe_reiserfs 296 279 -17 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 26/1 up/down: 570/-17) Total: 553 bytes --- configs/android2_defconfig | 1 - configs/android_502_defconfig | 1 - configs/android_defconfig | 1 - configs/android_ndk_defconfig | 1 - configs/cygwin_defconfig | 1 - util-linux/blkid.c | 7 ------ util-linux/volume_id/bcache.c | 2 +- util-linux/volume_id/btrfs.c | 2 +- util-linux/volume_id/cramfs.c | 2 +- util-linux/volume_id/erofs.c | 2 +- util-linux/volume_id/exfat.c | 2 +- util-linux/volume_id/ext.c | 3 +-- util-linux/volume_id/f2fs.c | 2 +- util-linux/volume_id/fat.c | 2 +- util-linux/volume_id/get_devname.c | 29 ++++------------------- util-linux/volume_id/hfs.c | 4 ++-- util-linux/volume_id/iso9660.c | 2 +- util-linux/volume_id/jfs.c | 2 +- util-linux/volume_id/lfs.c | 4 ++-- util-linux/volume_id/linux_raid.c | 2 +- util-linux/volume_id/linux_swap.c | 2 +- util-linux/volume_id/luks.c | 2 +- util-linux/volume_id/minix.c | 2 +- util-linux/volume_id/nilfs.c | 2 +- util-linux/volume_id/ntfs.c | 2 +- util-linux/volume_id/ocfs2.c | 2 +- util-linux/volume_id/reiserfs.c | 2 +- util-linux/volume_id/romfs.c | 2 +- util-linux/volume_id/squashfs.c | 4 ++-- util-linux/volume_id/sysv.c | 4 ++-- util-linux/volume_id/ubifs.c | 2 +- util-linux/volume_id/udf.c | 2 +- util-linux/volume_id/volume_id_internal.h | 2 -- util-linux/volume_id/xfs.c | 2 +- 34 files changed, 35 insertions(+), 69 deletions(-) diff --git a/configs/android2_defconfig b/configs/android2_defconfig index d4b8f1616..10eb2b290 100644 --- a/configs/android2_defconfig +++ b/configs/android2_defconfig @@ -502,7 +502,6 @@ CONFIG_REV=y # CONFIG_ACPID is not set # CONFIG_FEATURE_ACPID_COMPAT is not set CONFIG_BLKID=y -# CONFIG_FEATURE_BLKID_TYPE is not set CONFIG_DMESG=y CONFIG_FEATURE_DMESG_PRETTY=y CONFIG_FBSET=y diff --git a/configs/android_502_defconfig b/configs/android_502_defconfig index 104e70f23..908feddb7 100644 --- a/configs/android_502_defconfig +++ b/configs/android_502_defconfig @@ -631,7 +631,6 @@ CONFIG_UEVENT=y CONFIG_ACPID=y CONFIG_FEATURE_ACPID_COMPAT=y CONFIG_BLKID=y -# CONFIG_FEATURE_BLKID_TYPE is not set CONFIG_DMESG=y CONFIG_FEATURE_DMESG_PRETTY=y CONFIG_FBSET=y diff --git a/configs/android_defconfig b/configs/android_defconfig index 92a66048a..c64349ebe 100644 --- a/configs/android_defconfig +++ b/configs/android_defconfig @@ -532,7 +532,6 @@ CONFIG_REV=y # CONFIG_ACPID is not set # CONFIG_FEATURE_ACPID_COMPAT is not set CONFIG_BLKID=y -CONFIG_FEATURE_BLKID_TYPE=y CONFIG_DMESG=y CONFIG_FEATURE_DMESG_PRETTY=y CONFIG_FBSET=y diff --git a/configs/android_ndk_defconfig b/configs/android_ndk_defconfig index 425593454..8cb74404b 100644 --- a/configs/android_ndk_defconfig +++ b/configs/android_ndk_defconfig @@ -555,7 +555,6 @@ CONFIG_UEVENT=y # CONFIG_ACPID is not set # CONFIG_FEATURE_ACPID_COMPAT is not set CONFIG_BLKID=y -CONFIG_FEATURE_BLKID_TYPE=y CONFIG_DMESG=y CONFIG_FEATURE_DMESG_PRETTY=y CONFIG_FBSET=y diff --git a/configs/cygwin_defconfig b/configs/cygwin_defconfig index c09bc9281..81719c1cc 100644 --- a/configs/cygwin_defconfig +++ b/configs/cygwin_defconfig @@ -505,7 +505,6 @@ CONFIG_REV=y # CONFIG_ACPID is not set # CONFIG_FEATURE_ACPID_COMPAT is not set # CONFIG_BLKID is not set -# CONFIG_FEATURE_BLKID_TYPE is not set # CONFIG_DMESG is not set # CONFIG_FEATURE_DMESG_PRETTY is not set # CONFIG_FBSET is not set diff --git a/util-linux/blkid.c b/util-linux/blkid.c index 4a820771f..e8907c101 100644 --- a/util-linux/blkid.c +++ b/util-linux/blkid.c @@ -12,13 +12,6 @@ //config: select VOLUMEID //config: help //config: Lists labels and UUIDs of all filesystems. -//config: -//config:config FEATURE_BLKID_TYPE -//config: bool "Print filesystem type" -//config: default y -//config: depends on BLKID -//config: help -//config: Show TYPE="filesystem type" //applet:IF_BLKID(APPLET_NOEXEC(blkid, blkid, BB_DIR_SBIN, BB_SUID_DROP, blkid)) diff --git a/util-linux/volume_id/bcache.c b/util-linux/volume_id/bcache.c index 085c158db..2c5589380 100644 --- a/util-linux/volume_id/bcache.c +++ b/util-linux/volume_id/bcache.c @@ -99,7 +99,7 @@ int FAST_FUNC volume_id_probe_bcache(struct volume_id *id /*,uint64_t off*/) volume_id_set_label_string(id, sb->label, SB_LABEL_SIZE); volume_id_set_uuid(id, sb->uuid, UUID_DCE); - IF_FEATURE_BLKID_TYPE(id->type = "bcache";) + id->type = "bcache"; return 0; } diff --git a/util-linux/volume_id/btrfs.c b/util-linux/volume_id/btrfs.c index a3ddf9782..ee1dc4ccb 100644 --- a/util-linux/volume_id/btrfs.c +++ b/util-linux/volume_id/btrfs.c @@ -108,7 +108,7 @@ int FAST_FUNC volume_id_probe_btrfs(struct volume_id *id /*,uint64_t off*/) // N.B.: btrfs natively supports 256 (>VOLUME_ID_LABEL_SIZE) size labels volume_id_set_label_string(id, sb->label, VOLUME_ID_LABEL_SIZE); volume_id_set_uuid(id, sb->fsid, UUID_DCE); - IF_FEATURE_BLKID_TYPE(id->type = "btrfs";) + id->type = "btrfs"; return 0; } diff --git a/util-linux/volume_id/cramfs.c b/util-linux/volume_id/cramfs.c index 3468a5005..d6f7572e8 100644 --- a/util-linux/volume_id/cramfs.c +++ b/util-linux/volume_id/cramfs.c @@ -57,7 +57,7 @@ int FAST_FUNC volume_id_probe_cramfs(struct volume_id *id /*,uint64_t off*/) volume_id_set_label_string(id, cs->name, 16); // volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); - IF_FEATURE_BLKID_TYPE(id->type = "cramfs";) + id->type = "cramfs"; return 0; } diff --git a/util-linux/volume_id/erofs.c b/util-linux/volume_id/erofs.c index a163a353d..3688dc4d5 100644 --- a/util-linux/volume_id/erofs.c +++ b/util-linux/volume_id/erofs.c @@ -56,7 +56,7 @@ int FAST_FUNC volume_id_probe_erofs(struct volume_id *id /*,uint64_t off*/) if (sb->magic != cpu_to_le32(EROFS_SUPER_MAGIC_V1)) return -1; - IF_FEATURE_BLKID_TYPE(id->type = "erofs"); + id->type = "erofs"; volume_id_set_label_string(id, sb->volume_name, MIN(sizeof(sb->volume_name), VOLUME_ID_LABEL_SIZE)); diff --git a/util-linux/volume_id/exfat.c b/util-linux/volume_id/exfat.c index 952b027d9..d90df60d9 100644 --- a/util-linux/volume_id/exfat.c +++ b/util-linux/volume_id/exfat.c @@ -135,6 +135,6 @@ int FAST_FUNC volume_id_probe_exfat(struct volume_id *id /*,uint64_t off*/) break; } - IF_FEATURE_BLKID_TYPE(id->type = "exfat";) + id->type = "exfat"; return 0; } diff --git a/util-linux/volume_id/ext.c b/util-linux/volume_id/ext.c index f17faddb6..be441b35f 100644 --- a/util-linux/volume_id/ext.c +++ b/util-linux/volume_id/ext.c @@ -51,7 +51,6 @@ int FAST_FUNC volume_id_probe_ext(struct volume_id *id /*,uint64_t off*/) volume_id_set_uuid(id, es->s_uuid, UUID_DCE); dbg("ext: label '%s' uuid '%s'", id->label, id->uuid); -#if ENABLE_FEATURE_BLKID_TYPE if ((es->s_feature_ro_compat & cpu_to_le32(EXT4_FEATURE_RO_COMPAT_HUGE_FILE | EXT4_FEATURE_RO_COMPAT_DIR_NLINK)) || (es->s_feature_incompat & cpu_to_le32(EXT4_FEATURE_INCOMPAT_EXTENTS | EXT4_FEATURE_INCOMPAT_64BIT)) ) { @@ -61,6 +60,6 @@ int FAST_FUNC volume_id_probe_ext(struct volume_id *id /*,uint64_t off*/) id->type = "ext3"; else id->type = "ext2"; -#endif + return 0; } diff --git a/util-linux/volume_id/f2fs.c b/util-linux/volume_id/f2fs.c index e6100aec2..dbce91815 100644 --- a/util-linux/volume_id/f2fs.c +++ b/util-linux/volume_id/f2fs.c @@ -77,7 +77,7 @@ int FAST_FUNC volume_id_probe_f2fs(struct volume_id *id /*,uint64_t off*/) if (sb->magic != cpu_to_le32(F2FS_MAGIC)) return -1; - IF_FEATURE_BLKID_TYPE(id->type = "f2fs"); + id->type = "f2fs"; // For version 1.0 we don't know sb structure and can't set label/uuid if (sb->major_ver == cpu_to_le16(1) && sb->minor_ver == cpu_to_le16(0)) diff --git a/util-linux/volume_id/fat.c b/util-linux/volume_id/fat.c index fe3750880..806d94f55 100644 --- a/util-linux/volume_id/fat.c +++ b/util-linux/volume_id/fat.c @@ -338,7 +338,7 @@ int FAST_FUNC volume_id_probe_vfat(struct volume_id *id /*,uint64_t fat_partitio ret: // volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); - IF_FEATURE_BLKID_TYPE(id->type = "vfat";) + id->type = "vfat"; return 0; } diff --git a/util-linux/volume_id/get_devname.c b/util-linux/volume_id/get_devname.c index 00cfb2826..9a5f6abce 100644 --- a/util-linux/volume_id/get_devname.c +++ b/util-linux/volume_id/get_devname.c @@ -25,16 +25,9 @@ static struct uuidCache_s { char *device; char *label; char *uc_uuid; /* prefix makes it easier to grep for */ - IF_FEATURE_BLKID_TYPE(const char *type;) + const char *type; } *uuidCache; -#if !ENABLE_FEATURE_BLKID_TYPE -#define get_label_uuid(fd, label, uuid, type) \ - get_label_uuid(fd, label, uuid) -#define uuidcache_addentry(device, label, uuid, type) \ - uuidcache_addentry(device, label, uuid) -#endif - /* Returns !0 on error. * Otherwise, returns malloc'ed strings for label and uuid * (and they can't be NULL, although they can be ""). @@ -55,19 +48,11 @@ get_label_uuid(int fd, char **label, char **uuid, const char **type) if (volume_id_probe_all(vid, /*0,*/ size) != 0) goto ret; - if (vid->label[0] != '\0' || vid->uuid[0] != '\0' -#if ENABLE_FEATURE_BLKID_TYPE - || vid->type != NULL -#endif - ) { + if (vid->label[0] != '\0' || vid->uuid[0] != '\0' || vid->type != NULL) { *label = xstrndup(vid->label, sizeof(vid->label)); *uuid = xstrndup(vid->uuid, sizeof(vid->uuid)); -#if ENABLE_FEATURE_BLKID_TYPE *type = vid->type; dbg("found label '%s', uuid '%s', type '%s'", *label, *uuid, *type); -#else - dbg("found label '%s', uuid '%s'", *label, *uuid); -#endif rv = 0; } ret: @@ -95,7 +80,7 @@ uuidcache_addentry(char *device, /*int major, int minor,*/ char *label, char *uu last->device = device; last->label = label; last->uc_uuid = uuid; - IF_FEATURE_BLKID_TYPE(last->type = type;) + last->type = type; } /* If get_label_uuid() on device_name returns success, @@ -240,10 +225,8 @@ void display_uuid_cache(int scan_devices) printf(" LABEL=\"%s\"", uc->label); if (uc->uc_uuid[0]) printf(" UUID=\"%s\"", uc->uc_uuid); -#if ENABLE_FEATURE_BLKID_TYPE - if (uc->type) - printf(" TYPE=\"%s\"", uc->type); -#endif + if (uc->type) + printf(" TYPE=\"%s\"", uc->type); bb_putchar('\n'); uc = uc->next; } @@ -253,9 +236,7 @@ int add_to_uuid_cache(const char *device) { char *uuid = uuid; /* for compiler */ char *label = label; -#if ENABLE_FEATURE_BLKID_TYPE const char *type = type; -#endif int fd; fd = open(device, O_RDONLY); diff --git a/util-linux/volume_id/hfs.c b/util-linux/volume_id/hfs.c index 05d16db34..16ef8c93e 100644 --- a/util-linux/volume_id/hfs.c +++ b/util-linux/volume_id/hfs.c @@ -222,7 +222,7 @@ int FAST_FUNC volume_id_probe_hfs_hfsplus(struct volume_id *id /*,uint64_t off*/ hfs_set_uuid(id, hfs->finder_info.id); // volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); - IF_FEATURE_BLKID_TYPE(id->type = "hfs";) + id->type = "hfs"; return 0; @@ -313,7 +313,7 @@ int FAST_FUNC volume_id_probe_hfs_hfsplus(struct volume_id *id /*,uint64_t off*/ found: // volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); - IF_FEATURE_BLKID_TYPE(id->type = "hfsplus";) + id->type = "hfsplus"; return 0; } diff --git a/util-linux/volume_id/iso9660.c b/util-linux/volume_id/iso9660.c index c771b01f5..f8e00b40d 100644 --- a/util-linux/volume_id/iso9660.c +++ b/util-linux/volume_id/iso9660.c @@ -120,7 +120,7 @@ int FAST_FUNC volume_id_probe_iso9660(struct volume_id *id /*,uint64_t off*/) found: // volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); - IF_FEATURE_BLKID_TYPE(id->type = "iso9660";) + id->type = "iso9660"; return 0; } diff --git a/util-linux/volume_id/jfs.c b/util-linux/volume_id/jfs.c index 5e523e236..902788dc5 100644 --- a/util-linux/volume_id/jfs.c +++ b/util-linux/volume_id/jfs.c @@ -60,7 +60,7 @@ int FAST_FUNC volume_id_probe_jfs(struct volume_id *id /*,uint64_t off*/) volume_id_set_uuid(id, js->uuid, UUID_DCE); // volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); - IF_FEATURE_BLKID_TYPE(id->type = "jfs";) + id->type = "jfs"; return 0; } diff --git a/util-linux/volume_id/lfs.c b/util-linux/volume_id/lfs.c index 1a2a2987f..396e78d0e 100644 --- a/util-linux/volume_id/lfs.c +++ b/util-linux/volume_id/lfs.c @@ -8,7 +8,7 @@ //config:config FEATURE_VOLUMEID_LFS //config: bool "LittleFS filesystem" //config: default y -//config: depends on VOLUMEID && FEATURE_BLKID_TYPE +//config: depends on VOLUMEID //config: help //config: LittleFS is a small fail-safe filesystem designed for embedded //config: systems. It has strong copy-on-write guarantees and storage on disk @@ -56,7 +56,7 @@ int FAST_FUNC volume_id_probe_lfs(struct volume_id *id /*,uint64_t off*/) if (memcmp(sb->magic, LFS_MAGIC_NAME, LFS_MAGIC_LEN) != 0) return -1; - IF_FEATURE_BLKID_TYPE(id->type = LFS_MAGIC_NAME); + id->type = LFS_MAGIC_NAME; return 0; } diff --git a/util-linux/volume_id/linux_raid.c b/util-linux/volume_id/linux_raid.c index db6209a4d..4d3df402e 100644 --- a/util-linux/volume_id/linux_raid.c +++ b/util-linux/volume_id/linux_raid.c @@ -81,7 +81,7 @@ int FAST_FUNC volume_id_probe_linux_raid(struct volume_id *id /*,uint64_t off*/, dbg("found raid signature"); // volume_id_set_usage(id, VOLUME_ID_RAID); - IF_FEATURE_BLKID_TYPE(id->type = "linux_raid_member";) + id->type = "linux_raid_member"; return 0; } diff --git a/util-linux/volume_id/linux_swap.c b/util-linux/volume_id/linux_swap.c index 78b339cf0..2496a096c 100644 --- a/util-linux/volume_id/linux_swap.c +++ b/util-linux/volume_id/linux_swap.c @@ -78,7 +78,7 @@ int FAST_FUNC volume_id_probe_linux_swap(struct volume_id *id /*,uint64_t off*/) found: // volume_id_set_usage(id, VOLUME_ID_OTHER); - IF_FEATURE_BLKID_TYPE(id->type = "swap";) + id->type = "swap"; return 0; } diff --git a/util-linux/volume_id/luks.c b/util-linux/volume_id/luks.c index 8e634d4ee..e40185d79 100644 --- a/util-linux/volume_id/luks.c +++ b/util-linux/volume_id/luks.c @@ -100,7 +100,7 @@ int FAST_FUNC volume_id_probe_luks(struct volume_id *id /*,uint64_t off*/) // volume_id_set_usage(id, VOLUME_ID_CRYPTO); volume_id_set_uuid(id, header->uuid, UUID_DCE_STRING); - IF_FEATURE_BLKID_TYPE(id->type = "crypto_LUKS";) + id->type = "crypto_LUKS"; return 0; } diff --git a/util-linux/volume_id/minix.c b/util-linux/volume_id/minix.c index c934f9ead..41c0f4df2 100644 --- a/util-linux/volume_id/minix.c +++ b/util-linux/volume_id/minix.c @@ -86,6 +86,6 @@ int FAST_FUNC volume_id_probe_minix(struct volume_id *id /*, uint64_t off*/) found: // volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); - IF_FEATURE_BLKID_TYPE(id->type = "minix";) + id->type = "minix"; return 0; } diff --git a/util-linux/volume_id/nilfs.c b/util-linux/volume_id/nilfs.c index 7a8b798df..a790c5102 100644 --- a/util-linux/volume_id/nilfs.c +++ b/util-linux/volume_id/nilfs.c @@ -107,7 +107,7 @@ int FAST_FUNC volume_id_probe_nilfs(struct volume_id *id /*,uint64_t off*/) volume_id_set_uuid(id, sb->s_uuid, UUID_DCE); if (sb->s_rev_level == 2) - IF_FEATURE_BLKID_TYPE(id->type = "nilfs2"); + id->type = "nilfs2"; return 0; } diff --git a/util-linux/volume_id/ntfs.c b/util-linux/volume_id/ntfs.c index 22dd77fc7..86c4746c8 100644 --- a/util-linux/volume_id/ntfs.c +++ b/util-linux/volume_id/ntfs.c @@ -194,7 +194,7 @@ int FAST_FUNC volume_id_probe_ntfs(struct volume_id *id /*,uint64_t off*/) found: // volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); - IF_FEATURE_BLKID_TYPE(id->type = "ntfs";) + id->type = "ntfs"; return 0; } diff --git a/util-linux/volume_id/ocfs2.c b/util-linux/volume_id/ocfs2.c index 235968b88..296485b6c 100644 --- a/util-linux/volume_id/ocfs2.c +++ b/util-linux/volume_id/ocfs2.c @@ -107,6 +107,6 @@ int FAST_FUNC volume_id_probe_ocfs2(struct volume_id *id /*,uint64_t off*/) volume_id_set_label_string(id, os->s_label, OCFS2_MAX_VOL_LABEL_LEN < VOLUME_ID_LABEL_SIZE ? OCFS2_MAX_VOL_LABEL_LEN : VOLUME_ID_LABEL_SIZE); volume_id_set_uuid(id, os->s_uuid, UUID_DCE); - IF_FEATURE_BLKID_TYPE(id->type = "ocfs2";) + id->type = "ocfs2"; return 0; } diff --git a/util-linux/volume_id/reiserfs.c b/util-linux/volume_id/reiserfs.c index d9fd8944d..24af88f3e 100644 --- a/util-linux/volume_id/reiserfs.c +++ b/util-linux/volume_id/reiserfs.c @@ -113,7 +113,7 @@ int FAST_FUNC volume_id_probe_reiserfs(struct volume_id *id /*,uint64_t off*/) found: // volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); - IF_FEATURE_BLKID_TYPE(id->type = "reiserfs";) + id->type = "reiserfs"; return 0; } diff --git a/util-linux/volume_id/romfs.c b/util-linux/volume_id/romfs.c index bd74fda8d..915af951f 100644 --- a/util-linux/volume_id/romfs.c +++ b/util-linux/volume_id/romfs.c @@ -53,7 +53,7 @@ int FAST_FUNC volume_id_probe_romfs(struct volume_id *id /*,uint64_t off*/) } // volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); - IF_FEATURE_BLKID_TYPE(id->type = "romfs";) + id->type = "romfs"; return 0; } diff --git a/util-linux/volume_id/squashfs.c b/util-linux/volume_id/squashfs.c index 4b65afd8b..a1fddcb69 100644 --- a/util-linux/volume_id/squashfs.c +++ b/util-linux/volume_id/squashfs.c @@ -8,7 +8,7 @@ //config:config FEATURE_VOLUMEID_SQUASHFS //config: bool "SquashFS filesystem" //config: default y -//config: depends on VOLUMEID && FEATURE_BLKID_TYPE +//config: depends on VOLUMEID //config: help //config: Squashfs is a compressed read-only filesystem for Linux. Squashfs is //config: intended for general read-only filesystem use and in constrained block @@ -50,7 +50,7 @@ int FAST_FUNC volume_id_probe_squashfs(struct volume_id *id /*,uint64_t off*/) || sb->magic == SIG3 || sb->magic == SIG4 ) { - IF_FEATURE_BLKID_TYPE(id->type = "squashfs";) + id->type = "squashfs"; return 0; } diff --git a/util-linux/volume_id/sysv.c b/util-linux/volume_id/sysv.c index be41f8048..2a069e228 100644 --- a/util-linux/volume_id/sysv.c +++ b/util-linux/volume_id/sysv.c @@ -105,7 +105,7 @@ int FAST_FUNC volume_id_probe_sysv(struct volume_id *id /*,uint64_t off*/) if (vs->s_magic == cpu_to_le32(SYSV_MAGIC) || vs->s_magic == cpu_to_be32(SYSV_MAGIC)) { // volume_id_set_label_raw(id, vs->s_fname, 6); volume_id_set_label_string(id, vs->s_fname, 6); - IF_FEATURE_BLKID_TYPE(id->type = "sysv"); + id->type = "sysv"; goto found; } } @@ -118,7 +118,7 @@ int FAST_FUNC volume_id_probe_sysv(struct volume_id *id /*,uint64_t off*/) if (xs->s_magic == cpu_to_le32(XENIX_MAGIC) || xs->s_magic == cpu_to_be32(XENIX_MAGIC)) { // volume_id_set_label_raw(id, xs->s_fname, 6); volume_id_set_label_string(id, xs->s_fname, 6); - IF_FEATURE_BLKID_TYPE(id->type = "xenix";) + id->type = "xenix"; goto found; } } diff --git a/util-linux/volume_id/ubifs.c b/util-linux/volume_id/ubifs.c index aee53f9dd..780d06bb9 100644 --- a/util-linux/volume_id/ubifs.c +++ b/util-linux/volume_id/ubifs.c @@ -115,7 +115,7 @@ int FAST_FUNC volume_id_probe_ubifs(struct volume_id *id /*,uint64_t off*/) if (le32_to_cpu(sb->ch.magic) != UBIFS_NODE_MAGIC) return -1; - IF_FEATURE_BLKID_TYPE(id->type = "ubifs";) + id->type = "ubifs"; volume_id_set_uuid(id, sb->uuid, UUID_DCE); return 0; diff --git a/util-linux/volume_id/udf.c b/util-linux/volume_id/udf.c index 0df4a86df..93f960351 100644 --- a/util-linux/volume_id/udf.c +++ b/util-linux/volume_id/udf.c @@ -173,6 +173,6 @@ anchor: found: // volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); - IF_FEATURE_BLKID_TYPE(id->type = "udf";) + id->type = "udf"; return 0; } diff --git a/util-linux/volume_id/volume_id_internal.h b/util-linux/volume_id/volume_id_internal.h index b1e44481f..cff9b882e 100644 --- a/util-linux/volume_id/volume_id_internal.h +++ b/util-linux/volume_id/volume_id_internal.h @@ -66,9 +66,7 @@ struct volume_id { uint8_t *sbbuf; uint8_t *seekbuf; uint64_t seekbuf_off; -#if ENABLE_FEATURE_BLKID_TYPE const char *type; -#endif #ifdef UNUSED_PARTITION_CODE struct volume_id_partition *partitions; size_t partition_count; diff --git a/util-linux/volume_id/xfs.c b/util-linux/volume_id/xfs.c index f98b66a53..092cae47b 100644 --- a/util-linux/volume_id/xfs.c +++ b/util-linux/volume_id/xfs.c @@ -60,7 +60,7 @@ int FAST_FUNC volume_id_probe_xfs(struct volume_id *id /*,uint64_t off*/) volume_id_set_uuid(id, xs->uuid, UUID_DCE); // volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); - IF_FEATURE_BLKID_TYPE(id->type = "xfs";) + id->type = "xfs"; return 0; } -- 2.34.1 From alex_y_xu at yahoo.ca Thu Nov 25 23:22:50 2021 From: alex_y_xu at yahoo.ca (Alex Xu (Hello71)) Date: Thu, 25 Nov 2021 18:22:50 -0500 Subject: [PATCH 2/2] mount: use volume_id for fstype detection In-Reply-To: <20211125232250.87522-1-alex_y_xu@yahoo.ca> References: <20211125232250.87522-1-alex_y_xu@yahoo.ca> Message-ID: <20211125232250.87522-2-alex_y_xu@yahoo.ca> This allows filesystems to be mounted even if the module is not currently loaded and the type is not listed in /etc/filesystems. This was semi-rejected back in 2005 on the basis that it would be impractical to add a database of all filesystem types into busybox, but that has since been added in the form of volume_id. The benefits of using volume_id instead of adding all filesystems to /etc/filesystems or listing modaliases are: 1. it is faster since it doesn't call mount (or worse, modprobe) N times for each filesystem 2. it doesn't require loading all filesystems into kernel memory 3. it doesn't require the distributor/sysadmin to maintain /etc/filesystems function old new delta resolve_mount_spec 107 266 +159 singlemount 1053 1150 +97 uuidcache_init 64 67 +3 swap_enable_disable 245 247 +2 findfs_main 82 84 +2 devices_scanned - 1 +1 mount_main 1275 1255 -20 get_devname_from_uuid 63 - -63 get_devname_from_label 68 - -68 ------------------------------------------------------------------------------ (add/remove: 1/2 grow/shrink: 5/1 up/down: 264/-151) Total: 113 bytes --- include/volume_id.h | 4 +- util-linux/findfs.c | 2 +- util-linux/mount.c | 54 ++++++++++++----------- util-linux/swaponoff.c | 4 +- util-linux/volume_id/get_devname.c | 69 +++++++++++++----------------- 5 files changed, 64 insertions(+), 69 deletions(-) diff --git a/include/volume_id.h b/include/volume_id.h index a83da899e..6e6d7aef9 100644 --- a/include/volume_id.h +++ b/include/volume_id.h @@ -18,8 +18,6 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -char *get_devname_from_label(const char *spec); -char *get_devname_from_uuid(const char *spec); void display_uuid_cache(int scan_devices); /* Returns: @@ -27,5 +25,5 @@ void display_uuid_cache(int scan_devices); * 1: UUID= or LABEL= prefix found. In this case, * *fsname is replaced if device with such UUID or LABEL is found */ -int resolve_mount_spec(char **fsname); +int resolve_mount_spec(char **fsname, char **fstype); int add_to_uuid_cache(const char *device); diff --git a/util-linux/findfs.c b/util-linux/findfs.c index f5621a1fa..3a5f442a9 100644 --- a/util-linux/findfs.c +++ b/util-linux/findfs.c @@ -46,7 +46,7 @@ int findfs_main(int argc UNUSED_PARAM, char **argv) } else { /* Otherwise, handle LABEL=xxx and UUID=xxx, * fail on anything else */ - if (!resolve_mount_spec(argv)) + if (!resolve_mount_spec(argv, NULL)) bb_show_usage(); } diff --git a/util-linux/mount.c b/util-linux/mount.c index 4e65b6b46..2a94ca759 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c @@ -55,8 +55,8 @@ //config: "sometype [-o opts] fs /mnt" if simple mount syscall fails. //config: The idea is to use such virtual filesystems in /etc/fstab. //config: -//config:config FEATURE_MOUNT_LABEL -//config: bool "Support specifying devices by label or UUID" +//config:config FEATURE_MOUNT_VOLUMEID +//config: bool "Support auto-detecting type and searching by label or UUID" //config: default y //config: depends on MOUNT //config: select VOLUMEID @@ -234,10 +234,10 @@ #include "libbb.h" #include "common_bufsiz.h" -#if ENABLE_FEATURE_MOUNT_LABEL +#if ENABLE_FEATURE_MOUNT_VOLUMEID # include "volume_id.h" #else -# define resolve_mount_spec(fsname) ((void)0) +# define resolve_mount_spec(fsname, fstype) ((void)0) #endif // Needed for nfs support only @@ -1972,7 +1972,7 @@ static int singlemount(struct mntent *mp, int ignore_busy) int loopfd = -1; int rc = -1; unsigned long vfsflags; - char *loopFile = NULL, *filteropts = NULL; + char *loopFile = NULL, *filteropts = NULL, *guess_type = NULL; llist_t *fl = NULL; struct stat st; @@ -2103,6 +2103,8 @@ static int singlemount(struct mntent *mp, int ignore_busy) } } + resolve_mount_spec(&mp->mnt_fsname, mp->mnt_type ? NULL : &guess_type); + // Look at the file. (Not found isn't a failure for remount, or for // a synthetic filesystem like proc or sysfs.) // (We use stat, not lstat, in order to allow @@ -2162,23 +2164,31 @@ static int singlemount(struct mntent *mp, int ignore_busy) mp->mnt_type = next + 1; } } else { - // Loop through filesystem types until mount succeeds - // or we run out - - // Initialize list of block backed filesystems. - // This has to be done here so that during "mount -a", - // mounts after /proc shows up can autodetect. - if (!fslist) { - fslist = get_block_backed_filesystems(); - if (ENABLE_FEATURE_CLEAN_UP && fslist) - atexit(delete_block_backed_filesystems); + // Try the guessed type if one is available + if (guess_type) { + mp->mnt_type = guess_type; + rc = mount_it_now(mp, vfsflags, filteropts); } - for (fl = fslist; fl; fl = fl->link) { - mp->mnt_type = fl->data; - rc = mount_it_now(mp, vfsflags, filteropts); - if (rc == 0) - break; + if (rc != 0) { + // Loop through filesystem types until mount succeeds + // or we run out + + // Initialize list of block backed filesystems. + // This has to be done here so that during "mount -a", + // mounts after /proc shows up can autodetect. + if (!fslist) { + fslist = get_block_backed_filesystems(); + if (ENABLE_FEATURE_CLEAN_UP && fslist) + atexit(delete_block_backed_filesystems); + } + + for (fl = fslist; fl; fl = fl->link) { + mp->mnt_type = fl->data; + rc = mount_it_now(mp, vfsflags, filteropts); + if (rc == 0) + break; + } } } @@ -2350,7 +2360,6 @@ int mount_main(int argc UNUSED_PARAM, char **argv) mtpair->mnt_dir = argv[1]; mtpair->mnt_type = fstype; mtpair->mnt_opts = cmdopts; - resolve_mount_spec(&mtpair->mnt_fsname); rc = singlemount(mtpair, /*ignore_busy:*/ 0); return rc; } @@ -2446,8 +2455,6 @@ int mount_main(int argc UNUSED_PARAM, char **argv) if (!match_opt(mtcur->mnt_opts, O_optmatch)) continue; - resolve_mount_spec(&mtcur->mnt_fsname); - // NFS mounts want this to be xrealloc-able mtcur->mnt_opts = xstrdup(mtcur->mnt_opts); @@ -2523,7 +2530,6 @@ int mount_main(int argc UNUSED_PARAM, char **argv) // ...mount the last thing we found mtcur->mnt_opts = xstrdup(mtcur->mnt_opts); append_mount_options(&(mtcur->mnt_opts), cmdopts); - resolve_mount_spec(&mtpair->mnt_fsname); rc = singlemount(mtcur, /*ignore_busy:*/ 0); if (ENABLE_FEATURE_CLEAN_UP) free(mtcur->mnt_opts); diff --git a/util-linux/swaponoff.c b/util-linux/swaponoff.c index e2ff4b5cc..540faa042 100644 --- a/util-linux/swaponoff.c +++ b/util-linux/swaponoff.c @@ -82,7 +82,7 @@ #if ENABLE_FEATURE_SWAPONOFF_LABEL # include "volume_id.h" #else -# define resolve_mount_spec(fsname) ((void)0) +# define resolve_mount_spec(fsname, fstype) ((void)0) #endif #ifndef MNTTYPE_SWAP @@ -151,7 +151,7 @@ static int swap_enable_disable(char *device) int err = 0; int quiet = 0; - resolve_mount_spec(&device); + resolve_mount_spec(&device, NULL); if (do_swapoff) { err = swapoff(device); diff --git a/util-linux/volume_id/get_devname.c b/util-linux/volume_id/get_devname.c index 9a5f6abce..007d2b737 100644 --- a/util-linux/volume_id/get_devname.c +++ b/util-linux/volume_id/get_devname.c @@ -28,6 +28,8 @@ static struct uuidCache_s { const char *type; } *uuidCache; +static unsigned char devices_scanned; + /* Returns !0 on error. * Otherwise, returns malloc'ed strings for label and uuid * (and they can't be NULL, although they can be ""). @@ -116,8 +118,6 @@ static struct uuidCache_s* uuidcache_init(int scan_devices) { dbg("DBG: uuidCache=%x, uuidCache"); - if (uuidCache) - return uuidCache; /* We were scanning /proc/partitions * and /proc/sys/dev/cdrom/info here. @@ -129,21 +129,22 @@ uuidcache_init(int scan_devices) * This is unacceptably complex. Let's just scan /dev. * (Maybe add scanning of /sys/block/XXX/dev for devices * somehow not having their /dev/XXX entries created?) */ - if (scan_devices) { + if (scan_devices && !devices_scanned) { recursive_action("/dev", ACTION_RECURSE, uuidcache_check_device, /* file_action */ NULL, /* dir_action */ NULL /* userData */ ); + devices_scanned = 1; } return uuidCache; } +#ifdef UNUSED #define UUID 1 #define VOL 2 -#ifdef UNUSED static char * get_spec_by_x(int n, const char *t, int *majorPtr, int *minorPtr) { @@ -254,49 +255,39 @@ int add_to_uuid_cache(const char *device) /* Used by mount and findfs */ - -char *get_devname_from_label(const char *spec) +int resolve_mount_spec(char **fsname, char **fstype) { - struct uuidCache_s *uc; + struct uuidCache_s *uc = NULL; + enum { NONE = 0, UUID, LABEL } nametype = + is_prefixed_with(*fsname, "UUID=") ? UUID : + is_prefixed_with(*fsname, "LABEL=") ? LABEL : + NONE; - uc = uuidcache_init(/*scan_devices:*/ 1); - while (uc) { - if (uc->label[0] && strcmp(spec, uc->label) == 0) { - return xstrdup(uc->device); - } - uc = uc->next; + if (nametype) { + uc = uuidcache_init(/*scan_devices:*/ 1); + } else if (fstype) { + uc = uuidcache_init(/*scan_devices:*/ 0); + add_to_uuid_cache(*fsname); } - return NULL; -} - -char *get_devname_from_uuid(const char *spec) -{ - struct uuidCache_s *uc; - - uc = uuidcache_init(/*scan_devices:*/ 1); - while (uc) { - /* case of hex numbers doesn't matter */ - if (strcasecmp(spec, uc->uc_uuid) == 0) { - return xstrdup(uc->device); + if (nametype || fstype) { + while (uc) { + if ((nametype == NONE && strcmp(*fsname, uc->device) == 0) || + (nametype == UUID && strcasecmp(*fsname + 5, uc->uc_uuid) == 0) || + (nametype == LABEL && uc->label[0] && strcmp(*fsname + 6, uc->label) == 0)) { + break; + } + uc = uc->next; } - uc = uc->next; } - return NULL; -} -int resolve_mount_spec(char **fsname) -{ - char *tmp = *fsname; + if (!uc) + return 0; - if (is_prefixed_with(*fsname, "UUID=")) - tmp = get_devname_from_uuid(*fsname + 5); - else if (is_prefixed_with(*fsname, "LABEL=")) - tmp = get_devname_from_label(*fsname + 6); + if (nametype) + *fsname = xstrdup(uc->device); - if (tmp == *fsname) - return 0; /* no UUID= or LABEL= prefix found */ + if (fstype) + *fstype = xstrdup(uc->type); - if (tmp) - *fsname = tmp; return 1; } -- 2.34.1 From peter at korsgaard.com Fri Nov 26 15:38:57 2021 From: peter at korsgaard.com (Peter Korsgaard) Date: Fri, 26 Nov 2021 16:38:57 +0100 Subject: [PATCH] libarchive/get_header_ar.c: fix extraction of archives from binutils in deterministic mode Message-ID: <20211126153857.23988-1-peter@korsgaard.com> 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. Signed-off-by: Peter Korsgaard --- 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)); -- 2.20.1 From rep.dot.nop at gmail.com Sat Nov 27 20:56:47 2021 From: rep.dot.nop at gmail.com (Bernhard Reutner-Fischer) Date: Sat, 27 Nov 2021 21:56:47 +0100 Subject: return type demotion remarks In-Reply-To: <20211127215003.4cbf1992@nbbrfq> References: <20211127215003.4cbf1992@nbbrfq> Message-ID: <20211127215647.0891bed9@nbbrfq> Hi! I'm attaching a color log of some spots that may benefit of using narrower return types; See "could return". It certainly misses still quite some cases as it currently works only per function and thus does not see return values flowing from calls in the function. Taking call's known return ranges into account would point at e.g. pack_lzop() which returns 1 always. I guess most if not all of the spots noting that "Maybe the function should be ?void?" are not that useful to mention, but i included them here anyway. In BusyBox we have alot of *_main and i currently only ignore main()s return value.. And JFYI i did only spot-check a few places, not all. Hope this is useful. cheers, -------------- next part -------------- A non-text attachment was scrubbed... Name: LOG-color.02.txt.gz Type: application/gzip Size: 31355 bytes Desc: not available URL: From aaro.koskinen at iki.fi Sun Nov 28 10:11:48 2021 From: aaro.koskinen at iki.fi (Aaro Koskinen) Date: Sun, 28 Nov 2021 12:11:48 +0200 Subject: [PATCH] find: implement -samefile Message-ID: <20211128101148.9715-1-aaro.koskinen@iki.fi> Implement -samefile. Signed-off-by: Aaro Koskinen --- findutils/find.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/findutils/find.c b/findutils/find.c index fdc5c152d..87fd5b9bc 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; -- 2.17.0 From David.Laight at ACULAB.COM Sun Nov 28 18:00:31 2021 From: David.Laight at ACULAB.COM (David Laight) Date: Sun, 28 Nov 2021 18:00:31 +0000 Subject: return type demotion remarks In-Reply-To: <20211127215647.0891bed9@nbbrfq> References: <20211127215003.4cbf1992@nbbrfq> <20211127215647.0891bed9@nbbrfq> Message-ID: From: Bernhard Reutner-Fischer > Sent: 27 November 2021 20:57 > > Hi! > > I'm attaching a color log of some spots that may benefit of using > narrower return types; See "could return". My mailer won't expand a .gz file ..... However making function arguments and return values smaller than a normal cpu register (long is probably better than int!) is likely to increase code size. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales) From David.Laight at ACULAB.COM Sun Nov 28 19:51:52 2021 From: David.Laight at ACULAB.COM (David Laight) Date: Sun, 28 Nov 2021 19:51:52 +0000 Subject: return type demotion remarks In-Reply-To: <20211128203649.637204f5@nbbrfq> References: <20211127215003.4cbf1992@nbbrfq> <20211127215647.0891bed9@nbbrfq> <20211128203649.637204f5@nbbrfq> Message-ID: <31ea4b1ae0cb4366bab174fa8f117edc@AcuMS.aculab.com> From: Bernhard Reutner-Fischer > Sent: 28 November 2021 19:37 > > On Sun, 28 Nov 2021 18:00:31 +0000 > David Laight wrote: > > > From: Bernhard Reutner-Fischer > > > Sent: 27 November 2021 20:57 > > > > > > Hi! > > > > > > I'm attaching a color log of some spots that may benefit of using > > > narrower return types; See "could return". > > > > My mailer won't expand a .gz file ..... > > yea, it was too big to send uncompressed, sorry for that. > > > > However making function arguments and return values smaller > > than a normal cpu register (long is probably better than int!) > > is likely to increase code size. > > Arches will promote types as they see fit anyway. The problem is that the values start needing to be masked to the smaller type, not that they get promoted. > I'm attaching something that i would _not_ apply since it was based off > the user-visible fix-it not taking into account the shifts needed in > the callers. > Lessons learned in this v0.0: > - iterate_on_dir callback should be void > - find ACTF could use a narrower type > - functors are a bit of a pain ;) > cheers, Try using outlook :-( It really only wants to execute attachments, not display them. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales) From peter+busybox at mutable.cc Sun Nov 28 21:06:23 2021 From: peter+busybox at mutable.cc (Peter Willis) Date: Sun, 28 Nov 2021 16:06:23 -0500 Subject: Patch to add support for RFC2324 (HTCPCP) Message-ID: <35b511aa-e3f1-492c-a6c5-2bbcfed364bb@www.fastmail.com> Hi busybox devs, It's been a long time! About 17 years since my last submission :-) I was just trying to make some coffee with busybox, and I noticed it doesn't support RFC 2324 (Hyper Text Coffee Pot Control Protocol). Attached is a patch that adds support for the standard. Although I should mention it's not full support for the standard; I take my coffee black, so I didn't implement WHEN and Accept-Additions, but I'm sure someone else can if they need creamer (although some Kahlua wouldn't go amiss with this winter weather...) The patch includes a configuration file option "T" that sets if the host is a teapot or not. The default is teapot mode, for portability (coffee brewing operations shouldn't happen on a teapot). Sample operation: $ echo "T:1" > cgi-bin/httpd.conf $ curl -d 'start' -H "Content-Type: application/coffee-pot-command" -X BREW http://localhost:6789/cgi-bin/coffeepot 418 I'm a teapot

418 I'm a teapot

The web server is a teapot $ echo "T:0" > cgi-bin/httpd.conf $ curl -d 'start' -H "Content-Type: application/coffee-pot-command" -X BREW http://localhost:6789/cgi-bin/coffeepot Brewing coffee! Also note that the patch fixes a Content-Length bug I found in send_headers(): The function always returns the Content-Length, which is always set to the length of a file (for example, if there was a request of a file, the file's size is taken - but then some error might be thrown after this point). After the Content-Length is set, if infoString was set (the text of a response code) the resulting HTML output's length bears no relation to the file size it previously set as the Content-Length. Therefore the Content-Length needs to be set to either the file size, or the length of the infoString HTML message. The patch includes a change to calculate the size of the infoString template and return that length if infoString was set. -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: HTCPCP.diff.gz Type: application/gzip Size: 2637 bytes Desc: not available URL: From explorer09 at gmail.com Mon Nov 29 05:44:51 2021 From: explorer09 at gmail.com (Kang-Che Sung) Date: Mon, 29 Nov 2021 13:44:51 +0800 Subject: Patch to add support for RFC2324 (HTCPCP) In-Reply-To: <35b511aa-e3f1-492c-a6c5-2bbcfed364bb@www.fastmail.com> References: <35b511aa-e3f1-492c-a6c5-2bbcfed364bb@www.fastmail.com> Message-ID: On Mon, Nov 29, 2021 at 5:16 AM Peter Willis wrote: > > Hi busybox devs, It's been a long time! About 17 years since my last submission :-) > > I was just trying to make some coffee with busybox, and I noticed it doesn't support RFC 2324 (Hyper Text Coffee Pot Control Protocol). Attached is a patch that adds support for the standard. Although I should mention it's not full support for the standard; I take my coffee black, so I didn't implement WHEN and Accept-Additions, but I'm sure someone else can if they need creamer (although some Kahlua wouldn't go amiss with this winter weather...) > > The patch includes a configuration file option "T" that sets if the host is a teapot or not. The default is teapot mode, for portability (coffee brewing operations shouldn't happen on a teapot). > > Sample operation: > > $ echo "T:1" > cgi-bin/httpd.conf > $ curl -d 'start' -H "Content-Type: application/coffee-pot-command" -X BREW http://localhost:6789/cgi-bin/coffeepot > 418 I'm a teapot >

418 I'm a teapot

> The web server is a teapot > > $ echo "T:0" > cgi-bin/httpd.conf > $ curl -d 'start' -H "Content-Type: application/coffee-pot-command" -X BREW http://localhost:6789/cgi-bin/coffeepot > Brewing coffee! > > Also note that the patch fixes a Content-Length bug I found in send_headers(): > > The function always returns the Content-Length, which is always set to the length of a file (for example, if there was a request of a file, the file's size is taken - but then some error might be thrown after this point). After the Content-Length is set, if infoString was set (the text of a response code) the resulting HTML output's length bears no relation to the file size it previously set as the Content-Length. Therefore the Content-Length needs to be set to either the file size, or the length of the infoString HTML message. The patch includes a change to calculate the size of the infoString template and return that length if infoString was set. Just wondering. Is this an out-of-season April Fools joke? (Sorry for quoting that guy at Blizzcon.) But I have a serious question here: I don't see the ".cup" file extension or the "vessel/cup" MIME type defined anywhere in the HTCPCP spec. Where are those keywords from?