From vda.linux at googlemail.com Sun Jul 3 19:41:38 2022 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Sun, 3 Jul 2022 21:41:38 +0200 Subject: [git commit] lineedit: get PWD from ash Message-ID: <20220703193118.ED87F81841@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=298ac9507bb6cb932162f863c7b9623c0a37dedb branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master The line editing code and ash disagree when the current directory is changed to a symbolic link: ~ $ mkdir real ~ $ ln -s real link ~ $ cd link ~/real $ pwd /home/rmyf36/link Note the prompt says we're in ~/real. Bash does: [rmy at random ~]$ cd link [rmy at random link]$ pwd /home/rmyf36/link Ash uses the name supplied by the user while the line editing code calls getcwd(3). The discrepancy can be avoided by fetching the value of PWD from ash. Hush calls getcwd(3) when the directory is changed so there's no disagreement with the line editing code. There is no standard how shells should handle cd'ing into symlinks. function old new delta parse_and_put_prompt 838 869 +31 Signed-off-by: Ron Yorston Signed-off-by: Denys Vlasenko --- libbb/lineedit.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libbb/lineedit.c b/libbb/lineedit.c index b685399f9..697f2a577 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -2035,7 +2035,13 @@ static void parse_and_put_prompt(const char *prmt_ptr) case 'W': /* basename of cur dir */ if (!cwd_buf) { const char *home; +#if ENABLE_SHELL_ASH + cwd_buf = state->sh_get_var + ? xstrdup(state->sh_get_var("PWD")) + : xrealloc_getcwd_or_warn(NULL); +#else cwd_buf = xrealloc_getcwd_or_warn(NULL); +#endif if (!cwd_buf) cwd_buf = (char *)bb_msg_unknown; else if ((home = get_homedir_or_NULL()) != NULL && home[0]) { From bugzilla at busybox.net Tue Jul 5 23:08:05 2022 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Tue, 05 Jul 2022 23:08:05 +0000 Subject: [Bug 14896] New: ash: Add ifsfree to varunset and varvalue function to fix a buffer over-read Message-ID: https://bugs.busybox.net/show_bug.cgi?id=14896 Bug ID: 14896 Summary: ash: Add ifsfree to varunset and varvalue function to fix a buffer over-read Product: Busybox Version: 1.35.x Hardware: All OS: Linux Status: NEW Severity: normal Priority: P5 Component: Other Assignee: unassigned at busybox.net Reporter: algore3698 at gmail.com CC: busybox-cvs at busybox.net Target Milestone: --- Due to a logic error in the ifsbreakup function in ash.c when a heredoc and normal command is run one after the other by means of a semi-colon, when the second command drops into ifsbreakup the command will be evaluated with the ifslastp/ifsfirst struct that was set when the heredoc was evaluated. This results in a buffer over-read that can leak the program's heap, stack, and arena addresses which can be used to beat ASLR. Steps to Reproduce: First bug: cmd args: ~/exampleDir/example> busybox ash $ M='AAAAAAAAAAAAAAAAA' $ q00(){ $ <<000;echo $ ${D?$M$M$M$M$M$M} $ 000 $ } $ q00 Patch: Adding the following to ash.c will fix the bug. ================================ --- a/shell/ash.c +++ b/shell/ash.c @@ -7030,6 +7030,7 @@ msg = umsg; } } +ifsfree(); ash_msg_and_raise_error("%.*s: %s%s", (int)(end - var - 1), var, msg, tail); } @@ -7445,6 +7446,7 @@ if (discard) return -1; +ifsfree(); raise_error_syntax("bad substitution"); } ================================ -- You are receiving this mail because: You are on the CC list for the bug. From bugzilla at busybox.net Fri Jul 8 19:19:32 2022 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Fri, 08 Jul 2022 19:19:32 +0000 Subject: [Bug 14811] networking/nslookup.c parse_reply() CVE-2022-28391 patch query In-Reply-To: References: Message-ID: https://bugs.busybox.net/show_bug.cgi?id=14811 --- Comment #1 from Mark Esler --- > Is BusyBox affected Appears so. The vulnerability was reproduced on arch: https://gitlab.alpinelinux.org/alpine/aports/-/issues/13661 -- You are receiving this mail because: You are on the CC list for the bug. From bugzilla at busybox.net Mon Jul 11 05:01:24 2022 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Mon, 11 Jul 2022 05:01:24 +0000 Subject: [Bug 14906] New: find -atime does not follow the actual atime Message-ID: https://bugs.busybox.net/show_bug.cgi?id=14906 Bug ID: 14906 Summary: find -atime does not follow the actual atime Product: Busybox Version: 1.35.x Hardware: PC OS: Linux Status: NEW Severity: normal Priority: P5 Component: Standard Compliance Assignee: unassigned at busybox.net Reporter: zhaoyitengfs at gmail.com CC: busybox-cvs at busybox.net Target Milestone: --- The integrated find -atime option does not follow the access time of the file. I believe it is still referencing the mtime from my testing. The GNU version (findutils) does not have this issue. Output: /test # find --help BusyBox v1.35.0 (2022-05-09 17:27:12 UTC) multi-call binary. Usage: find [-HL] [PATH]... [OPTIONS] [ACTIONS] ... /test # stat old File: old Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: 0,107 Inode: 692229 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2022-07-09 03:26:00.000000000 +0000 Modify: 2022-07-01 03:26:00.000000000 +0000 Change: 2022-07-11 03:36:15.549088648 +0000 Birth: - /test # date Mon Jul 11 03:36:27 UTC 2022 /test # find . -atime +1 ./old /test # find . -atime +3 ./old /test # find . -atime +10 /test # Expected: /test # find . -atime +1 ./old /test # find . -atime +3 /test # Environment: Alpine Linux 3.16.0 (Docker Image/Busybox v1.35.0) w/ Kernel 5.17.11 -- You are receiving this mail because: You are on the CC list for the bug. From vda.linux at googlemail.com Mon Jul 11 12:36:39 2022 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Mon, 11 Jul 2022 14:36:39 +0200 Subject: [git commit] shaNNNsum: accept one-space "HASH FILENAME" format for -c, closes 14866 Message-ID: <20220711122435.8E0E18367F@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=3ad3aa6441ebaf817137051de2b74cb6b4379e7f branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta md5_sha1_sum_main 496 501 +5 Signed-off-by: Denys Vlasenko --- coreutils/md5_sha1_sum.c | 13 ++++++++----- testsuite/sha1sum.tests | 10 ++++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/coreutils/md5_sha1_sum.c b/coreutils/md5_sha1_sum.c index 0e57673f1..b4bdc262c 100644 --- a/coreutils/md5_sha1_sum.c +++ b/coreutils/md5_sha1_sum.c @@ -301,9 +301,7 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv) count_total++; filename_ptr = strchr(line, ' '); - if (filename_ptr == NULL - || (filename_ptr[1] != ' ' && filename_ptr[1] != '*') - ) { + if (!filename_ptr) { if (flags & FLAG_WARN) { bb_simple_error_msg("invalid format"); } @@ -312,8 +310,13 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv) free(line); continue; } - *filename_ptr = '\0'; - filename_ptr += 2; + *filename_ptr++ = '\0'; + /* coreutils 9.1 allows "HASH FILENAME" format, + * with only one space. Skip the 'correct' + * " " or " *" delimiter if it is there: + */ + if (*filename_ptr == ' ' || *filename_ptr == '*') + filename_ptr++; hash_value = hash_file(in_buf, filename_ptr, sha3_width); diff --git a/testsuite/sha1sum.tests b/testsuite/sha1sum.tests index a968fa87c..7ad1334c3 100755 --- a/testsuite/sha1sum.tests +++ b/testsuite/sha1sum.tests @@ -1,3 +1,13 @@ #!/bin/sh +. ./testing.sh + +# testing "test name" "cmd" "expected result" "file input" "stdin" +>EMPTY +testing "sha1sum: one-space separated input for -c" \ + 'echo "da39a3ee5e6b4b0d3255bfef95601890afd80709 EMPTY" | sha1sum -c' \ + "EMPTY: OK\n" \ + "" "" +rm EMPTY + . ./md5sum.tests sha1sum d41337e834377140ae7f98460d71d908598ef04f From bugzilla at busybox.net Mon Jul 11 12:38:20 2022 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Mon, 11 Jul 2022 12:38:20 +0000 Subject: [Bug 14866] sha256sum reports false mismatch if input not delimited by two spaces In-Reply-To: References: Message-ID: https://bugs.busybox.net/show_bug.cgi?id=14866 --- Comment #3 from Denys Vlasenko --- Fixed in git -- You are receiving this mail because: You are on the CC list for the bug. From vda.linux at googlemail.com Mon Jul 11 15:18:07 2022 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Mon, 11 Jul 2022 17:18:07 +0200 Subject: [git commit] awk: fix use after free (CVE-2022-30065) Message-ID: <20220711152821.193BE83687@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=e63d7cdfdac78c6fd27e9e63150335767592b85e branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master fixes https://bugs.busybox.net/show_bug.cgi?id=14781 function old new delta evaluate 3343 3357 +14 Signed-off-by: Natanael Copa Signed-off-by: Denys Vlasenko --- editors/awk.c | 3 +++ testsuite/awk.tests | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/editors/awk.c b/editors/awk.c index 079d0bde5..728ee8685 100644 --- a/editors/awk.c +++ b/editors/awk.c @@ -3128,6 +3128,9 @@ static var *evaluate(node *op, var *res) case XC( OC_MOVE ): debug_printf_eval("MOVE\n"); + /* make sure that we never return a temp var */ + if (L.v == TMPVAR0) + L.v = res; /* if source is a temporary string, jusk relink it to dest */ if (R.v == TMPVAR1 && !(R.v->type & VF_NUMBER) diff --git a/testsuite/awk.tests b/testsuite/awk.tests index 93e25d8c1..bbf0fbff1 100755 --- a/testsuite/awk.tests +++ b/testsuite/awk.tests @@ -479,4 +479,10 @@ testing 'awk backslash+newline eaten with no trace' \ "Hello world\n" \ '' '' +testing 'awk assign while test' \ + "awk '\$1==\$1=\"foo\" {print \$1}'" \ + "foo\n" \ + "" \ + "foo" + exit $FAILCOUNT From bugzilla at busybox.net Mon Jul 11 23:30:06 2022 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Mon, 11 Jul 2022 23:30:06 +0000 Subject: [Bug 14781] A use-after-free in Busybox's awk applet leads to denial of service and possibly code execution when processing a crafted awk pattern in the copyvar function In-Reply-To: References: Message-ID: https://bugs.busybox.net/show_bug.cgi?id=14781 --- Comment #8 from Denys Vlasenko --- Fixed in git -- You are receiving this mail because: You are on the CC list for the bug. From bugzilla at busybox.net Mon Jul 11 23:30:17 2022 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Mon, 11 Jul 2022 23:30:17 +0000 Subject: [Bug 14781] A use-after-free in Busybox's awk applet leads to denial of service and possibly code execution when processing a crafted awk pattern in the copyvar function In-Reply-To: References: Message-ID: https://bugs.busybox.net/show_bug.cgi?id=14781 Denys Vlasenko changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution|--- |FIXED -- You are receiving this mail because: You are on the CC list for the bug. From vda.linux at googlemail.com Wed Jul 13 14:11:17 2022 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Wed, 13 Jul 2022 16:11:17 +0200 Subject: [git commit] tls: P256: remove NOP macro sp_256_norm_8() Message-ID: <20220713140224.5A1DD83894@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=7b969bb2ada4d7757229fd735135f7720ef8008c branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master Signed-off-by: Denys Vlasenko --- networking/tls_sp_c32.c | 35 +++++------------------------------ 1 file changed, 5 insertions(+), 30 deletions(-) diff --git a/networking/tls_sp_c32.c b/networking/tls_sp_c32.c index 292dda24e..a593c5c40 100644 --- a/networking/tls_sp_c32.c +++ b/networking/tls_sp_c32.c @@ -68,9 +68,6 @@ static const sp_digit p256_mod[8] ALIGNED(8) = { #define p256_mp_mod ((sp_digit)0x000001) -/* Normalize the values in each word to 32 bits - NOP */ -#define sp_256_norm_8(a) ((void)0) - /* Write r as big endian to byte array. * Fixed length number of bytes written: 32 * @@ -83,8 +80,6 @@ static void sp_256_to_bin_8(const sp_digit* rr, uint8_t* a) int i; const uint64_t* r = (void*)rr; - sp_256_norm_8(rr); - r += 4; for (i = 0; i < 4; i++) { r--; @@ -97,8 +92,6 @@ static void sp_256_to_bin_8(const sp_digit* r, uint8_t* a) { int i; - sp_256_norm_8(r); - r += 8; for (i = 0; i < 8; i++) { r--; @@ -641,7 +634,6 @@ static void sp_256_div2_8(sp_digit* r /*, const sp_digit* m*/) int carry = 0; if (r[0] & 1) carry = sp_256_add_8(r, r, m); - sp_256_norm_8(r); sp_256_rshift1_8(r, carry); } @@ -652,10 +644,8 @@ static void sp_256_mont_add_8(sp_digit* r, const sp_digit* a, const sp_digit* b // const sp_digit* m = p256_mod; int carry = sp_256_add_8(r, a, b); - sp_256_norm_8(r); if (carry) { sp_256_sub_8_p256_mod(r); - sp_256_norm_8(r); } } @@ -667,10 +657,8 @@ static void sp_256_mont_sub_8(sp_digit* r, const sp_digit* a, const sp_digit* b int borrow; borrow = sp_256_sub_8(r, a, b); - sp_256_norm_8(r); if (borrow) { sp_256_add_8(r, r, m); - sp_256_norm_8(r); } } @@ -680,10 +668,8 @@ static void sp_256_mont_dbl_8(sp_digit* r, const sp_digit* a /*, const sp_digit* // const sp_digit* m = p256_mod; int carry = sp_256_add_8(r, a, a); - sp_256_norm_8(r); if (carry) sp_256_sub_8_p256_mod(r); - sp_256_norm_8(r); } /* Triple a Montgomery form number (r = a + a + a % m) */ @@ -692,16 +678,12 @@ static void sp_256_mont_tpl_8(sp_digit* r, const sp_digit* a /*, const sp_digit* // const sp_digit* m = p256_mod; int carry = sp_256_add_8(r, a, a); - sp_256_norm_8(r); if (carry) { sp_256_sub_8_p256_mod(r); - sp_256_norm_8(r); } carry = sp_256_add_8(r, r, a); - sp_256_norm_8(r); if (carry) { sp_256_sub_8_p256_mod(r); - sp_256_norm_8(r); } } @@ -844,7 +826,6 @@ static void sp_512to256_mont_reduce_8(sp_digit* r, sp_digit* aa/*, const sp_digi sp_512to256_mont_shift_8(r, aa); if (carry != 0) sp_256_sub_8_p256_mod(r); - sp_256_norm_8(r); } #else /* Generic 32-bit version */ @@ -1003,8 +984,6 @@ static int sp_256_mul_add_8(sp_digit* r /*, const sp_digit* a, sp_digit b*/) * [In our case, it is (p256_mp_mod * a[1]) << 32.] * And so on. Eventually T is divisible by R, and after division by R * the algorithm is in the same place as the usual Montgomery reduction. - * - * TODO: Can conditionally use 64-bit (if bit-little-endian arch) logic? */ static void sp_512to256_mont_reduce_8(sp_digit* r, sp_digit* a/*, const sp_digit* m, sp_digit mp*/) { @@ -1032,7 +1011,6 @@ static void sp_512to256_mont_reduce_8(sp_digit* r, sp_digit* a/*, const sp_digit sp_512to256_mont_shift_8(r, a); if (word16th != 0) sp_256_sub_8_p256_mod(r); - sp_256_norm_8(r); } else { /* Same code for explicit mp == 1 (which is always the case for P256) */ sp_digit word16th = 0; @@ -1052,7 +1030,6 @@ static void sp_512to256_mont_reduce_8(sp_digit* r, sp_digit* a/*, const sp_digit sp_512to256_mont_shift_8(r, a); if (word16th != 0) sp_256_sub_8_p256_mod(r); - sp_256_norm_8(r); } } #endif @@ -1208,14 +1185,12 @@ static void sp_256_map_8(sp_point* r, sp_point* p) /* Reduce x to less than modulus */ if (sp_256_cmp_8(r->x, p256_mod) >= 0) sp_256_sub_8_p256_mod(r->x); - sp_256_norm_8(r->x); /* y /= z^3 */ sp_256_mont_mul_and_reduce_8(r->y, p->y, t1 /*, p256_mod, p256_mp_mod*/); /* Reduce y to less than modulus */ if (sp_256_cmp_8(r->y, p256_mod) >= 0) sp_256_sub_8_p256_mod(r->y); - sp_256_norm_8(r->y); memset(r->z, 0, sizeof(r->z)); r->z[0] = 1; @@ -1300,7 +1275,6 @@ static NOINLINE void sp_256_proj_point_add_8(sp_point* r, sp_point* p, sp_point* /* Check double */ sp_256_sub_8(t1, p256_mod, q->y); - sp_256_norm_8(t1); if (sp_256_cmp_equal_8(p->x, q->x) && sp_256_cmp_equal_8(p->z, q->z) && (sp_256_cmp_equal_8(p->y, q->y) || sp_256_cmp_equal_8(p->y, t1)) @@ -1422,14 +1396,15 @@ static void sp_256_ecc_mulmod_8(sp_point* r, const sp_point* g, const sp_digit* static void sp_256_ecc_mulmod_base_8(sp_point* r, sp_digit* k /*, int map*/) { /* Since this function is called only once, save space: - * don't have "static const sp_point p256_base = {...}", - * it would have more zeros than data. + * don't have "static const sp_point p256_base = {...}". */ static const uint8_t p256_base_bin[] = { /* x (big-endian) */ - 0x6b,0x17,0xd1,0xf2,0xe1,0x2c,0x42,0x47,0xf8,0xbc,0xe6,0xe5,0x63,0xa4,0x40,0xf2,0x77,0x03,0x7d,0x81,0x2d,0xeb,0x33,0xa0,0xf4,0xa1,0x39,0x45,0xd8,0x98,0xc2,0x96, + 0x6b,0x17,0xd1,0xf2,0xe1,0x2c,0x42,0x47,0xf8,0xbc,0xe6,0xe5,0x63,0xa4,0x40,0xf2, + 0x77,0x03,0x7d,0x81,0x2d,0xeb,0x33,0xa0,0xf4,0xa1,0x39,0x45,0xd8,0x98,0xc2,0x96, /* y */ - 0x4f,0xe3,0x42,0xe2,0xfe,0x1a,0x7f,0x9b,0x8e,0xe7,0xeb,0x4a,0x7c,0x0f,0x9e,0x16,0x2b,0xce,0x33,0x57,0x6b,0x31,0x5e,0xce,0xcb,0xb6,0x40,0x68,0x37,0xbf,0x51,0xf5, + 0x4f,0xe3,0x42,0xe2,0xfe,0x1a,0x7f,0x9b,0x8e,0xe7,0xeb,0x4a,0x7c,0x0f,0x9e,0x16, + 0x2b,0xce,0x33,0x57,0x6b,0x31,0x5e,0xce,0xcb,0xb6,0x40,0x68,0x37,0xbf,0x51,0xf5, /* z will be set to 1, infinity flag to "false" */ }; sp_point p256_base; From vda.linux at googlemail.com Wed Jul 13 14:15:04 2022 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Wed, 13 Jul 2022 16:15:04 +0200 Subject: [git commit] udhcpc6: add missed big-endian conversions Message-ID: <20220713140224.64D2A8389D@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=9b6eb2a8ef4f1cfeeea821e270d49ef9c6ae4503 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta option_to_env 686 694 +8 Signed-off-by: Denys Vlasenko --- networking/udhcp/d6_dhcpc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c index 9fc690315..d4cdd0c3a 100644 --- a/networking/udhcp/d6_dhcpc.c +++ b/networking/udhcp/d6_dhcpc.c @@ -295,6 +295,7 @@ static void option_to_env(const uint8_t *option, const uint8_t *option_end) *new_env() = xasprintf("ipv6=%s", ipv6str); move_from_unaligned32(v32, option + 4 + 16 + 4); + v32 = ntohl(v32); *new_env() = xasprintf("lease=%u", (unsigned)v32); break; @@ -332,6 +333,7 @@ static void option_to_env(const uint8_t *option, const uint8_t *option_end) * +-+-+-+-+-+-+-+-+ */ move_from_unaligned32(v32, option + 4 + 4); + v32 = ntohl(v32); *new_env() = xasprintf("ipv6prefix_lease=%u", (unsigned)v32); sprint_nip6(ipv6str, option + 4 + 4 + 4 + 1); From bugzilla at busybox.net Sat Jul 16 14:51:00 2022 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Sat, 16 Jul 2022 14:51:00 +0000 Subject: [Bug 14896] ash: Add ifsfree to varunset and varvalue function to fix a buffer over-read In-Reply-To: References: Message-ID: https://bugs.busybox.net/show_bug.cgi?id=14896 --- Comment #1 from algore3698 at gmail.com --- Hello, Has any progress been made on this? -- You are receiving this mail because: You are on the CC list for the bug. From bugzilla at busybox.net Fri Jul 29 02:24:00 2022 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Fri, 29 Jul 2022 02:24:00 +0000 Subject: [Bug 14781] A use-after-free in Busybox's awk applet leads to denial of service and possibly code execution when processing a crafted awk pattern in the copyvar function In-Reply-To: References: Message-ID: https://bugs.busybox.net/show_bug.cgi?id=14781 --- Comment #9 from xiechengliang --- Does the vulnerability affect versions 1.32.1 and 1.34.1? -- You are receiving this mail because: You are on the CC list for the bug. From vda.linux at googlemail.com Fri Jul 29 14:05:50 2022 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Fri, 29 Jul 2022 16:05:50 +0200 Subject: [git commit] sort: fix -k2M (wasn't skipping leading whitespace) Message-ID: <20220729135304.2A7C0868F6@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=00f2a35b835c6f49617f5379073e9063e7e683ce branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta compare_keys 848 862 +14 Signed-off-by: Denys Vlasenko --- coreutils/sort.c | 4 ++-- testsuite/sort.tests | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/coreutils/sort.c b/coreutils/sort.c index 9aac656fe..80b578fc2 100644 --- a/coreutils/sort.c +++ b/coreutils/sort.c @@ -357,9 +357,9 @@ static int compare_keys(const void *xarg, const void *yarg) int dx; char *xx, *yy; - xx = strptime(x, "%b", &thyme); + xx = strptime(skip_whitespace(x), "%b", &thyme); dx = thyme.tm_mon; - yy = strptime(y, "%b", &thyme); + yy = strptime(skip_whitespace(y), "%b", &thyme); if (!xx) retval = (!yy) ? 0 : -1; else if (!yy) diff --git a/testsuite/sort.tests b/testsuite/sort.tests index ff33e21b4..fb2cc91bd 100755 --- a/testsuite/sort.tests +++ b/testsuite/sort.tests @@ -219,4 +219,15 @@ testing "sort -h" \ # testing "description" "command(s)" "result" "infile" "stdin" +testing "sort -k2,2M" \ +"sort -k2,2M input" "\ +3 March +2 April +1 May +" "\ +2 April +1 May +3 March +" "" + exit $FAILCOUNT From vda.linux at googlemail.com Fri Jul 29 14:40:00 2022 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Fri, 29 Jul 2022 16:40:00 +0200 Subject: [git commit] sort: fix sort -s -u, closes 14871 Message-ID: <20220729142637.3FED586900@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=5479c435fde32e720af5e177e95d6364a422885a branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta sort_main 851 856 +5 Signed-off-by: Denys Vlasenko --- coreutils/sort.c | 9 +++++---- testsuite/sort.tests | 10 ++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/coreutils/sort.c b/coreutils/sort.c index 80b578fc2..01b7c44e5 100644 --- a/coreutils/sort.c +++ b/coreutils/sort.c @@ -652,11 +652,12 @@ int sort_main(int argc UNUSED_PARAM, char **argv) /* Handle -u */ if (option_mask32 & FLAG_u) { int j = 0; - /* coreutils 6.3 drop lines for which only key is the same - * -- disabling last-resort compare, or else compare_keys() - * will be the same only for completely identical lines. + /* coreutils 6.3 drop lines for which only key is the same: + * - disabling last-resort compare, or else compare_keys() + * will be the same only for completely identical lines + * - disabling -s (same reasons) */ - option_mask32 |= FLAG_no_tie_break; + option_mask32 = (option_mask32 | FLAG_no_tie_break) & (~FLAG_s); for (i = 1; i < linecount; i++) { if (compare_keys(&lines[j], &lines[i]) == 0) free(lines[i]); diff --git a/testsuite/sort.tests b/testsuite/sort.tests index fb2cc91bd..8dbadbdae 100755 --- a/testsuite/sort.tests +++ b/testsuite/sort.tests @@ -230,4 +230,14 @@ testing "sort -k2,2M" \ 3 March " "" +testing "sort -s -u" \ +"sort -s -u -k 2 input" "\ +z a +z b +" "\ +z b +a b +z a +a a" "" + exit $FAILCOUNT From bugzilla at busybox.net Fri Jul 29 14:40:29 2022 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Fri, 29 Jul 2022 14:40:29 +0000 Subject: [Bug 14871] sort: `sort -s -u -k 2' didn't remove duplicate lines In-Reply-To: References: Message-ID: https://bugs.busybox.net/show_bug.cgi?id=14871 Denys Vlasenko changed: What |Removed |Added ---------------------------------------------------------------------------- Resolution|--- |FIXED Status|NEW |RESOLVED --- Comment #2 from Denys Vlasenko --- Fixed in git -- You are receiving this mail because: You are on the CC list for the bug.