From bugzilla at busybox.net Sat May 6 12:48:49 2023 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Sat, 06 May 2023 12:48:49 +0000 Subject: [Bug 15556] New: The compiled busybox runs the date command in the docker container, but the time zone cannot be loaded Message-ID: https://bugs.busybox.net/show_bug.cgi?id=15556 Bug ID: 15556 Summary: The compiled busybox runs the date command in the docker container, but the time zone cannot be loaded Product: Busybox Version: 1.30.x Hardware: All OS: Linux Status: NEW Severity: normal Priority: P5 Component: Standard Compliance Assignee: unassigned at busybox.net Reporter: devops.linus at gmail.com CC: busybox-cvs at busybox.net Target Milestone: --- orignal busybox /bin # date Sat May 6 20:47:48 CST 2023 compiled busybox /bin # /bin/busybox3 date Sat May 6 12:47:53 UTC 2023 -- You are receiving this mail because: You are on the CC list for the bug. From vda.linux at googlemail.com Sun May 7 16:35:22 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Sun, 7 May 2023 18:35:22 +0200 Subject: [git commit] nmeter: improve %T fractionals display Message-ID: <20230507163546.816D385FDB@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=c6058d221a44718d086e067b08b070bdce16a7ef branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta nmeter_main 751 786 +35 Signed-off-by: Denys Vlasenko --- procps/nmeter.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/procps/nmeter.c b/procps/nmeter.c index e52c868df..4197174ba 100644 --- a/procps/nmeter.c +++ b/procps/nmeter.c @@ -985,6 +985,15 @@ int nmeter_main(int argc UNUSED_PARAM, char **argv) xgettimeofday(&G.start); G.tv = G.start; + + // Move back start of monotonic time a bit, to syncronize fractionals of %T and %t: + // nmeter -d500 '%6T %6t' + // 00:00:00.000161 12:32:07.500161 + // 00:00:00.500282 12:32:08.000282 + // 00:00:01.000286 12:32:08.500286 + if (G.delta > 0) + G.start.tv_usec -= (G.start.tv_usec % (unsigned)G.delta); + while (1) { collect_info(first); put_c(G.final_char); @@ -999,6 +1008,15 @@ int nmeter_main(int argc UNUSED_PARAM, char **argv) int rem; // can be commented out, will sacrifice sleep time precision a bit xgettimeofday(&G.tv); + + // TODO: nmeter -d10000 '%6T %6t' + // 00:00:00.770333 12:34:44.770333 + // 00:00:06.000088 12:34:50.000088 + // 00:00:16.000094 12:35:00.000094 + // 00:00:26.000275 12:35:10.000275 + // we can't syncronize interval to start close to 10 seconds for both + // %T and %t (as shown above), but what if there is only %T + // in format string? Maybe sync _it_ instead of %t in this case? if (need_seconds) rem = G.delta - ((ullong)G.tv.tv_sec*1000000 + G.tv.tv_usec) % G.deltanz; else From vda.linux at googlemail.com Sun May 7 16:44:03 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Sun, 7 May 2023 18:44:03 +0200 Subject: [git commit] readlink: code shrink Message-ID: <20230507164439.DA5FD85FE7@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=07f8b6feac2ff80793394b5b5acff5cd149d7fb2 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta readlink_main 111 103 -8 Signed-off-by: Denys Vlasenko --- coreutils/readlink.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/coreutils/readlink.c b/coreutils/readlink.c index 0a9aa957e..e17fc3b1e 100644 --- a/coreutils/readlink.c +++ b/coreutils/readlink.c @@ -68,12 +68,11 @@ int readlink_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int readlink_main(int argc UNUSED_PARAM, char **argv) { char *buf; - char *fname; unsigned opt; + /* -n must use bit 0 (see printf below) */ opt = getopt32(argv, "^" "n" IF_FEATURE_READLINK_FOLLOW("fvsq") "\0" "=1"); - fname = argv[optind]; /* compat: coreutils readlink reports errors silently via exit code */ if (!(opt & 4)) /* not -v */ @@ -81,14 +80,14 @@ int readlink_main(int argc UNUSED_PARAM, char **argv) /* NOFORK: only one alloc is allowed; must free */ if (opt & 2) { /* -f */ - buf = xmalloc_realpath_coreutils(fname); + buf = xmalloc_realpath_coreutils(argv[optind]); } else { - buf = xmalloc_readlink_or_warn(fname); + buf = xmalloc_readlink_or_warn(argv[optind]); } if (!buf) return EXIT_FAILURE; - printf((opt & 1) ? "%s" : "%s\n", buf); + printf("%s%s", buf, &"\n"[opt & 1]); free(buf); fflush_stdout_and_exit_SUCCESS(); From vda.linux at googlemail.com Sun May 7 16:57:06 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Sun, 7 May 2023 18:57:06 +0200 Subject: [git commit] build system: Make it possible to build with 64bit time_t Message-ID: <20230507165721.437E785FFB@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=40fa8eb998e27529fcd59830eb163b43658f9e81 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master On most 32bit architectures time_t (and a few other time related types) are a signed 32bit wide integer type. As a consequence they can only represent dates between Fri Dec 13 08:45:52 PM UTC 1901 (-0x80000000 seconds before Jan 1 1970) and Tue Jan 19 03:14:07 AM UTC 2038 (0x7fffffff seconds after Jan 1 1970). Given that some machines that are built today have an expected lifetime of >15 years, this needs to be extended. To to that, define the cpp symbol _TIME_BITS to 64 which results in some magic in glibc to make time_t (and the few other time related types) 64 bit wide. This new switch CONFIG_TIME64 is in the spirit of CONFIG_LFS and only expected to have the expected effect with glibc. On musl for examples time_t already defaults to 64bit wide types. Signed-off-by: Uwe Kleine-K??nig Signed-off-by: Denys Vlasenko --- Config.in | 10 ++++++++++ Makefile.flags | 1 + 2 files changed, 11 insertions(+) diff --git a/Config.in b/Config.in index a98a8b15b..214eba546 100644 --- a/Config.in +++ b/Config.in @@ -108,6 +108,16 @@ config LFS programs that can benefit from large file support include dd, gzip, cp, mount, tar. +config TIME64 + bool "Support 64bit wide time types" + default y + depends on LFS + help + Make times later than 2038 representable for several libc syscalls + (stat, clk_gettime etc.). Note this switch is specific to glibc and has + no effect on platforms that already use 64bit wide time types (i.e. all + 64bit archs and some selected 32bit archs (currently riscv and x32)). + config PAM bool "Support PAM (Pluggable Authentication Modules)" default n diff --git a/Makefile.flags b/Makefile.flags index 1cec5ba20..e4cd658fd 100644 --- a/Makefile.flags +++ b/Makefile.flags @@ -15,6 +15,7 @@ CPPFLAGS += \ -include include/autoconf.h \ -D_GNU_SOURCE -DNDEBUG \ $(if $(CONFIG_LFS),-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64) \ + $(if $(CONFIG_TIME64),-D_TIME_BITS=64) \ -DBB_VER=$(squote)$(quote)$(BB_VER)$(quote)$(squote) CFLAGS += $(call cc-option,-Wall,) From vda.linux at googlemail.com Mon May 8 10:27:50 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Mon, 8 May 2023 12:27:50 +0200 Subject: [git commit] hush: fix an interactive abort on error Message-ID: <20230508103016.5829E860F6@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=3c8e540eb7b7cd3d60d55bb195e26537f83eb836 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta parse_and_run_stream 140 155 +15 Signed-off-by: Denys Vlasenko --- shell/hush.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/shell/hush.c b/shell/hush.c index f8951d084..ac8e44778 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -7589,6 +7589,14 @@ static void parse_and_run_stream(struct in_str *inp, int end_trigger) } /* Force prompt */ inp->p = NULL; + /* Clear "peeked" EOF. Without this, + * $ { cmd } + * > ^D + * hush: syntax error: unterminated { + * exits interactive shell: + */ + if (inp->peek_buf[0] == EOF) + inp->peek_buf[0] = 0; /* This stream isn't empty */ empty = 0; continue; From vda.linux at googlemail.com Mon May 8 10:31:34 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Mon, 8 May 2023 12:31:34 +0200 Subject: [git commit] build system: fix "Config.in:117 error: Overlong line" Message-ID: <20230508103149.7B99C86107@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=465f05a4209b07e8a90bc80249d63e8ee07091da branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master Signed-off-by: Denys Vlasenko --- Config.in | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Config.in b/Config.in index 214eba546..ad0cd1e26 100644 --- a/Config.in +++ b/Config.in @@ -114,9 +114,10 @@ config TIME64 depends on LFS help Make times later than 2038 representable for several libc syscalls - (stat, clk_gettime etc.). Note this switch is specific to glibc and has - no effect on platforms that already use 64bit wide time types (i.e. all - 64bit archs and some selected 32bit archs (currently riscv and x32)). + (stat, clk_gettime etc.). Note this switch is specific to glibc + and has no effect on platforms that already use 64bit wide time types + (i.e. all 64bit archs and some selected 32bit archs (currently riscv + and x32)). config PAM bool "Support PAM (Pluggable Authentication Modules)" From vda.linux at googlemail.com Tue May 9 12:02:06 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Tue, 9 May 2023 14:02:06 +0200 Subject: [git commit] hush: add comment about abort on syntax error %{^} Message-ID: <20230509120233.42B2685F2B@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=3a7f00eadcf400df5f9381b49f3ff5e882af0261 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master Signed-off-by: Denys Vlasenko --- shell/hush.c | 1 + 1 file changed, 1 insertion(+) diff --git a/shell/hush.c b/shell/hush.c index ac8e44778..810dafd35 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -1429,6 +1429,7 @@ static void syntax_error_unterm_str(unsigned lineno UNUSED_PARAM, const char *s) { bb_error_msg("syntax error: unterminated %s", s); //? source4.tests fails: in bash, echo ${^} in script does not terminate the script +// (but bash --posix, or if bash is run as "sh", does terminate in script, so maybe uncomment this?) // die_if_script(); } From bugzilla at busybox.net Tue May 9 14:22:31 2023 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Tue, 09 May 2023 14:22:31 +0000 Subject: [Bug 15236] [1.36] SIGILL on accessing sha256 on some CPUs In-Reply-To: References: Message-ID: https://bugs.busybox.net/show_bug.cgi?id=15236 --- Comment #4 from Jens Maus --- In one of my projects we recently stumbled for this issue (sha256sum running in Illegal instruction) as well and this project is using buildroot/busybox with latest busybox 1.36. See here for the related bugreport on github: https://github.com/jens-maus/RaspberryMatic/issues/2309 Too me this ready like this might be the exact same thing and even thought only affects very rarely some users with some CPU/setup types, I do feel this might be related as well. Any chance to get this patch merged if it really solves this issue? -- You are receiving this mail because: You are on the CC list for the bug. From vda.linux at googlemail.com Tue May 9 17:32:29 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Tue, 9 May 2023 19:32:29 +0200 Subject: [git commit] nslookup: code shrink Message-ID: <20230509173255.779BB85FF2@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=dc84002a8256feb1cc7f0fb70bdbfc998deeba4a branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta send_queries 725 723 -2 nslookup_main 822 820 -2 add_query 89 86 -3 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-7) Total: -7 bytes Signed-off-by: Denys Vlasenko --- networking/nslookup.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/networking/nslookup.c b/networking/nslookup.c index 24eae4010..249083e24 100644 --- a/networking/nslookup.c +++ b/networking/nslookup.c @@ -589,6 +589,7 @@ static int RESOLVFUNC res_mkquery(int op, const char *dname, int class, int type if (l>253 || buflen15u || class>255u || type>255u) return -1; +//TODO: why do we even have the q[] array? Use buf[] directly! /* Construct query template - ID will be filled later */ memset(q, 0, n); q[2] = op*8 + 1; @@ -637,7 +638,12 @@ struct query { unsigned qlen; // unsigned latency; // uint8_t rcode; - unsigned char query[512]; + /* res_mkquery() balks on names > 253 chars. + * The formed query is 253+18 chars at max. + * Real hostnames are nowhere near that long anyway. + * Use of power-of-2 size means smaller code. + */ + unsigned char query[512 - sizeof(int) - sizeof(char*)]; // unsigned char reply[512]; }; From vda.linux at googlemail.com Tue May 9 17:21:45 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Tue, 9 May 2023 19:21:45 +0200 Subject: [git commit] nslookup: ensure unique transaction IDs for the DNS queries Message-ID: <20230509173255.6E76985FC0@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=62775ec4b34bd2a1b5e4c60aa40ba67bd979069a branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master Based on patch by Uwe Kleine-K??nig. It makes sense to actually see the nitty-gritty details of DNS querying, so bringing in (commented-out) musl's DNS request code. function old new delta nslookup_main 760 822 +62 Signed-off-by: Denys Vlasenko --- networking/nslookup.c | 394 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 390 insertions(+), 4 deletions(-) diff --git a/networking/nslookup.c b/networking/nslookup.c index 6da97baf4..24eae4010 100644 --- a/networking/nslookup.c +++ b/networking/nslookup.c @@ -34,16 +34,14 @@ //usage: "Name: debian\n" //usage: "Address: 127.0.0.1\n" +#if !ENABLE_FEATURE_NSLOOKUP_BIG + #include -#include /* for IFNAMSIZ */ //#include //#include #include "libbb.h" #include "common_bufsiz.h" - -#if !ENABLE_FEATURE_NSLOOKUP_BIG - /* * Mini nslookup implementation for busybox * @@ -248,12 +246,385 @@ int nslookup_main(int argc, char **argv) * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include "libbb.h" +#include "common_bufsiz.h" + #if 0 # define dbg(...) fprintf(stderr, __VA_ARGS__) #else # define dbg(...) ((void)0) #endif +/* Instead of using ancient libc DNS query support, + * we can carry our own, independent code. + * E.g. res_mkquery() loses + * three of its paramemters (they are unused!). + * Unfortunately, while it does eliminate + * ns_get16 + * ns_get32 + * ns_name_uncompress + * dn_skipname + * ns_skiprr + * ns_initparse + * ns_parserr + * libc functions from a static binary, libc versions of + * dn_expand and res_mkquery are still linked in + * - they are used by getnameinfo(). Each is ~230 bytes of code. + * This makes USE_LIBC_RESOLV = 0 code _bigger_ (by about 27 bytes), + * despite inlining and constant propagation. + */ +#define USE_LIBC_RESOLV 1 + +#if USE_LIBC_RESOLV + +#include + +#else + +#define RESOLVFUNC /*nothing*/ +#define BIGRESOLVFUNC /*nothing*/ +#define TINYRESOLVFUNC ALWAYS_INLINE + +/* This one is taken from musl 1.2.4 */ + +#define NS_MAXDNAME 1025 +#define NS_INT32SZ 4 +#define NS_INT16SZ 2 + +#define MAXDNAME NS_MAXDNAME + +typedef enum __ns_opcode { + ns_o_query = 0, +} ns_opcode; +typedef enum __ns_class { + ns_c_in = 1, +} ns_class; +typedef enum __ns_sect { + ns_s_qd = 0, + ns_s_zn = 0, + ns_s_an = 1, + ns_s_pr = 1, + ns_s_ns = 2, + ns_s_ud = 2, + ns_s_ar = 3, + ns_s_max = 4 +} ns_sect; +typedef enum __ns_type { + ns_t_a = 1, + ns_t_ns = 2, + ns_t_cname = 5, + ns_t_soa = 6, + ns_t_ptr = 12, + ns_t_mx = 15, + ns_t_txt = 16, + ns_t_aaaa = 28, + ns_t_srv = 33, + ns_t_any = 255, +} ns_type; +#define QUERY ns_o_query +#define T_A ns_t_a +#define T_PTR ns_t_ptr +#define T_AAAA ns_t_aaaa +#define C_IN ns_c_in + +typedef struct __ns_msg { + const unsigned char *_msg, *_eom; + uint16_t _id, _flags, _counts[ns_s_max]; + const unsigned char *_sections[ns_s_max]; + ns_sect _sect; + int _rrnum; + const unsigned char *_msg_ptr; +} ns_msg; +#define ns_msg_id(handle) ((handle)._id + 0) +#define ns_msg_base(handle) ((handle)._msg + 0) +#define ns_msg_end(handle) ((handle)._eom + 0) +#define ns_msg_size(handle) ((handle)._eom - (handle)._msg) +#define ns_msg_count(handle, section) ((handle)._counts[section] + 0) +#define ns_msg_getflag(handle, flag) \ + (((handle)._flags & _ns_flagdata[flag].mask) >> _ns_flagdata[flag].shift) + +typedef struct __ns_rr { + char name[NS_MAXDNAME]; + uint16_t type; + uint16_t rr_class; + uint32_t ttl; + uint16_t rdlength; + const unsigned char *rdata; +} ns_rr; +#define ns_rr_name(rr) (((rr).name[0] != '\0') ? (rr).name : ".") +#define ns_rr_type(rr) ((ns_type)((rr).type + 0)) +#define ns_rr_class(rr) ((ns_class)((rr).rr_class + 0)) +#define ns_rr_ttl(rr) ((rr).ttl + 0) +#define ns_rr_rdlen(rr) ((rr).rdlength + 0) +#define ns_rr_rdata(rr) ((rr).rdata + 0) + +typedef struct { + unsigned id :16; +#if __BYTE_ORDER == __BIG_ENDIAN + unsigned qr: 1; + unsigned opcode: 4; + unsigned aa: 1; + unsigned tc: 1; + unsigned rd: 1; + unsigned ra: 1; + unsigned unused :1; + unsigned ad: 1; + unsigned cd: 1; + unsigned rcode :4; +#else + unsigned rd :1; + unsigned tc :1; + unsigned aa :1; + unsigned opcode :4; + unsigned qr :1; + unsigned rcode :4; + unsigned cd: 1; + unsigned ad: 1; + unsigned unused :1; + unsigned ra :1; +#endif + unsigned qdcount :16; + unsigned ancount :16; + unsigned nscount :16; + unsigned arcount :16; +} HEADER; + +#define dn_ns_get16 bb_ns_get16 +static unsigned TINYRESOLVFUNC ns_get16(const unsigned char *cp) +{ + return cp[0]<<8 | cp[1]; +} +#define ns_get32 bb_ns_get32 +static unsigned long TINYRESOLVFUNC ns_get32(const unsigned char *cp) +{ + return (unsigned)cp[0]<<24 | cp[1]<<16 | cp[2]<<8 | cp[3]; +} +#define NS_GET16(s, cp) (void)((s) = ns_get16(((cp)+=2)-2)) +#define NS_GET32(l, cp) (void)((l) = ns_get32(((cp)+=4)-4)) + +#define dn_expand bb_dn_expand +static int BIGRESOLVFUNC dn_expand(const unsigned char *base, const unsigned char *end, const unsigned char *src, char *dest, int space) +{ + const unsigned char *p = src; + char *dend, *dbegin = dest; + int len = -1, i, j; + if (p==end || space <= 0) return -1; + dend = dest + (space > 254 ? 254 : space); + /* detect reference loop using an iteration counter */ + for (i=0; i < end-base; i+=2) { + /* loop invariants: p= end-base) return -1; + p = base+j; + } else if (*p) { + if (dest != dbegin) *dest++ = '.'; + j = *p++; + if (j >= end-p || j >= dend-dest) return -1; + while (j--) *dest++ = *p++; + } else { + *dest = 0; + if (len < 0) len = p+1-src; + return len; + } + } + return -1; +} + +#define ns_name_uncompress bb_ns_name_uncompress +static int RESOLVFUNC ns_name_uncompress(const unsigned char *msg, const unsigned char *eom, + const unsigned char *src, char *dst, size_t dstsiz) +{ + int r; + r = dn_expand(msg, eom, src, dst, dstsiz); + if (r < 0) errno = EMSGSIZE; + return r; +} + +#define dn_skipname bb_dn_skipname +static int RESOLVFUNC dn_skipname(const unsigned char *s, const unsigned char *end) +{ + const unsigned char *p = s; + while (p < end) + if (!*p) return p-s+1; + else if (*p>=192) + if (p+1 eom - p) goto bad; + p += r + 2 * NS_INT16SZ; + if (section != ns_s_qd) { + if (NS_INT32SZ + NS_INT16SZ > eom - p) goto bad; + p += NS_INT32SZ; + NS_GET16(r, p); + if (r > eom - p) goto bad; + p += r; + } + } + return p - ptr; +bad: + errno = EMSGSIZE; + return -1; +} + +#define ns_parserr bb_ns_parserr +static int BIGRESOLVFUNC ns_parserr(ns_msg *handle, ns_sect section, int rrnum, ns_rr *rr) +{ + int r; + + if (section < 0 || section >= ns_s_max) goto bad; + if (section != handle->_sect) { + handle->_sect = section; + handle->_rrnum = 0; + handle->_msg_ptr = handle->_sections[section]; + } + if (rrnum == -1) rrnum = handle->_rrnum; + if (rrnum < 0 || rrnum >= handle->_counts[section]) goto bad; + if (rrnum < handle->_rrnum) { + handle->_rrnum = 0; + handle->_msg_ptr = handle->_sections[section]; + } + if (rrnum > handle->_rrnum) { + r = ns_skiprr(handle->_msg_ptr, handle->_eom, section, rrnum - handle->_rrnum); + if (r < 0) return -1; + handle->_msg_ptr += r; + handle->_rrnum = rrnum; + } + r = ns_name_uncompress(handle->_msg, handle->_eom, handle->_msg_ptr, rr->name, NS_MAXDNAME); + if (r < 0) return -1; + handle->_msg_ptr += r; + if (2 * NS_INT16SZ > handle->_eom - handle->_msg_ptr) goto size; + NS_GET16(rr->type, handle->_msg_ptr); + NS_GET16(rr->rr_class, handle->_msg_ptr); + if (section != ns_s_qd) { + if (NS_INT32SZ + NS_INT16SZ > handle->_eom - handle->_msg_ptr) goto size; + NS_GET32(rr->ttl, handle->_msg_ptr); + NS_GET16(rr->rdlength, handle->_msg_ptr); + if (rr->rdlength > handle->_eom - handle->_msg_ptr) goto size; + rr->rdata = handle->_msg_ptr; + handle->_msg_ptr += rr->rdlength; + } else { + rr->ttl = 0; + rr->rdlength = 0; + rr->rdata = NULL; + } + handle->_rrnum++; + if (handle->_rrnum > handle->_counts[section]) { + handle->_sect = section + 1; + if (handle->_sect == ns_s_max) { + handle->_rrnum = -1; + handle->_msg_ptr = NULL; + } else { + handle->_rrnum = 0; + } + } + return 0; +bad: + errno = ENODEV; + return -1; +size: + errno = EMSGSIZE; + return -1; +} + +#define ns_initparse bb_ns_initparse +static int BIGRESOLVFUNC ns_initparse(const unsigned char *msg, int msglen, ns_msg *handle) +{ + int i, r; + + handle->_msg = msg; + handle->_eom = msg + msglen; + if (msglen < (2 + ns_s_max) * NS_INT16SZ) goto bad; + NS_GET16(handle->_id, msg); + NS_GET16(handle->_flags, msg); + for (i = 0; i < ns_s_max; i++) NS_GET16(handle->_counts[i], msg); + for (i = 0; i < ns_s_max; i++) { + if (handle->_counts[i]) { + handle->_sections[i] = msg; + r = ns_skiprr(msg, handle->_eom, i, handle->_counts[i]); + if (r < 0) return -1; + msg += r; + } else { + handle->_sections[i] = NULL; + } + } + if (msg != handle->_eom) goto bad; + handle->_sect = ns_s_max; + handle->_rrnum = -1; + handle->_msg_ptr = NULL; + return 0; +bad: + errno = EMSGSIZE; + return -1; +} + +#define res_mkquery bb_res_mkquery +static int RESOLVFUNC res_mkquery(int op, const char *dname, int class, int type, + const unsigned char *data UNUSED_PARAM, int datalen UNUSED_PARAM, + const unsigned char *newrr UNUSED_PARAM, unsigned char *buf, int buflen) +{ + int i, j; + unsigned char q[280]; + size_t l = strnlen(dname, 255); + int n; + + if (l && dname[l-1]=='.') l--; + if (l && dname[l-1]=='.') return -1; + n = 17+l+!!l; + if (l>253 || buflen15u || class>255u || type>255u) + return -1; + + /* Construct query template - ID will be filled later */ + memset(q, 0, n); + q[2] = op*8 + 1; + q[3] = 32; /* AD */ + q[5] = 1; + memcpy((char *)q+13, dname, l); + for (i=13; q[i]; i=j+1) { + for (j=i; q[j] && q[j] != '.'; j++); + if (j-i-1u > 62u) return -1; + q[i-1] = j-i; + } + q[i+1] = type; + q[i+3] = class; +#if 0 +//For some machines (here: a TP-Link RE200 powered by a MediaTek MT7620A) +//the monotonic clock has a coarse resolution (here: 20us) and it can happen +//that the requests for A and AAAA share the same transaction ID. + +//In that case the mapping from received responses to the sent queries +//doesn't work and name resolution fails because the AAAA reply +//is dropped as a duplicate reply to the A query. + /* Make a reasonably unpredictable id */ + unsigned id; + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + id = ts.tv_nsec + ((uint32_t)(ts.tv_nsec) >> 16); + q[0] = id/256; + q[1] = id; +#endif + memcpy(buf, q, n); + return n; +} + +#endif /* !USE_LIBC_RESOLV */ + + struct ns { const char *name; len_and_sockaddr *lsa; @@ -978,6 +1349,21 @@ int nslookup_main(int argc UNUSED_PARAM, char **argv) } } + /* Ensure the Transaction IDs are unique. + * See, for example, musl source of res_mkquery() where + * it risks using current time (same value!) for ALL queries. + */ + { + struct timeval tv; + unsigned id; + xgettimeofday(&tv); + id = tv.tv_sec + tv.tv_usec; + for (rc = 0; rc < G.query_count; rc++) { + G.query[rc].query[0] = id >> 8; + G.query[rc].query[1] = id++; + } + } + for (rc = 0; rc < G.serv_count;) { int c; From vda.linux at googlemail.com Tue May 9 18:35:16 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Tue, 9 May 2023 20:35:16 +0200 Subject: [git commit] cpio: tweak --help Message-ID: <20230509183532.BE5B28600C@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=2f663a6f7d4264ddffc33f857b24d6a4e1e1bc61 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master Signed-off-by: Denys Vlasenko --- archival/cpio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archival/cpio.c b/archival/cpio.c index 839a15621..f0d990048 100644 --- a/archival/cpio.c +++ b/archival/cpio.c @@ -62,7 +62,7 @@ //usage: " [-ti"IF_FEATURE_CPIO_O("o")"]" IF_FEATURE_CPIO_P(" [-p DIR]") //usage: " [EXTR_FILE]..." //usage:#define cpio_full_usage "\n\n" -//usage: "Extract (-i) or list (-t) files from a cpio archive" +//usage: "Extract (-i) or list (-t) files from a cpio archive on stdin" //usage: IF_FEATURE_CPIO_O(", or" //usage: "\ntake file list from stdin and create an archive (-o)" //usage: IF_FEATURE_CPIO_P(" or copy files (-p)") From bugzilla at busybox.net Fri May 12 15:14:06 2023 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Fri, 12 May 2023 15:14:06 +0000 Subject: [Bug 15481] /bin/sh does not work when invoked with argv[0] different from "sh" In-Reply-To: References: Message-ID: https://bugs.busybox.net/show_bug.cgi?id=15481 --- Comment #2 from Eric Blake --- Compliance-wise, it looks like POSIX intends to relax things, so that as long as libc invokes the sh fallback with argv[0] of "sh" (or maybe "/bin/sh"), that is acceptable. Thus, it is no longer as urgent that busybox consider installing a shim that performs shell functionality regardless of argv[0] contents. https://austingroupbugs.net/view.php?id=1645#c6281 -- You are receiving this mail because: You are on the CC list for the bug. From bugzilla at busybox.net Mon May 15 17:01:40 2023 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Mon, 15 May 2023 17:01:40 +0000 Subject: [Bug 15561] New: klogd fail to restart successfully across hardware reboots. Message-ID: https://bugs.busybox.net/show_bug.cgi?id=15561 Bug ID: 15561 Summary: klogd fail to restart successfully across hardware reboots. Product: Busybox Version: 1.35.x Hardware: All OS: Linux Status: NEW Severity: normal Priority: P5 Component: Other Assignee: unassigned at busybox.net Reporter: koteswararao18 at gmail.com CC: busybox-cvs at busybox.net Target Milestone: --- Hi, i am redirecting kernel log (dmesg) to /var/log/dmesg/kern.log by defining below rule in /etc/syslog.conf in linux. {{ kern.* /var/log/dmesg/kern.log }} I am using Busybox-1.35 version specific syslogd and klogd to redirect dmesg log to above kern.log file. In Linux x86-64 machine, once device is upgraded with firmware and after rebooting, observed dmesg log is copied to kern.log successfully as klogd and syslogd daemons are launched sucessfully during boot phase. {{ May 15 09:11:37 kern.notice kernel: klogd started: BusyBox v1.35.0 (2023-01-18 02:16:44 UTC) ... May 15 09:34:41 syslog.info syslogd started: BusyBox v1.35.0 }} But if i reboot machine intentionally and then, i noticed klogd is not launched at all , so dmesg log is not copied to kern.log file. Where as syslogd is launched successfully across reboots and klogd is not at all launched even after many attempts. 5.4 is the kernel version running on linux machine. Surprising why klogd is not launched at all from second reboot onwards. any input for further debugging on the issue? Regards Koti -- You are receiving this mail because: You are on the CC list for the bug. From bugzilla at busybox.net Mon May 15 20:48:47 2023 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Mon, 15 May 2023 20:48:47 +0000 Subject: [Bug 15561] klogd fail to restart successfully across hardware reboots. In-Reply-To: References: Message-ID: https://bugs.busybox.net/show_bug.cgi?id=15561 --- Comment #1 from Peter Korsgaard --- Some more details would be good, E.G. how do you start klogd, does it print out any error messages when it fails to start? You talk about a firmware upgrade, but it is unclear to me what the relation is between that and your klogd issue? -- You are receiving this mail because: You are on the CC list for the bug. From bugzilla at busybox.net Tue May 16 07:13:30 2023 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Tue, 16 May 2023 07:13:30 +0000 Subject: [Bug 15561] klogd fail to restart successfully across hardware reboots. In-Reply-To: References: Message-ID: https://bugs.busybox.net/show_bug.cgi?id=15561 --- Comment #2 from koti --- Hi, thank you for your reply. >>how do you start klogd, does it print out any error messages when it fails to >>start? i didn't see any error message in the log. seems i need to enable loglevel to see klog failure if it emit it or not. meanwhile, as i mentioned earlier, once booting is done, i didn't see "klogd start" message which indicates klogd is started successfully but in the 'ps ' list i noticed klogd process is alive. {{ /# ps | grep klogd 5500 root 3916 S /bin/klogd -n }} i launched /bin/klogd at shell prompt as given below and klogd is launched successfully. {{ /# /bin/klogd -n (In one shell, this command is launched, and it's waiting indefinitely) }} in another shell, i just checked if klogd is started successfully or not? it's started successfully. {{ # cat /var/log/dmesg/kern.log | grep klogd .. May 15 23:49:53 kern.notice kernel: klogd started: BusyBox v1.35.0 (2023-05-12 04:41:16 UTC) /# ps | grep klogd 5500 root 3916 S /bin/klogd -n 26327 root 3916 S /bin/klogd -n 26449 root 3916 S grep klogd /# >From process list, observed klogd -n generates new PID 26327. does it mean klogd is not exited properly during shutdown is leading to failure in starting it successfully? }} >>firmware upgrade, but it is unclear to me what the relation is between that >>and your klogd issue Firwmare upgrade means, x86-64 target machine is flashed with image i.e built on local ubuntu machine. Once it's flashed with new image, all services will be started for first time and as part of it, klogd also launched for first time successfully. But during second reboot, klogd seems not exited properly, so launching it again fails after reboot is done? Regards Koti -- You are receiving this mail because: You are on the CC list for the bug. From bugzilla at busybox.net Tue May 16 14:32:55 2023 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Tue, 16 May 2023 14:32:55 +0000 Subject: [Bug 15561] klogd fail to restart successfully across hardware reboots. In-Reply-To: References: Message-ID: https://bugs.busybox.net/show_bug.cgi?id=15561 --- Comment #3 from Peter Korsgaard --- The "klogd start" message presumably comes from an init script or similar, so if you don't see that, please verify/debug the script. You don't mention if this is a completely custom setup with init scripts written by you or if you use something existing like Buildroot to provide the start/stop logic? Maybe the easiest way forward is to not startup anything though scripts but instead run syslogd and klogd manually, possibly through strace to see what is happening. -- You are receiving this mail because: You are on the CC list for the bug. From vda.linux at googlemail.com Thu May 18 11:30:10 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Thu, 18 May 2023 13:30:10 +0200 Subject: [git commit] examples/var_service/README: fix an error Message-ID: <20230518113029.55B7A867CA@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=c5682813abb2f24a7ab026c905af73eea58cb621 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master Signed-off-by: Denys Vlasenko --- examples/var_service/README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/var_service/README b/examples/var_service/README index 15a1bc9d2..02d987515 100644 --- a/examples/var_service/README +++ b/examples/var_service/README @@ -43,7 +43,7 @@ directory, running one child runsv process for the service in each subdirectory. A typical choice is to start an instance of runsvdir which supervises services in subdirectories of /var/service/. -If /var/service/log/ exists, runsv will supervise two services, +If /var/service/SERVICE_DIR/log/ exists, runsv will supervise two services, and will connect stdout of main service to the stdin of log service. This is primarily used for logging. From vda.linux at googlemail.com Thu May 18 14:49:54 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Thu, 18 May 2023 16:49:54 +0200 Subject: [git commit] ash: use-after-free in bash pattern substitution Message-ID: <20230518145003.938BF867F1@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=3e83699ce23400d75c7ddaa7ebfdec015177caa7 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master Commit daa66ed6 fixed a number of use-after-free bugs in bash pattern substitution, however one "unguarded" STPUTC remained, which is fixed here. function old new delta subevalvar 1564 1576 +12 Signed-off-by: Karsten Sperling Signed-off-by: Denys Vlasenko --- shell/ash.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/shell/ash.c b/shell/ash.c index d2c5c5d50..51b627fcc 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -7370,6 +7370,8 @@ subevalvar(char *start, char *str, int strloc, char *restart_detect = stackblock(); if (quotes && *loc == '\\') { STPUTC(CTLESC, expdest); + if (stackblock() != restart_detect) + goto restart; len++; } STPUTC(*loc, expdest); From bugzilla at busybox.net Thu May 18 22:11:22 2023 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Thu, 18 May 2023 22:11:22 +0000 Subject: [Bug 15236] [1.36] SIGILL on accessing sha256 on some CPUs In-Reply-To: References: Message-ID: https://bugs.busybox.net/show_bug.cgi?id=15236 Denys Vlasenko changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution|--- |FIXED --- Comment #5 from Denys Vlasenko --- In your patch: - shaNI = ((ebx >> 29) << 1) - 1; + shaNI = ((ebx >> 29) & 1); This will set shaNI to 0 if bit is not set, instead of -1. Which will make sha1_begin/sha256_begin check it again on every single call. CPUID insn takes something like 300 cycles. Fixed in git. https://git.busybox.net/busybox/commit/?id=bd76b75f72f717150b909e8c64edfda725cabe11 - shaNI = ((ebx >> 29) << 1) - 1; + shaNI = ((ebx >> 28) & 2) - 1; /* bit 29 -> 1 or -1 */ Will be released in June. -- You are receiving this mail because: You are on the CC list for the bug. From vda.linux at googlemail.com Thu May 18 22:44:44 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Fri, 19 May 2023 00:44:44 +0200 Subject: [git commit] Announce 1.36.1 Message-ID: <20230518224511.E2281867FF@busybox.osuosl.org> commit: https://git.busybox.net/busybox-website/commit/?id=587d27d39fe5b81846cc2d1ac36e9529ba8ccaf2 branch: https://git.busybox.net/busybox-website/commit/?id=refs/heads/master Signed-off-by: Denys Vlasenko --- news.html | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/news.html b/news.html index 282f2d6..5693bb2 100644 --- a/news.html +++ b/news.html @@ -17,6 +17,19 @@

+
  • 19 May 2023 -- BusyBox 1.36.1 (stable) +

    BusyBox 1.36.1. + (git)

    + +

    Bug fix release. 1.36.1 has fixes for + line editing, + detection of hardware sha1/sha256 support, + unzip (do not create suid/sgid files unless -K), + shell (printf and sleep with no args, handing of SIGINT in sleep), + ed. +

    +
  • +
  • 3 January 2023 -- BusyBox 1.36.0 (unstable)

    BusyBox 1.36.0. (git, From bugzilla at busybox.net Fri May 19 09:12:37 2023 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Fri, 19 May 2023 09:12:37 +0000 Subject: [Bug 15571] New: hush will bypass commands after the first one in elif Message-ID: https://bugs.busybox.net/show_bug.cgi?id=15571 Bug ID: 15571 Summary: hush will bypass commands after the first one in elif Product: Busybox Version: unspecified Hardware: All OS: All Status: NEW Severity: normal Priority: P5 Component: Other Assignee: unassigned at busybox.net Reporter: vsfos at qq.com CC: busybox-cvs at busybox.net Target Milestone: --- Created attachment 9591 --> https://bugs.busybox.net/attachment.cgi?id=9591&action=edit patch to fix the bug, but need more test Busybox is at the top of the git repo. Tested on WSL ubuntu and orangepi linux by running the test script with command line: busybox hush test the test script: #!/bin/sh if false; then : nothing elif echo 'test-1'; echo 'test-2' ; echo 'test-3'; then echo "abcdefg-1" fi echo again if echo 'test-1'; echo 'test-2' ; echo 'test-3'; then echo "abcdefg-1" fi Output of the test script on hush: # ./busybox hush test test-1 again test-1 test-2 test-3 abcdefg-1 Output of the test script on bash: #bash test test-1 test-2 test-3 abcdefg-1 again test-1 test-2 test-3 abcdefg-1 -- You are receiving this mail because: You are on the CC list for the bug. From bugzilla at busybox.net Fri May 19 20:56:09 2023 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Fri, 19 May 2023 20:56:09 +0000 Subject: [Bug 15571] hush will bypass commands after the first one in elif In-Reply-To: References: Message-ID: https://bugs.busybox.net/show_bug.cgi?id=15571 --- Comment #1 from SimonQian --- The attached patch is wrong. -- You are receiving this mail because: You are on the CC list for the bug. From bugzilla at busybox.net Tue May 23 14:14:46 2023 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Tue, 23 May 2023 14:14:46 +0000 Subject: [Bug 15596] New: 1.36.1 tag and version bump commit missing in git Message-ID: https://bugs.busybox.net/show_bug.cgi?id=15596 Bug ID: 15596 Summary: 1.36.1 tag and version bump commit missing in git Product: Busybox Version: unspecified Hardware: All OS: All Status: NEW Severity: trivial Priority: P5 Component: Other Assignee: unassigned at busybox.net Reporter: osm0sis at outlook.com CC: busybox-cvs at busybox.net Target Milestone: --- I see that's the only difference when comparing the source blob to the git, but my build system operates on git using the latest tag, as I'm sure many do, so I just wanted to make you aware it was missed. Thanks! 1.36.x is also missing in Bugzilla's Version list. -- You are receiving this mail because: You are on the CC list for the bug. From bugzilla at busybox.net Tue May 23 23:21:09 2023 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Tue, 23 May 2023 23:21:09 +0000 Subject: [Bug 13716] Broken Android NDK x86 builds with TLS due to triggered ASM code In-Reply-To: References: Message-ID: https://bugs.busybox.net/show_bug.cgi?id=13716 Chris Renshaw changed: What |Removed |Added ---------------------------------------------------------------------------- Resolution|--- |FIXED Status|REOPENED |RESOLVED --- Comment #11 from Chris Renshaw --- Resolved on latest NDK! -- You are receiving this mail because: You are on the CC list for the bug. From bugzilla at busybox.net Wed May 24 08:56:16 2023 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Wed, 24 May 2023 08:56:16 +0000 Subject: [Bug 15601] New: CVE-2021-42380 unrepaired or new issues introduced by fixing CVE-2021-42380. Message-ID: https://bugs.busybox.net/show_bug.cgi?id=15601 Bug ID: 15601 Summary: CVE-2021-42380 unrepaired or new issues introduced by fixing CVE-2021-42380. Product: Busybox Version: unspecified Hardware: All OS: Linux Status: NEW Severity: normal Priority: P5 Component: Standard Compliance Assignee: unassigned at busybox.net Reporter: magicgoogol at gmail.com CC: busybox-cvs at busybox.net Target Milestone: --- Created attachment 9601 --> https://bugs.busybox.net/attachment.cgi?id=9601&action=edit poc Discoverer: Taolaw at Vlab of Vecentek $ ./busybox_unstripped awk -f '/home/fuzz/vuln_search/poc/CVE-2021-42380' '/home/fuzz/vuln_search/poc/1.txt' ? process timing ?????????????????????????????????????? ? process timing ???????????????????? results ????????? overall results ????? days, 0 hrs, 0 min, 56 sec ? cycles done : 0 ? 0 min, 56 sec ? cycles done : 0 ? ? last new find ? last new find : 0 days, 0 hrs, 0 min, 1 sec ? corpus count : 208 0 days, 0 hrs, 0 min, 1 sec ? corpus count : 208 ? ?last saved crash : ?last saved crash : none seen yet ?saved crashes : 0 seen yet ?saved crashes : 0 ? ? last saved hang ? last saved hang : none seen yet ? saved hangs : 0 none seen yet ? saved hangs : 0 ? ?? cycle progress ??????????????????????? ?? cycle progress ??????????????????????? map cover coverage???????????????????????? ================================================================= ==474939==ERROR: AddressSanitizer: heap-use-after-free on address 0x619000000b00 at pc 0x558ba8a13137 bp 0x7ffcfb7b8990 sp 0x7ffcfb7b8980 READ of size 4 at 0x619000000b00 thread T0 #0 0x558ba8a13136 in clrvar (/home/fuzz/vuln_search/busybox/busybox-1.36.1/busybox_unstripped+0x9c8136) 0x619000000b00 is located 128 bytes inside of 1088-byte region [0x619000000a80,0x619000000ec0) freed by thread T0 here: #0 0x7f1e23748c3e in __interceptor_realloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:163 #1 0x558ba87009dc in xrealloc (/home/fuzz/vuln_search/busybox/busybox-1.36.1/busybox_unstripped+0x6b59dc) previously allocated by thread T0 here: #0 0x7f1e23748c3e in __interceptor_realloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:163 #1 0x558ba87009dc in xrealloc (/home/fuzz/vuln_search/busybox/busybox-1.36.1/busybox_unstripped+0x6b59dc) SUMMARY: AddressSanitizer: heap-use-after-free (/home/fuzz/vuln_search/busybox/busybox-1.36.1/busybox_unstripped+0x9c8136) in clrvar Shadow bytes around the buggy address: 0x0c327fff8110: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c327fff8120: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c327fff8130: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c327fff8140: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c327fff8150: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd =>0x0c327fff8160:[fd]fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0c327fff8170: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0c327fff8180: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0c327fff8190: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0c327fff81a0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0c327fff81b0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd Shadow byte legend (one shadow byte represents 8 application bytes): Addressable: 00 Partially addressable: 01 02 03 04 05 06 07 Heap left redzone: fa Freed heap region: fd Stack left redzone: f1 Stack mid redzone: f2 Stack right redzone: f3 Stack after return: f5 Stack use after scope: f8 Global redzone: f9 Global init order: f6 Poisoned by user: f7 Container overflow: fc Array cookie: ac Intra object redzone: bb ASan internal: fe Left alloca redzone: ca Right alloca redzone: cb Shadow gap: cc ==474939==ABORTING -- You are receiving this mail because: You are on the CC list for the bug. From bugzilla at busybox.net Wed May 24 14:29:10 2023 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Wed, 24 May 2023 14:29:10 +0000 Subject: [Bug 15606] New: Possible license conflict with 4-Clause BSD licensed code Message-ID: https://bugs.busybox.net/show_bug.cgi?id=15606 Bug ID: 15606 Summary: Possible license conflict with 4-Clause BSD licensed code Product: Busybox Version: unspecified Hardware: All OS: Linux Status: NEW Severity: normal Priority: P5 Component: Other Assignee: unassigned at busybox.net Reporter: gnu at d-git.de CC: busybox-cvs at busybox.net Target Milestone: --- Hi there, I found a possible license conflict in the files: - networking/inetd.c (includes libbb.h which is GPLv2 licensed) - util-linux/fdisk_osf.c (included in fdisk.c which is GPLv2 licensed) These files are 4-Clause BSD licensed which is incompatible with GPL. I have not found any statement in the license which resolves this issue. -- You are receiving this mail because: You are on the CC list for the bug. From bugzilla at busybox.net Wed May 24 14:30:46 2023 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Wed, 24 May 2023 14:30:46 +0000 Subject: [Bug 15606] Possible license conflict with 4-Clause BSD licensed code In-Reply-To: References: Message-ID: https://bugs.busybox.net/show_bug.cgi?id=15606 Daniel Glinka changed: What |Removed |Added ---------------------------------------------------------------------------- Version|unspecified |1.27.x -- You are receiving this mail because: You are on the CC list for the bug. From bugzilla at busybox.net Thu May 25 03:01:36 2023 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Thu, 25 May 2023 03:01:36 +0000 Subject: [Bug 15611] New: udhcpc6 does not support obtaining the NTP server. Message-ID: https://bugs.busybox.net/show_bug.cgi?id=15611 Bug ID: 15611 Summary: udhcpc6 does not support obtaining the NTP server. Product: Busybox Version: 1.34.x Hardware: All OS: Linux Status: NEW Severity: normal Priority: P5 Component: Networking Assignee: unassigned at busybox.net Reporter: zhousiqi5 at huawei.com CC: busybox-cvs at busybox.net Target Milestone: --- When I use busybox, I find that udhcpc supports ntp acquisition, but udhcpc6 does not. Is there any way to achieve this requirement? Thank you! -- You are receiving this mail because: You are on the CC list for the bug. From vda at busybox.net Thu May 18 22:31:04 2023 From: vda at busybox.net (Denys Vlasenko) Date: Fri, 19 May 2023 00:31:04 +0200 Subject: [tag/1_36_1] new tag created Message-ID: <20230525072607.93BBB868CD@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=1a64f6a20aaf6ea4dbba68bbfa8cc1ab7e5c57c4 tag: https://git.busybox.net/busybox/commit/?id=refs/tags/1_36_1 Bump version to 1.36.1 From vda.linux at googlemail.com Thu May 18 22:31:04 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Fri, 19 May 2023 00:31:04 +0200 Subject: [git commit branch/1_36_stable] Bump version to 1.36.1 Message-ID: <20230525072829.40CAE868CD@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=1a64f6a20aaf6ea4dbba68bbfa8cc1ab7e5c57c4 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/1_36_stable Signed-off-by: Denys Vlasenko --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 503af6941..fa8cb7614 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ VERSION = 1 PATCHLEVEL = 36 -SUBLEVEL = 0 +SUBLEVEL = 1 EXTRAVERSION = NAME = Unnamed From vda.linux at googlemail.com Thu May 25 12:22:10 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Thu, 25 May 2023 14:22:10 +0200 Subject: [git commit] hush: fix ELIF cmd1; cmd2 THEN ... not executing cmd2, closes 15571 Message-ID: <20230525122303.D43E3868EC@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=6824298ab4d3da40763af4d2d466a72745b8b593 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta run_list 1012 1024 +12 Signed-off-by: Denys Vlasenko --- shell/ash_test/ash-misc/elif1.right | 4 ++++ shell/ash_test/ash-misc/elif1.tests | 6 ++++++ shell/ash_test/ash-misc/elif2.right | 2 ++ shell/ash_test/ash-misc/elif2.tests | 8 ++++++++ shell/hush.c | 24 ++++++++++++++++-------- shell/hush_test/hush-misc/elif1.right | 4 ++++ shell/hush_test/hush-misc/elif1.tests | 6 ++++++ shell/hush_test/hush-misc/elif2.right | 2 ++ shell/hush_test/hush-misc/elif2.tests | 8 ++++++++ 9 files changed, 56 insertions(+), 8 deletions(-) diff --git a/shell/ash_test/ash-misc/elif1.right b/shell/ash_test/ash-misc/elif1.right new file mode 100644 index 000000000..36dc59fed --- /dev/null +++ b/shell/ash_test/ash-misc/elif1.right @@ -0,0 +1,4 @@ +ELIF1 +ELIF2 +ELIF THEN +Ok:0 diff --git a/shell/ash_test/ash-misc/elif1.tests b/shell/ash_test/ash-misc/elif1.tests new file mode 100755 index 000000000..77b8a25ea --- /dev/null +++ b/shell/ash_test/ash-misc/elif1.tests @@ -0,0 +1,6 @@ +if false; then + : +elif echo 'ELIF1'; echo 'ELIF2'; then + echo "ELIF THEN" +fi +echo "Ok:$?" diff --git a/shell/ash_test/ash-misc/elif2.right b/shell/ash_test/ash-misc/elif2.right new file mode 100644 index 000000000..8f2851f91 --- /dev/null +++ b/shell/ash_test/ash-misc/elif2.right @@ -0,0 +1,2 @@ +THEN +Ok:0 diff --git a/shell/ash_test/ash-misc/elif2.tests b/shell/ash_test/ash-misc/elif2.tests new file mode 100755 index 000000000..3e5876f05 --- /dev/null +++ b/shell/ash_test/ash-misc/elif2.tests @@ -0,0 +1,8 @@ +if true; then + echo "THEN" +elif echo "ELIF false"; false; then + echo "ELIF THEN" +else + echo "ELSE" +fi +echo "Ok:$?" diff --git a/shell/hush.c b/shell/hush.c index 810dafd35..1f7b58d4f 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -9758,7 +9758,7 @@ static int run_list(struct pipe *pi) smallint last_rword; /* ditto */ #endif - debug_printf_exec("run_list start lvl %d\n", G.run_list_level); + debug_printf_exec("run_list lvl %d start\n", G.run_list_level); debug_enter(); #if ENABLE_HUSH_LOOPS @@ -9817,7 +9817,7 @@ static int run_list(struct pipe *pi) break; IF_HAS_KEYWORDS(rword = pi->res_word;) - debug_printf_exec(": rword=%d cond_code=%d last_rword=%d\n", + debug_printf_exec(": rword:%d cond_code:%d last_rword:%d\n", rword, cond_code, last_rword); sv_errexit_depth = G.errexit_depth; @@ -9851,23 +9851,29 @@ static int run_list(struct pipe *pi) } } last_followup = pi->followup; - IF_HAS_KEYWORDS(last_rword = rword;) #if ENABLE_HUSH_IF - if (cond_code) { + if (cond_code != 0) { if (rword == RES_THEN) { /* if false; then ... fi has exitcode 0! */ G.last_exitcode = rcode = EXIT_SUCCESS; /* "if THEN cmd": skip cmd */ + debug_printf_exec("skipped THEN cmd because IF condition was false\n"); + last_rword = rword; continue; } } else { - if (rword == RES_ELSE || rword == RES_ELIF) { + if (rword == RES_ELSE + || (rword == RES_ELIF && last_rword != RES_ELIF) + ) { /* "if then ... ELSE/ELIF cmd": * skip cmd and all following ones */ + debug_printf_exec("skipped ELSE/ELIF branch because IF condition was true\n"); break; } + //if (rword == RES_THEN): "if THEN cmd", run cmd (fall through) } #endif + IF_HAS_KEYWORDS(last_rword = rword;) #if ENABLE_HUSH_LOOPS if (rword == RES_FOR) { /* && pi->num_cmds - always == 1 */ if (!for_lcur) { @@ -9943,7 +9949,7 @@ static int run_list(struct pipe *pi) ); /* TODO: which FNM_xxx flags to use? */ cond_code = (fnmatch(pattern, case_word, /*flags:*/ 0) != 0); - debug_printf_exec("fnmatch(pattern:'%s',str:'%s'):%d\n", + debug_printf_exec("cond_code=fnmatch(pattern:'%s',str:'%s'):%d\n", pattern, case_word, cond_code); free(pattern); if (cond_code == 0) { @@ -10069,8 +10075,10 @@ static int run_list(struct pipe *pi) /* Analyze how result affects subsequent commands */ #if ENABLE_HUSH_IF - if (rword == RES_IF || rword == RES_ELIF) + if (rword == RES_IF || rword == RES_ELIF) { + debug_printf_exec("cond_code=rcode:%d\n", rcode); cond_code = rcode; + } #endif check_jobs_and_continue: checkjobs(NULL, 0 /*(no pid to wait for)*/); @@ -10111,7 +10119,7 @@ static int run_list(struct pipe *pi) free(case_word); #endif debug_leave(); - debug_printf_exec("run_list lvl %d return %d\n", G.run_list_level + 1, rcode); + debug_printf_exec("run_list lvl %d return %d\n", G.run_list_level, rcode); return rcode; } diff --git a/shell/hush_test/hush-misc/elif1.right b/shell/hush_test/hush-misc/elif1.right new file mode 100644 index 000000000..36dc59fed --- /dev/null +++ b/shell/hush_test/hush-misc/elif1.right @@ -0,0 +1,4 @@ +ELIF1 +ELIF2 +ELIF THEN +Ok:0 diff --git a/shell/hush_test/hush-misc/elif1.tests b/shell/hush_test/hush-misc/elif1.tests new file mode 100755 index 000000000..77b8a25ea --- /dev/null +++ b/shell/hush_test/hush-misc/elif1.tests @@ -0,0 +1,6 @@ +if false; then + : +elif echo 'ELIF1'; echo 'ELIF2'; then + echo "ELIF THEN" +fi +echo "Ok:$?" diff --git a/shell/hush_test/hush-misc/elif2.right b/shell/hush_test/hush-misc/elif2.right new file mode 100644 index 000000000..8f2851f91 --- /dev/null +++ b/shell/hush_test/hush-misc/elif2.right @@ -0,0 +1,2 @@ +THEN +Ok:0 diff --git a/shell/hush_test/hush-misc/elif2.tests b/shell/hush_test/hush-misc/elif2.tests new file mode 100755 index 000000000..3e5876f05 --- /dev/null +++ b/shell/hush_test/hush-misc/elif2.tests @@ -0,0 +1,8 @@ +if true; then + echo "THEN" +elif echo "ELIF false"; false; then + echo "ELIF THEN" +else + echo "ELSE" +fi +echo "Ok:$?" From bugzilla at busybox.net Thu May 25 12:31:12 2023 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Thu, 25 May 2023 12:31:12 +0000 Subject: [Bug 15571] hush will bypass commands after the first one in elif In-Reply-To: References: Message-ID: https://bugs.busybox.net/show_bug.cgi?id=15571 Denys Vlasenko changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution|--- |FIXED --- Comment #2 from Denys Vlasenko --- Fixed in git, thank you. commit 6824298ab4d3da40763af4d2d466a72745b8b593 Date: Thu May 25 14:22:10 2023 +0200 hush: fix ELIF cmd1;cmd2 THEN ... not executing cmd2, closes 15571 -- You are receiving this mail because: You are on the CC list for the bug. From bugzilla at busybox.net Thu May 25 12:32:30 2023 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Thu, 25 May 2023 12:32:30 +0000 Subject: [Bug 15596] 1.36.1 tag and version bump commit missing in git In-Reply-To: References: Message-ID: https://bugs.busybox.net/show_bug.cgi?id=15596 Denys Vlasenko changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution|--- |FIXED --- Comment #1 from Denys Vlasenko --- Fixed. -- You are receiving this mail because: You are on the CC list for the bug. From vda.linux at googlemail.com Thu May 25 13:24:56 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Thu, 25 May 2023 15:24:56 +0200 Subject: [git commit] hush: make "false" built-in Message-ID: <20230525132513.EBD47868F0@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=b5be8da350b59ddc1925c485f2acb9c8f5b79b7e branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta bltins1 384 396 +12 builtin_false - 6 +6 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/0 up/down: 18/0) Total: 18 bytes Signed-off-by: Denys Vlasenko --- shell/hush.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/shell/hush.c b/shell/hush.c index 1f7b58d4f..cdaa67a3b 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -1061,6 +1061,7 @@ static int builtin_export(char **argv) FAST_FUNC; #if ENABLE_HUSH_READONLY static int builtin_readonly(char **argv) FAST_FUNC; #endif +static int builtin_false(char **argv) FAST_FUNC; #if ENABLE_HUSH_JOB static int builtin_fg_bg(char **argv) FAST_FUNC; static int builtin_jobs(char **argv) FAST_FUNC; @@ -1161,6 +1162,7 @@ static const struct built_in_command bltins1[] ALIGN_PTR = { #if ENABLE_HUSH_EXPORT BLTIN("export" , builtin_export , "Set environment variables"), #endif + BLTIN("false" , builtin_false , NULL), #if ENABLE_HUSH_JOB BLTIN("fg" , builtin_fg_bg , "Bring job to foreground"), #endif @@ -10831,6 +10833,11 @@ static int FAST_FUNC builtin_true(char **argv UNUSED_PARAM) return 0; } +static int FAST_FUNC builtin_false(char **argv UNUSED_PARAM) +{ + return 1; +} + #if ENABLE_HUSH_TEST || ENABLE_HUSH_ECHO || ENABLE_HUSH_PRINTF || ENABLE_HUSH_KILL static NOINLINE int run_applet_main(char **argv, int (*applet_main_func)(int argc, char **argv)) { From vda.linux at googlemail.com Thu May 25 13:32:03 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Thu, 25 May 2023 15:32:03 +0200 Subject: [git commit] od: fix -O Message-ID: <20230525133209.58D9186905@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=2bda790fd14adb80820643198bb1e96e4be73571 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master od with option -O (4-byte octal) was incorrectly displaying 2-byte decimal when built without CONFIG_DESKTOP Signed-off-by: David Leonard Signed-off-by: Denys Vlasenko --- coreutils/od.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coreutils/od.c b/coreutils/od.c index 6f22331e0..dcf1bd6f6 100644 --- a/coreutils/od.c +++ b/coreutils/od.c @@ -166,7 +166,7 @@ static const char od_o2si[] ALIGN1 = { 0, 1, 2, 3, 5, 4, 6, 6, 7, 8, 9, 0xa, 0xb, 0xa, 0xa, - 0xb, 1, 8, 9, + 0xc, 1, 8, 9, }; int od_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; From vda.linux at googlemail.com Thu May 25 13:32:03 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Thu, 25 May 2023 15:32:03 +0200 Subject: [git commit] od: add tests Message-ID: <20230525133209.61BC886906@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=64bdd7566c21cb53cb4c384ed52845106529e55f branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master * Added tests for od (non-DESKTOP little-endian) * Allow 'optional' to invert meaning of a config option with '!' Signed-off-by: David Leonard Signed-off-by: Denys Vlasenko --- testsuite/od.tests | 210 +++++++++++++++++++++++++++++++++++++++++++++++++++ testsuite/testing.sh | 10 +++ 2 files changed, 220 insertions(+) diff --git a/testsuite/od.tests b/testsuite/od.tests index 0880e0d2f..0b949d5f0 100755 --- a/testsuite/od.tests +++ b/testsuite/od.tests @@ -6,6 +6,216 @@ # testing "test name" "commands" "expected result" "file input" "stdin" +input="$(printf '\001\002\003\nABC\xfe')" + +le=false +{ printf '\0\1' | od -i | grep -q 256; } && le=true +readonly le + +optional !DESKTOP +testing "od -a (!DESKTOP)" \ + "od -a" \ +"\ +0000000 soh stx etx lf A B C fe +0000010 +" \ + "" "$input" +SKIP= + +optional !DESKTOP +testing "od -B (!DESKTOP)" \ + "od -B" \ +"\ +0000000 001001 005003 041101 177103 +0000010 +" \ + "" "$input" +SKIP= + +optional !DESKTOP +$le || SKIP=1 +testing "od -o (!DESKTOP little-endian)" \ + "od -o" \ +"\ +0000000 001001 005003 041101 177103 +0000010 +" \ + "" "$input" +SKIP= + +optional !DESKTOP +testing "od -b (!DESKTOP)" \ + "od -b" \ +"\ +0000000 001 002 003 012 101 102 103 376 +0000010 +" \ + "" "$input" +SKIP= + +optional !DESKTOP +testing "od -c (!DESKTOP)" \ + "od -c" \ +"\ +0000000 001 002 003 \\\\n A B C 376 +0000010 +" \ + "" "$input" +SKIP= + +optional !DESKTOP +$le || SKIP=1 +testing "od -d (!DESKTOP little-endian)" \ + "od -d" \ +"\ +0000000 00513 02563 16961 65091 +0000010 +" \ + "" "$input" +SKIP= + +optional !DESKTOP +$le || SKIP=1 +testing "od -D (!DESKTOP little-endian)" \ + "od -D" \ +"\ +0000000 0167969281 4265820737 +0000010 +" \ + "" "$input" +SKIP= + +optional !DESKTOP +$le || SKIP=1 +testing "od -e (!DESKTOP little-endian)" \ + "od -e" \ +"\ +0000000 -1.61218556514036e+300 +0000010 +" \ + "" "$input" +SKIP= + +optional !DESKTOP +$le || SKIP=1 +testing "od -F (!DESKTOP little-endian)" \ + "od -F" \ +"\ +0000000 -1.61218556514036e+300 +0000010 +" \ + "" "$input" + +optional !DESKTOP +$le || SKIP=1 +testing "od -f (!DESKTOP little-endian)" \ + "od -f" \ +"\ +0000000 6.3077975e-33 -6.4885867e+37 +0000010 +" \ + "" "$input" +SKIP= + +optional !DESKTOP +$le || SKIP=1 +testing "od -H (!DESKTOP little-endian)" \ + "od -H" \ +"\ +0000000 0a030201 fe434241 +0000010 +" \ + "" "$input" +SKIP= + +optional !DESKTOP +$le || SKIP=1 +testing "od -X (!DESKTOP little-endian)" \ + "od -X" \ +"\ +0000000 0a030201 fe434241 +0000010 +" \ + "" "$input" +SKIP= + +optional !DESKTOP +$le || SKIP=1 +testing "od -h (!DESKTOP little-endian)" \ + "od -h" \ +"\ +0000000 0201 0a03 4241 fe43 +0000010 +" \ + "" "$input" +SKIP= + +optional !DESKTOP +$le || SKIP=1 +testing "od -x (!DESKTOP little-endian)" \ + "od -x" \ +"\ +0000000 0201 0a03 4241 fe43 +0000010 +" \ + "" "$input" +SKIP= + +optional !DESKTOP +$le || SKIP=1 +testing "od -I (!DESKTOP little-endian)" \ + "od -I" \ +"\ +0000000 167969281 -29146559 +0000010 +" \ + "" "$input" +SKIP= + +optional !DESKTOP +$le || SKIP=1 +testing "od -L (!DESKTOP little-endian)" \ + "od -L" \ +"\ +0000000 167969281 -29146559 +0000010 +" \ + "" "$input" +SKIP= + +optional !DESKTOP +$le || SKIP=1 +testing "od -i (!DESKTOP little-endian)" \ + "od -i" \ +"\ +0000000 513 2563 16961 -445 +0000010 +" \ + "" "$input" +SKIP= + +optional !DESKTOP +$le || SKIP=1 +testing "od -O (!DESKTOP little-endian)" \ + "od -O" \ +"\ +0000000 01200601001 37620641101 +0000010 +" \ + "" "$input" +SKIP= + +optional !DESKTOP +$le || SKIP=1 +testing "od -l (!DESKTOP little-endian)" \ + "od -l" \ +"\ +0000000 167969281 -29146559 +0000010 +" \ + "" "$input" +SKIP= + optional DESKTOP testing "od -b" \ "od -b" \ diff --git a/testsuite/testing.sh b/testsuite/testing.sh index f5b756947..95bb46dda 100644 --- a/testsuite/testing.sh +++ b/testsuite/testing.sh @@ -56,11 +56,21 @@ optional() { SKIP= while test "$1"; do + case $1 in + "!"*) + case "${OPTIONFLAGS}" in + *:${1#!}:*) SKIP=1; return;; + esac + shift + ;; + *) case "${OPTIONFLAGS}" in *:$1:*) ;; *) SKIP=1; return ;; esac shift + ;; + esac done } From vda.linux at googlemail.com Thu May 25 15:40:20 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Thu, 25 May 2023 17:40:20 +0200 Subject: [git commit] od: for !DESKTOP, match output more closely to GNU coreutils 9.1, implement -s Message-ID: <20230525173208.981E38690E@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=e2287f99fe6f21fd6435ad04340170ad4ba5f6b3 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master Signed-off-by: Denys Vlasenko --- coreutils/od.c | 55 ++++++++++++++++++++++-------------- libbb/dump.c | 30 ++++++++++++++------ testsuite/od.tests | 83 +++++++++++++++++++++++++++++------------------------- 3 files changed, 100 insertions(+), 68 deletions(-) diff --git a/coreutils/od.c b/coreutils/od.c index dcf1bd6f6..6d562ea91 100644 --- a/coreutils/od.c +++ b/coreutils/od.c @@ -22,7 +22,7 @@ //usage:#if !ENABLE_DESKTOP //usage:#define od_trivial_usage -//usage: "[-aBbcDdeFfHhIiLlOovXx] [FILE]" +//usage: "[-aBbcDdeFfHhIiLlOoXxsv] [FILE]" //usage:#define od_full_usage "\n\n" //usage: "Print FILE (or stdin) unambiguously, as octal bytes by default" //usage:#endif @@ -144,29 +144,42 @@ odoffset(dumper_t *dumper, int argc, char ***argvp) } } +// A format string contains format units separated by whitespace. +// A format unit contains up to three items: an iteration count, a byte count, +// and a format. +// The iteration count is an optional integer (default 1) +// Each format is applied iteration count times. +// The byte count is an optional integer. It defines the number +// of bytes to be interpreted by each iteration of the format. +// If an iteration count and/or a byte count is specified, a slash must be +// placed after the iteration count and/or before the byte count +// to disambiguate them. +// The format is required and must be surrounded by " "s. +// It is a printf-style format. static const char *const add_strings[] ALIGN_PTR = { - "16/1 \"%3_u \" \"\\n\"", /* a */ - "8/2 \" %06o \" \"\\n\"", /* B, o */ - "16/1 \"%03o \" \"\\n\"", /* b */ - "16/1 \"%3_c \" \"\\n\"", /* c */ - "8/2 \" %05u \" \"\\n\"", /* d */ - "4/4 \" %010u \" \"\\n\"", /* D */ - "2/8 \" %21.14e \" \"\\n\"", /* e (undocumented in od), F */ - "4/4 \" %14.7e \" \"\\n\"", /* f */ - "4/4 \" %08x \" \"\\n\"", /* H, X */ - "8/2 \" %04x \" \"\\n\"", /* h, x */ - "4/4 \" %11d \" \"\\n\"", /* I, L, l */ - "8/2 \" %6d \" \"\\n\"", /* i */ - "4/4 \" %011o \" \"\\n\"", /* O */ + "16/1 \"%3_u \" \"\\n\"", /* 0: a */ + "8/2 \"%06o \" \"\\n\"", /* 1: B (undocumented in od), o */ + "16/1 \"%03o \" \"\\n\"", /* 2: b */ + "16/1 \"%3_c \" \"\\n\"", /* 3: c */ + "8/2 \"%5u \" \"\\n\"", /* 4: d */ + "4/4 \"%10u \" \"\\n\"", /* 5: D */ + "2/8 \"%24.14e \" \"\\n\"", /* 6: e (undocumented in od), F */ + "4/4 \"%15.7e \" \"\\n\"", /* 7: f */ + "4/4 \"%08x \" \"\\n\"", /* 8: H, X */ + "8/2 \"%04x \" \"\\n\"", /* 9: h, x */ + "2/8 \"%20lld \" \"\\n\"", /* 10: I, L, l */ + "4/4 \"%11d \" \"\\n\"", /* 11: i */ + "4/4 \"%011o \" \"\\n\"", /* 12: O */ + "8/2 \"%6d \" \"\\n\"", /* 13: s */ }; -static const char od_opts[] ALIGN1 = "aBbcDdeFfHhIiLlOoXxv"; +static const char od_opts[] ALIGN1 = "aBbcDdeFfHhIiLlOoXxsv"; static const char od_o2si[] ALIGN1 = { - 0, 1, 2, 3, 5, - 4, 6, 6, 7, 8, - 9, 0xa, 0xb, 0xa, 0xa, - 0xc, 1, 8, 9, + 0, 1, 2, 3, 5, /* aBbcD */ + 4, 6, 6, 7, 8, /* deFfH */ + 9, 10, 11, 10, 10, /* hIiLl */ + 12, 1, 8, 9, 13 /* OoXxs */ }; int od_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; @@ -184,9 +197,9 @@ int od_main(int argc, char **argv) if (first) { first = 0; bb_dump_add(dumper, "\"%07.7_Ao\n\""); - bb_dump_add(dumper, "\"%07.7_ao \""); + bb_dump_add(dumper, "\"%07.7_ao \""); } else { - bb_dump_add(dumper, "\" \""); + bb_dump_add(dumper, "\" \""); } bb_dump_add(dumper, add_strings[(int)od_o2si[(p - od_opts)]]); } else { /* P, p, s, w, or other unhandled */ diff --git a/libbb/dump.c b/libbb/dump.c index fcdee8343..cfb9d94f9 100644 --- a/libbb/dump.c +++ b/libbb/dump.c @@ -187,6 +187,10 @@ static NOINLINE void rewrite(priv_dumper_t *dumper, FS *fs) ++p2; ++p1; + if (*p1 == 'l') { /* %lld etc */ + ++p2; + ++p1; + } DO_INT_CONV: e = strchr(int_convs, *p1); /* "diouxX"? */ if (!e) @@ -194,7 +198,7 @@ static NOINLINE void rewrite(priv_dumper_t *dumper, FS *fs) pr->flags = F_INT; if (e > int_convs + 1) /* not d or i? */ pr->flags = F_UINT; - byte_count_str = "\004\002\001"; + byte_count_str = "\010\004\002\001"; goto DO_BYTE_COUNT; } else if (strchr(int_convs, *p1)) { /* %d etc */ @@ -601,22 +605,32 @@ static NOINLINE void display(priv_dumper_t* dumper) break; } case F_INT: { - int ival; - short sval; + union { + uint16_t val16; + uint32_t val32; + uint64_t val64; + } u; + int value = *bp; switch (pr->bcnt) { case 1: - printf(pr->fmt, (int) *bp); break; case 2: - memcpy(&sval, bp, sizeof(sval)); - printf(pr->fmt, (int) sval); + memcpy(&u.val16, bp, 2); + value = u.val16; break; case 4: - memcpy(&ival, bp, sizeof(ival)); - printf(pr->fmt, ival); + memcpy(&u.val32, bp, 4); + value = u.val32; break; + case 8: + memcpy(&u.val64, bp, 8); +//A hack. Users _must_ use %llX formats to not truncate high bits + printf(pr->fmt, (long long) u.val64); + goto skip; } + printf(pr->fmt, value); + skip: break; } case F_P: diff --git a/testsuite/od.tests b/testsuite/od.tests index 0b949d5f0..500e0e638 100755 --- a/testsuite/od.tests +++ b/testsuite/od.tests @@ -9,14 +9,19 @@ input="$(printf '\001\002\003\nABC\xfe')" le=false -{ printf '\0\1' | od -i | grep -q 256; } && le=true +{ printf '\0\1' | od -s | grep -q 256; } && le=true readonly le +# NB: +# sed 's/ *$//' truncates trailing spaces. +# This needs to be fixed properly (not output them). +# For now, the tests ignore them (does not require a match). + optional !DESKTOP testing "od -a (!DESKTOP)" \ - "od -a" \ + "od -a | sed 's/ *$//'" \ "\ -0000000 soh stx etx lf A B C fe +0000000 soh stx etx lf A B C fe 0000010 " \ "" "$input" @@ -24,9 +29,9 @@ SKIP= optional !DESKTOP testing "od -B (!DESKTOP)" \ - "od -B" \ + "od -B | sed 's/ *$//'" \ "\ -0000000 001001 005003 041101 177103 +0000000 001001 005003 041101 177103 0000010 " \ "" "$input" @@ -35,9 +40,9 @@ SKIP= optional !DESKTOP $le || SKIP=1 testing "od -o (!DESKTOP little-endian)" \ - "od -o" \ + "od -o | sed 's/ *$//'" \ "\ -0000000 001001 005003 041101 177103 +0000000 001001 005003 041101 177103 0000010 " \ "" "$input" @@ -45,9 +50,9 @@ SKIP= optional !DESKTOP testing "od -b (!DESKTOP)" \ - "od -b" \ + "od -b | sed 's/ *$//'" \ "\ -0000000 001 002 003 012 101 102 103 376 +0000000 001 002 003 012 101 102 103 376 0000010 " \ "" "$input" @@ -55,9 +60,9 @@ SKIP= optional !DESKTOP testing "od -c (!DESKTOP)" \ - "od -c" \ + "od -c | sed 's/ *$//'" \ "\ -0000000 001 002 003 \\\\n A B C 376 +0000000 001 002 003 \\\\n A B C 376 0000010 " \ "" "$input" @@ -66,9 +71,9 @@ SKIP= optional !DESKTOP $le || SKIP=1 testing "od -d (!DESKTOP little-endian)" \ - "od -d" \ + "od -d | sed 's/ *$//'" \ "\ -0000000 00513 02563 16961 65091 +0000000 513 2563 16961 65091 0000010 " \ "" "$input" @@ -77,9 +82,9 @@ SKIP= optional !DESKTOP $le || SKIP=1 testing "od -D (!DESKTOP little-endian)" \ - "od -D" \ + "od -D | sed 's/ *$//'" \ "\ -0000000 0167969281 4265820737 +0000000 167969281 4265820737 0000010 " \ "" "$input" @@ -88,9 +93,9 @@ SKIP= optional !DESKTOP $le || SKIP=1 testing "od -e (!DESKTOP little-endian)" \ - "od -e" \ + "od -e | sed 's/ *$//'" \ "\ -0000000 -1.61218556514036e+300 +0000000 -1.61218556514036e+300 0000010 " \ "" "$input" @@ -99,9 +104,9 @@ SKIP= optional !DESKTOP $le || SKIP=1 testing "od -F (!DESKTOP little-endian)" \ - "od -F" \ + "od -F | sed 's/ *$//'" \ "\ -0000000 -1.61218556514036e+300 +0000000 -1.61218556514036e+300 0000010 " \ "" "$input" @@ -109,9 +114,9 @@ testing "od -F (!DESKTOP little-endian)" \ optional !DESKTOP $le || SKIP=1 testing "od -f (!DESKTOP little-endian)" \ - "od -f" \ + "od -f | sed 's/ *$//'" \ "\ -0000000 6.3077975e-33 -6.4885867e+37 +0000000 6.3077975e-33 -6.4885867e+37 0000010 " \ "" "$input" @@ -120,9 +125,9 @@ SKIP= optional !DESKTOP $le || SKIP=1 testing "od -H (!DESKTOP little-endian)" \ - "od -H" \ + "od -H | sed 's/ *$//'" \ "\ -0000000 0a030201 fe434241 +0000000 0a030201 fe434241 0000010 " \ "" "$input" @@ -131,9 +136,9 @@ SKIP= optional !DESKTOP $le || SKIP=1 testing "od -X (!DESKTOP little-endian)" \ - "od -X" \ + "od -X | sed 's/ *$//'" \ "\ -0000000 0a030201 fe434241 +0000000 0a030201 fe434241 0000010 " \ "" "$input" @@ -142,9 +147,9 @@ SKIP= optional !DESKTOP $le || SKIP=1 testing "od -h (!DESKTOP little-endian)" \ - "od -h" \ + "od -h | sed 's/ *$//'" \ "\ -0000000 0201 0a03 4241 fe43 +0000000 0201 0a03 4241 fe43 0000010 " \ "" "$input" @@ -153,9 +158,9 @@ SKIP= optional !DESKTOP $le || SKIP=1 testing "od -x (!DESKTOP little-endian)" \ - "od -x" \ + "od -x | sed 's/ *$//'" \ "\ -0000000 0201 0a03 4241 fe43 +0000000 0201 0a03 4241 fe43 0000010 " \ "" "$input" @@ -164,9 +169,9 @@ SKIP= optional !DESKTOP $le || SKIP=1 testing "od -I (!DESKTOP little-endian)" \ - "od -I" \ + "od -I | sed 's/ *$//'" \ "\ -0000000 167969281 -29146559 +0000000 -125183517527965183 0000010 " \ "" "$input" @@ -175,9 +180,9 @@ SKIP= optional !DESKTOP $le || SKIP=1 testing "od -L (!DESKTOP little-endian)" \ - "od -L" \ + "od -L | sed 's/ *$//'" \ "\ -0000000 167969281 -29146559 +0000000 -125183517527965183 0000010 " \ "" "$input" @@ -186,9 +191,9 @@ SKIP= optional !DESKTOP $le || SKIP=1 testing "od -i (!DESKTOP little-endian)" \ - "od -i" \ + "od -i | sed 's/ *$//'" \ "\ -0000000 513 2563 16961 -445 +0000000 167969281 -29146559 0000010 " \ "" "$input" @@ -197,9 +202,9 @@ SKIP= optional !DESKTOP $le || SKIP=1 testing "od -O (!DESKTOP little-endian)" \ - "od -O" \ + "od -O | sed 's/ *$//'" \ "\ -0000000 01200601001 37620641101 +0000000 01200601001 37620641101 0000010 " \ "" "$input" @@ -208,9 +213,9 @@ SKIP= optional !DESKTOP $le || SKIP=1 testing "od -l (!DESKTOP little-endian)" \ - "od -l" \ + "od -l | sed 's/ *$//'" \ "\ -0000000 167969281 -29146559 +0000000 -125183517527965183 0000010 " \ "" "$input" From vda.linux at googlemail.com Thu May 25 17:51:37 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Thu, 25 May 2023 19:51:37 +0200 Subject: [git commit] od: correct -i, enable tests which pass for DESKTOP too Message-ID: <20230525175315.B30CB86919@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=ce4cfc33cade63513963f9d5e701f305cbdfe693 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta .rodata 105302 105305 +3 Signed-off-by: Denys Vlasenko --- coreutils/od.c | 2 ++ coreutils/od_bloaty.c | 6 +++-- testsuite/od.tests | 62 +++++++++++++++++++++++++++------------------------ 3 files changed, 39 insertions(+), 31 deletions(-) diff --git a/coreutils/od.c b/coreutils/od.c index 6d562ea91..bd82487e5 100644 --- a/coreutils/od.c +++ b/coreutils/od.c @@ -167,6 +167,8 @@ static const char *const add_strings[] ALIGN_PTR = { "4/4 \"%15.7e \" \"\\n\"", /* 7: f */ "4/4 \"%08x \" \"\\n\"", /* 8: H, X */ "8/2 \"%04x \" \"\\n\"", /* 9: h, x */ + /* This probably also depends on word width of the arch (what is "long"?) */ + /* should be "2/8" or "4/4" depending on sizeof(long)? */ "2/8 \"%20lld \" \"\\n\"", /* 10: I, L, l */ "4/4 \"%11d \" \"\\n\"", /* 11: i */ "4/4 \"%011o \" \"\\n\"", /* 12: O */ diff --git a/coreutils/od_bloaty.c b/coreutils/od_bloaty.c index 5b5e56a21..51fff436b 100644 --- a/coreutils/od_bloaty.c +++ b/coreutils/od_bloaty.c @@ -1245,9 +1245,11 @@ int od_main(int argc UNUSED_PARAM, char **argv) if (opt & OPT_d) decode_format_string("u2"); if (opt & OPT_f) decode_format_string("fF"); if (opt & OPT_h) decode_format_string("x2"); - if (opt & OPT_i) decode_format_string("d2"); + if (opt & OPT_i) decode_format_string("dI"); if (opt & OPT_j) n_bytes_to_skip = xstrtooff_sfx(str_j, 0, bkm_suffixes); - if (opt & OPT_l) decode_format_string("d4"); + /* This probably also depends on word width of the arch (what is "long"?) */ + /* should be "d4" or "d8" depending on sizeof(long)? */ + if (opt & OPT_l) decode_format_string("d8"); if (opt & OPT_o) decode_format_string("o2"); while (lst_t) { decode_format_string(llist_pop(&lst_t)); diff --git a/testsuite/od.tests b/testsuite/od.tests index 500e0e638..fa6745b78 100755 --- a/testsuite/od.tests +++ b/testsuite/od.tests @@ -12,10 +12,10 @@ le=false { printf '\0\1' | od -s | grep -q 256; } && le=true readonly le -# NB: +# NB: for !DESKTOP, # sed 's/ *$//' truncates trailing spaces. -# This needs to be fixed properly (not output them). -# For now, the tests ignore them (does not require a match). +# This needs to be fixed properly (by not outputting them). +# For now, the tests ignore them (do not require a match). optional !DESKTOP testing "od -a (!DESKTOP)" \ @@ -26,8 +26,19 @@ testing "od -a (!DESKTOP)" \ " \ "" "$input" SKIP= +# ^^^ a bit incorrect handling of ctrl/high bytes. +# vvv this output is correct. +optional DESKTOP +testing "od -a (DESKTOP)" \ + "od -a" \ +"\ +0000000 soh stx etx nl A B C ~ +0000010 +" \ + "" "$input" +SKIP= -optional !DESKTOP +optional !DESKTOP #DESKTOP: unrecognized option: B testing "od -B (!DESKTOP)" \ "od -B | sed 's/ *$//'" \ "\ @@ -37,9 +48,8 @@ testing "od -B (!DESKTOP)" \ "" "$input" SKIP= -optional !DESKTOP $le || SKIP=1 -testing "od -o (!DESKTOP little-endian)" \ +testing "od -o (little-endian)" \ "od -o | sed 's/ *$//'" \ "\ 0000000 001001 005003 041101 177103 @@ -48,8 +58,7 @@ testing "od -o (!DESKTOP little-endian)" \ "" "$input" SKIP= -optional !DESKTOP -testing "od -b (!DESKTOP)" \ +testing "od -b" \ "od -b | sed 's/ *$//'" \ "\ 0000000 001 002 003 012 101 102 103 376 @@ -58,8 +67,7 @@ testing "od -b (!DESKTOP)" \ "" "$input" SKIP= -optional !DESKTOP -testing "od -c (!DESKTOP)" \ +testing "od -c" \ "od -c | sed 's/ *$//'" \ "\ 0000000 001 002 003 \\\\n A B C 376 @@ -68,9 +76,8 @@ testing "od -c (!DESKTOP)" \ "" "$input" SKIP= -optional !DESKTOP $le || SKIP=1 -testing "od -d (!DESKTOP little-endian)" \ +testing "od -d (little-endian)" \ "od -d | sed 's/ *$//'" \ "\ 0000000 513 2563 16961 65091 @@ -79,7 +86,7 @@ testing "od -d (!DESKTOP little-endian)" \ "" "$input" SKIP= -optional !DESKTOP +optional !DESKTOP #DESKTOP: unrecognized option: D $le || SKIP=1 testing "od -D (!DESKTOP little-endian)" \ "od -D | sed 's/ *$//'" \ @@ -90,7 +97,7 @@ testing "od -D (!DESKTOP little-endian)" \ "" "$input" SKIP= -optional !DESKTOP +optional !DESKTOP #DESKTOP: unrecognized option: e $le || SKIP=1 testing "od -e (!DESKTOP little-endian)" \ "od -e | sed 's/ *$//'" \ @@ -101,7 +108,7 @@ testing "od -e (!DESKTOP little-endian)" \ "" "$input" SKIP= -optional !DESKTOP +optional !DESKTOP #DESKTOP: unrecognized option: F $le || SKIP=1 testing "od -F (!DESKTOP little-endian)" \ "od -F | sed 's/ *$//'" \ @@ -111,7 +118,7 @@ testing "od -F (!DESKTOP little-endian)" \ " \ "" "$input" -optional !DESKTOP +#optional !DESKTOP $le || SKIP=1 testing "od -f (!DESKTOP little-endian)" \ "od -f | sed 's/ *$//'" \ @@ -122,7 +129,7 @@ testing "od -f (!DESKTOP little-endian)" \ "" "$input" SKIP= -optional !DESKTOP +optional !DESKTOP #DESKTOP: unrecognized option: H $le || SKIP=1 testing "od -H (!DESKTOP little-endian)" \ "od -H | sed 's/ *$//'" \ @@ -133,7 +140,7 @@ testing "od -H (!DESKTOP little-endian)" \ "" "$input" SKIP= -optional !DESKTOP +optional !DESKTOP #DESKTOP: unrecognized option: X $le || SKIP=1 testing "od -X (!DESKTOP little-endian)" \ "od -X | sed 's/ *$//'" \ @@ -144,9 +151,8 @@ testing "od -X (!DESKTOP little-endian)" \ "" "$input" SKIP= -optional !DESKTOP $le || SKIP=1 -testing "od -h (!DESKTOP little-endian)" \ +testing "od -h (little-endian)" \ "od -h | sed 's/ *$//'" \ "\ 0000000 0201 0a03 4241 fe43 @@ -155,9 +161,8 @@ testing "od -h (!DESKTOP little-endian)" \ "" "$input" SKIP= -optional !DESKTOP $le || SKIP=1 -testing "od -x (!DESKTOP little-endian)" \ +testing "od -x (little-endian)" \ "od -x | sed 's/ *$//'" \ "\ 0000000 0201 0a03 4241 fe43 @@ -166,7 +171,7 @@ testing "od -x (!DESKTOP little-endian)" \ "" "$input" SKIP= -optional !DESKTOP +optional !DESKTOP #DESKTOP: unrecognized option: I $le || SKIP=1 testing "od -I (!DESKTOP little-endian)" \ "od -I | sed 's/ *$//'" \ @@ -177,7 +182,7 @@ testing "od -I (!DESKTOP little-endian)" \ "" "$input" SKIP= -optional !DESKTOP +optional !DESKTOP #DESKTOP: unrecognized option: L $le || SKIP=1 testing "od -L (!DESKTOP little-endian)" \ "od -L | sed 's/ *$//'" \ @@ -188,9 +193,8 @@ testing "od -L (!DESKTOP little-endian)" \ "" "$input" SKIP= -optional !DESKTOP $le || SKIP=1 -testing "od -i (!DESKTOP little-endian)" \ +testing "od -i (little-endian)" \ "od -i | sed 's/ *$//'" \ "\ 0000000 167969281 -29146559 @@ -199,7 +203,7 @@ testing "od -i (!DESKTOP little-endian)" \ "" "$input" SKIP= -optional !DESKTOP +optional !DESKTOP #DESKTOP: unrecognized option: O $le || SKIP=1 testing "od -O (!DESKTOP little-endian)" \ "od -O | sed 's/ *$//'" \ @@ -210,9 +214,9 @@ testing "od -O (!DESKTOP little-endian)" \ "" "$input" SKIP= -optional !DESKTOP +# This probably also depends on word width of the arch (what is "long"?) $le || SKIP=1 -testing "od -l (!DESKTOP little-endian)" \ +testing "od -l (little-endian)" \ "od -l | sed 's/ *$//'" \ "\ 0000000 -125183517527965183 From vda.linux at googlemail.com Thu May 25 20:17:18 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Thu, 25 May 2023 22:17:18 +0200 Subject: [git commit] od: implement -B Message-ID: <20230525201738.5B0D786922@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=6882a933cf078be35f4eb93963365549d43cb497 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta .rodata 105305 105306 +1 od_main 1880 1866 -14 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 1/-14) Total: -13 bytes Signed-off-by: Denys Vlasenko --- coreutils/od_bloaty.c | 23 ++++++++++++----------- testsuite/od.tests | 7 +++---- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/coreutils/od_bloaty.c b/coreutils/od_bloaty.c index 51fff436b..57a4fe163 100644 --- a/coreutils/od_bloaty.c +++ b/coreutils/od_bloaty.c @@ -49,20 +49,21 @@ enum { OPT_j = 1 << 9, OPT_l = 1 << 10, OPT_o = 1 << 11, - OPT_t = 1 << 12, + OPT_B = 1 << 12, /* undocumented synonym to -o */ + OPT_t = 1 << 13, /* When zero and two or more consecutive blocks are equal, format only the first block and output an asterisk alone on the following line to indicate that identical blocks have been elided: */ - OPT_v = 1 << 13, - OPT_x = 1 << 14, - OPT_s = 1 << 15, - OPT_S = 1 << 16, - OPT_w = 1 << 17, - OPT_traditional = (1 << 18) * ENABLE_LONG_OPTS, + OPT_v = 1 << 14, + OPT_x = 1 << 15, + OPT_s = 1 << 16, + OPT_S = 1 << 17, + OPT_w = 1 << 18, + OPT_traditional = (1 << 19) * ENABLE_LONG_OPTS, }; #define OD_GETOPT32() getopt32long(argv, \ - "A:N:abcdfhij:lot:*vxsS:w:+:", od_longopts, \ + "A:N:abcdfhij:loBt:*vxsS:w:+:", od_longopts, \ /* -w with optional param */ \ /* -S was -s and also had optional parameter */ \ /* but in coreutils 6.3 it was renamed and now has */ \ @@ -1239,22 +1240,22 @@ int od_main(int argc UNUSED_PARAM, char **argv) if (opt & OPT_N) { max_bytes_to_format = xstrtooff_sfx(str_N, 0, bkm_suffixes); } + if (opt & OPT_a) decode_format_string("a"); if (opt & OPT_b) decode_format_string("oC"); if (opt & OPT_c) decode_format_string("c"); if (opt & OPT_d) decode_format_string("u2"); if (opt & OPT_f) decode_format_string("fF"); - if (opt & OPT_h) decode_format_string("x2"); + if (opt & (OPT_h|OPT_x)) decode_format_string("x2"); if (opt & OPT_i) decode_format_string("dI"); if (opt & OPT_j) n_bytes_to_skip = xstrtooff_sfx(str_j, 0, bkm_suffixes); /* This probably also depends on word width of the arch (what is "long"?) */ /* should be "d4" or "d8" depending on sizeof(long)? */ if (opt & OPT_l) decode_format_string("d8"); - if (opt & OPT_o) decode_format_string("o2"); + if (opt & (OPT_o|OPT_B)) decode_format_string("o2"); while (lst_t) { decode_format_string(llist_pop(&lst_t)); } - if (opt & OPT_x) decode_format_string("x2"); if (opt & OPT_s) decode_format_string("d2"); if (opt & OPT_S) { G.string_min = xstrtou_sfx(str_S, 0, bkm_suffixes); diff --git a/testsuite/od.tests b/testsuite/od.tests index fa6745b78..29ca829d5 100755 --- a/testsuite/od.tests +++ b/testsuite/od.tests @@ -38,8 +38,7 @@ testing "od -a (DESKTOP)" \ "" "$input" SKIP= -optional !DESKTOP #DESKTOP: unrecognized option: B -testing "od -B (!DESKTOP)" \ +testing "od -B" \ "od -B | sed 's/ *$//'" \ "\ 0000000 001001 005003 041101 177103 @@ -117,10 +116,10 @@ testing "od -F (!DESKTOP little-endian)" \ 0000010 " \ "" "$input" +SKIP= -#optional !DESKTOP $le || SKIP=1 -testing "od -f (!DESKTOP little-endian)" \ +testing "od -f (little-endian)" \ "od -f | sed 's/ *$//'" \ "\ 0000000 6.3077975e-33 -6.4885867e+37 From vda.linux at googlemail.com Thu May 25 21:48:13 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Thu, 25 May 2023 23:48:13 +0200 Subject: [git commit] od: stop printing extra trailing spaces Message-ID: <20230525214914.870AC8692F@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=0c3270f7e55e0ca7b8d664851468511d2c8995cf branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta .rodata 104598 104613 +15 display 1475 1485 +10 od_main 549 556 +7 rewrite 971 967 -4 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/1 up/down: 32/-4) Total: 28 bytes Signed-off-by: Denys Vlasenko --- coreutils/od.c | 33 +++++++++++++++++---------------- include/dump.h | 1 + libbb/dump.c | 21 ++++++++++++++------- testsuite/od.tests | 43 +++++++++++++++++++------------------------ 4 files changed, 51 insertions(+), 47 deletions(-) diff --git a/coreutils/od.c b/coreutils/od.c index bd82487e5..abedb40a7 100644 --- a/coreutils/od.c +++ b/coreutils/od.c @@ -157,22 +157,22 @@ odoffset(dumper_t *dumper, int argc, char ***argvp) // The format is required and must be surrounded by " "s. // It is a printf-style format. static const char *const add_strings[] ALIGN_PTR = { - "16/1 \"%3_u \" \"\\n\"", /* 0: a */ - "8/2 \"%06o \" \"\\n\"", /* 1: B (undocumented in od), o */ - "16/1 \"%03o \" \"\\n\"", /* 2: b */ - "16/1 \"%3_c \" \"\\n\"", /* 3: c */ - "8/2 \"%5u \" \"\\n\"", /* 4: d */ - "4/4 \"%10u \" \"\\n\"", /* 5: D */ - "2/8 \"%24.14e \" \"\\n\"", /* 6: e (undocumented in od), F */ - "4/4 \"%15.7e \" \"\\n\"", /* 7: f */ - "4/4 \"%08x \" \"\\n\"", /* 8: H, X */ - "8/2 \"%04x \" \"\\n\"", /* 9: h, x */ + "16/1 \" %3_u\" \"\\n\"", /* 0: a */ + "8/2 \" %06o\" \"\\n\"", /* 1: B (undocumented in od), o */ + "16/1 \" %03o\" \"\\n\"", /* 2: b */ + "16/1 \" %3_c\" \"\\n\"", /* 3: c */ + "8/2 \" %5u\" \"\\n\"", /* 4: d */ + "4/4 \" %10u\" \"\\n\"", /* 5: D */ + "2/8 \" %24.14e\" \"\\n\"", /* 6: e (undocumented in od), F */ + "4/4 \" %15.7e\" \"\\n\"", /* 7: f */ + "4/4 \" %08x\" \"\\n\"", /* 8: H, X */ + "8/2 \" %04x\" \"\\n\"", /* 9: h, x */ /* This probably also depends on word width of the arch (what is "long"?) */ /* should be "2/8" or "4/4" depending on sizeof(long)? */ - "2/8 \"%20lld \" \"\\n\"", /* 10: I, L, l */ - "4/4 \"%11d \" \"\\n\"", /* 11: i */ - "4/4 \"%011o \" \"\\n\"", /* 12: O */ - "8/2 \"%6d \" \"\\n\"", /* 13: s */ + "2/8 \" %20lld\" \"\\n\"", /* 10: I, L, l */ + "4/4 \" %11d\" \"\\n\"", /* 11: i */ + "4/4 \" %011o\" \"\\n\"", /* 12: O */ + "8/2 \" %6d\" \"\\n\"", /* 13: s */ }; static const char od_opts[] ALIGN1 = "aBbcDdeFfHhIiLlOoXxsv"; @@ -199,9 +199,9 @@ int od_main(int argc, char **argv) if (first) { first = 0; bb_dump_add(dumper, "\"%07.7_Ao\n\""); - bb_dump_add(dumper, "\"%07.7_ao \""); + bb_dump_add(dumper, "\"%07.7_ao\""); } else { - bb_dump_add(dumper, "\" \""); + bb_dump_add(dumper, "\" \""); } bb_dump_add(dumper, add_strings[(int)od_o2si[(p - od_opts)]]); } else { /* P, p, s, w, or other unhandled */ @@ -212,6 +212,7 @@ int od_main(int argc, char **argv) bb_dump_add(dumper, "\"%07.7_Ao\n\""); bb_dump_add(dumper, "\"%07.7_ao \" 8/2 \"%06o \" \"\\n\""); } + dumper->od_eofstring = "\n"; argc -= optind; argv += optind; diff --git a/include/dump.h b/include/dump.h index 10fc5d900..11dcf4523 100644 --- a/include/dump.h +++ b/include/dump.h @@ -34,6 +34,7 @@ typedef struct dumper_t { smallint dump_vflag; /*enum dump_vflag_t*/ FS *fshead; const char *xxd_eofstring; + const char *od_eofstring; off_t address; /* address/offset in stream */ long long xxd_displayoff; } dumper_t; diff --git a/libbb/dump.c b/libbb/dump.c index cfb9d94f9..77d76611b 100644 --- a/libbb/dump.c +++ b/libbb/dump.c @@ -242,7 +242,7 @@ static NOINLINE void rewrite(priv_dumper_t *dumper, FS *fs) pr->flags = F_P; *p1 = 'c'; goto DO_BYTE_COUNT_1; - case 'u': /* %_p: chars, 'nul', 'esc' etc for nonprintable */ + case 'u': /* %_u: chars, 'nul', 'esc' etc for nonprintable */ pr->flags = F_U; /* *p1 = 'c'; set in conv_u */ goto DO_BYTE_COUNT_1; @@ -322,8 +322,7 @@ static NOINLINE void rewrite(priv_dumper_t *dumper, FS *fs) p2 = NULL; for (p1 = pr->fmt; *p1; ++p1) p2 = isspace(*p1) ? p1 : NULL; - if (p2) - pr->nospace = p2; + pr->nospace = p2; } } } @@ -477,7 +476,7 @@ static void bpad(PR *pr) static const char conv_str[] ALIGN1 = "\0" "\\""0""\0" - "\007""\\""a""\0" /* \a */ + "\007""\\""a""\0" "\b" "\\""b""\0" "\f" "\\""f""\0" "\n" "\\""n""\0" @@ -539,7 +538,6 @@ static void conv_u(PR *pr, unsigned char *p) static NOINLINE void display(priv_dumper_t* dumper) { unsigned char *bp; - unsigned char savech = '\0'; while ((bp = get(dumper)) != NULL) { FS *fs; @@ -560,6 +558,8 @@ static NOINLINE void display(priv_dumper_t* dumper) PR *pr; for (pr = fu->nextpr; pr; dumper->pub.address += pr->bcnt, bp += pr->bcnt, pr = pr->nextpr) { + unsigned char savech; + if (dumper->eaddress && dumper->pub.address >= dumper->eaddress ) { @@ -568,9 +568,16 @@ static NOINLINE void display(priv_dumper_t* dumper) fputs_stdout(dumper->pub.xxd_eofstring); return; } + if (dumper->pub.od_eofstring) { + /* od support: requested to not pad incomplete blocks */ + /* ... but do print final offset */ + fputs_stdout(dumper->pub.od_eofstring); + goto endfu; + } if (!(pr->flags & (F_TEXT | F_BPAD))) bpad(pr); } + savech = '\0'; if (cnt == 1 && pr->nospace) { savech = *pr->nospace; *pr->nospace = '\0'; @@ -665,7 +672,7 @@ static NOINLINE void display(priv_dumper_t* dumper) break; } } - if (cnt == 1 && pr->nospace) { + if (savech) { *pr->nospace = savech; } } @@ -673,7 +680,7 @@ static NOINLINE void display(priv_dumper_t* dumper) } } } - + endfu: if (dumper->endfu) { PR *pr; /* diff --git a/testsuite/od.tests b/testsuite/od.tests index 29ca829d5..4b1525620 100755 --- a/testsuite/od.tests +++ b/testsuite/od.tests @@ -12,14 +12,9 @@ le=false { printf '\0\1' | od -s | grep -q 256; } && le=true readonly le -# NB: for !DESKTOP, -# sed 's/ *$//' truncates trailing spaces. -# This needs to be fixed properly (by not outputting them). -# For now, the tests ignore them (do not require a match). - optional !DESKTOP testing "od -a (!DESKTOP)" \ - "od -a | sed 's/ *$//'" \ + "od -a" \ "\ 0000000 soh stx etx lf A B C fe 0000010 @@ -39,7 +34,7 @@ testing "od -a (DESKTOP)" \ SKIP= testing "od -B" \ - "od -B | sed 's/ *$//'" \ + "od -B" \ "\ 0000000 001001 005003 041101 177103 0000010 @@ -49,7 +44,7 @@ SKIP= $le || SKIP=1 testing "od -o (little-endian)" \ - "od -o | sed 's/ *$//'" \ + "od -o" \ "\ 0000000 001001 005003 041101 177103 0000010 @@ -58,7 +53,7 @@ testing "od -o (little-endian)" \ SKIP= testing "od -b" \ - "od -b | sed 's/ *$//'" \ + "od -b" \ "\ 0000000 001 002 003 012 101 102 103 376 0000010 @@ -67,7 +62,7 @@ testing "od -b" \ SKIP= testing "od -c" \ - "od -c | sed 's/ *$//'" \ + "od -c" \ "\ 0000000 001 002 003 \\\\n A B C 376 0000010 @@ -77,7 +72,7 @@ SKIP= $le || SKIP=1 testing "od -d (little-endian)" \ - "od -d | sed 's/ *$//'" \ + "od -d" \ "\ 0000000 513 2563 16961 65091 0000010 @@ -88,7 +83,7 @@ SKIP= optional !DESKTOP #DESKTOP: unrecognized option: D $le || SKIP=1 testing "od -D (!DESKTOP little-endian)" \ - "od -D | sed 's/ *$//'" \ + "od -D" \ "\ 0000000 167969281 4265820737 0000010 @@ -99,7 +94,7 @@ SKIP= optional !DESKTOP #DESKTOP: unrecognized option: e $le || SKIP=1 testing "od -e (!DESKTOP little-endian)" \ - "od -e | sed 's/ *$//'" \ + "od -e" \ "\ 0000000 -1.61218556514036e+300 0000010 @@ -110,7 +105,7 @@ SKIP= optional !DESKTOP #DESKTOP: unrecognized option: F $le || SKIP=1 testing "od -F (!DESKTOP little-endian)" \ - "od -F | sed 's/ *$//'" \ + "od -F" \ "\ 0000000 -1.61218556514036e+300 0000010 @@ -120,7 +115,7 @@ SKIP= $le || SKIP=1 testing "od -f (little-endian)" \ - "od -f | sed 's/ *$//'" \ + "od -f" \ "\ 0000000 6.3077975e-33 -6.4885867e+37 0000010 @@ -131,7 +126,7 @@ SKIP= optional !DESKTOP #DESKTOP: unrecognized option: H $le || SKIP=1 testing "od -H (!DESKTOP little-endian)" \ - "od -H | sed 's/ *$//'" \ + "od -H" \ "\ 0000000 0a030201 fe434241 0000010 @@ -142,7 +137,7 @@ SKIP= optional !DESKTOP #DESKTOP: unrecognized option: X $le || SKIP=1 testing "od -X (!DESKTOP little-endian)" \ - "od -X | sed 's/ *$//'" \ + "od -X" \ "\ 0000000 0a030201 fe434241 0000010 @@ -152,7 +147,7 @@ SKIP= $le || SKIP=1 testing "od -h (little-endian)" \ - "od -h | sed 's/ *$//'" \ + "od -h" \ "\ 0000000 0201 0a03 4241 fe43 0000010 @@ -162,7 +157,7 @@ SKIP= $le || SKIP=1 testing "od -x (little-endian)" \ - "od -x | sed 's/ *$//'" \ + "od -x" \ "\ 0000000 0201 0a03 4241 fe43 0000010 @@ -173,7 +168,7 @@ SKIP= optional !DESKTOP #DESKTOP: unrecognized option: I $le || SKIP=1 testing "od -I (!DESKTOP little-endian)" \ - "od -I | sed 's/ *$//'" \ + "od -I" \ "\ 0000000 -125183517527965183 0000010 @@ -184,7 +179,7 @@ SKIP= optional !DESKTOP #DESKTOP: unrecognized option: L $le || SKIP=1 testing "od -L (!DESKTOP little-endian)" \ - "od -L | sed 's/ *$//'" \ + "od -L" \ "\ 0000000 -125183517527965183 0000010 @@ -194,7 +189,7 @@ SKIP= $le || SKIP=1 testing "od -i (little-endian)" \ - "od -i | sed 's/ *$//'" \ + "od -i" \ "\ 0000000 167969281 -29146559 0000010 @@ -205,7 +200,7 @@ SKIP= optional !DESKTOP #DESKTOP: unrecognized option: O $le || SKIP=1 testing "od -O (!DESKTOP little-endian)" \ - "od -O | sed 's/ *$//'" \ + "od -O" \ "\ 0000000 01200601001 37620641101 0000010 @@ -216,7 +211,7 @@ SKIP= # This probably also depends on word width of the arch (what is "long"?) $le || SKIP=1 testing "od -l (little-endian)" \ - "od -l | sed 's/ *$//'" \ + "od -l" \ "\ 0000000 -125183517527965183 0000010 From vda.linux at googlemail.com Fri May 26 02:27:43 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Fri, 26 May 2023 04:27:43 +0200 Subject: [git commit] od: fix default format, shrink Message-ID: <20230526024637.7F8C186940@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=aa4d303a3139107919f73cece4eaf85a7dc75db6 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta od_main 556 568 +12 .rodata 104613 104555 -58 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 12/-58) Total: -46 bytes Signed-off-by: Denys Vlasenko --- coreutils/od.c | 42 ++++++++++++++++++++++-------------------- testsuite/od.tests | 10 ++++++++++ 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/coreutils/od.c b/coreutils/od.c index abedb40a7..3fd241d51 100644 --- a/coreutils/od.c +++ b/coreutils/od.c @@ -144,35 +144,36 @@ odoffset(dumper_t *dumper, int argc, char ***argvp) } } -// A format string contains format units separated by whitespace. +// bb_dump_add(): +// A format string contains format units separated by [optional] whitespace. // A format unit contains up to three items: an iteration count, a byte count, // and a format. -// The iteration count is an optional integer (default 1) +// The iteration count is an optional integer (default 1). // Each format is applied iteration count times. // The byte count is an optional integer. It defines the number // of bytes to be interpreted by each iteration of the format. // If an iteration count and/or a byte count is specified, a slash must be // placed after the iteration count and/or before the byte count // to disambiguate them. -// The format is required and must be surrounded by " "s. -// It is a printf-style format. +// The printf-style format is required and must be surrounded by " "s. +// (Below, each string contains two format units) static const char *const add_strings[] ALIGN_PTR = { - "16/1 \" %3_u\" \"\\n\"", /* 0: a */ - "8/2 \" %06o\" \"\\n\"", /* 1: B (undocumented in od), o */ - "16/1 \" %03o\" \"\\n\"", /* 2: b */ - "16/1 \" %3_c\" \"\\n\"", /* 3: c */ - "8/2 \" %5u\" \"\\n\"", /* 4: d */ - "4/4 \" %10u\" \"\\n\"", /* 5: D */ - "2/8 \" %24.14e\" \"\\n\"", /* 6: e (undocumented in od), F */ - "4/4 \" %15.7e\" \"\\n\"", /* 7: f */ - "4/4 \" %08x\" \"\\n\"", /* 8: H, X */ - "8/2 \" %04x\" \"\\n\"", /* 9: h, x */ + "16/1 \" %3_u\"" "\"\n\"", /* 0: a */ + "8/2 \" %06o\"" "\"\n\"", /* 1: B (undocumented in od), o */ + "16/1 \" %03o\"" "\"\n\"", /* 2: b */ + "16/1 \" %3_c\"" "\"\n\"", /* 3: c */ + "8/2 \" %5u\"" "\"\n\"", /* 4: d */ + "4/4 \" %10u\"" "\"\n\"", /* 5: D */ + "2/8 \" %24.14e\"" "\"\n\"", /* 6: e (undocumented in od), F */ + "4/4 \" %15.7e\"" "\"\n\"", /* 7: f */ + "4/4 \" %08x\"" "\"\n\"", /* 8: H, X */ + "8/2 \" %04x\"" "\"\n\"", /* 9: h, x */ /* This probably also depends on word width of the arch (what is "long"?) */ /* should be "2/8" or "4/4" depending on sizeof(long)? */ - "2/8 \" %20lld\" \"\\n\"", /* 10: I, L, l */ - "4/4 \" %11d\" \"\\n\"", /* 11: i */ - "4/4 \" %011o\" \"\\n\"", /* 12: O */ - "8/2 \" %6d\" \"\\n\"", /* 13: s */ + "2/8 \" %20lld\"" "\"\n\"", /* 10: I, L, l */ + "4/4 \" %11d\"" "\"\n\"", /* 11: i */ + "4/4 \" %011o\"" "\"\n\"", /* 12: O */ + "8/2 \" %6d\"" "\"\n\"", /* 13: s */ }; static const char od_opts[] ALIGN1 = "aBbcDdeFfHhIiLlOoXxsv"; @@ -204,13 +205,14 @@ int od_main(int argc, char **argv) bb_dump_add(dumper, "\" \""); } bb_dump_add(dumper, add_strings[(int)od_o2si[(p - od_opts)]]); - } else { /* P, p, s, w, or other unhandled */ + } else { /* P, p, w, or other unhandled */ bb_show_usage(); } } if (!dumper->fshead) { bb_dump_add(dumper, "\"%07.7_Ao\n\""); - bb_dump_add(dumper, "\"%07.7_ao \" 8/2 \"%06o \" \"\\n\""); + bb_dump_add(dumper, "\"%07.7_ao\""); + bb_dump_add(dumper, add_strings[1]); /* -o format is default */ } dumper->od_eofstring = "\n"; diff --git a/testsuite/od.tests b/testsuite/od.tests index 4b1525620..d6f50a206 100755 --- a/testsuite/od.tests +++ b/testsuite/od.tests @@ -12,6 +12,16 @@ le=false { printf '\0\1' | od -s | grep -q 256; } && le=true readonly le +$le || SKIP=1 +testing "od (little-endian)" \ + "od" \ +"\ +0000000 001001 005003 041101 177103 +0000010 +" \ + "" "$input" +SKIP= + optional !DESKTOP testing "od -a (!DESKTOP)" \ "od -a" \ From vda.linux at googlemail.com Fri May 26 10:34:11 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Fri, 26 May 2023 12:34:11 +0200 Subject: [git commit] libbb/dump: conditionalize code used only by xxd and od Message-ID: <20230526105823.4CF4186956@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=3c6f6382eef14b880550cbf28ac5a517d0a075fc branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master Signed-off-by: Denys Vlasenko --- coreutils/od.c | 2 +- include/dump.h | 4 ++++ libbb/dump.c | 6 +++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/coreutils/od.c b/coreutils/od.c index 3fd241d51..46aba5a7c 100644 --- a/coreutils/od.c +++ b/coreutils/od.c @@ -223,7 +223,7 @@ int od_main(int argc, char **argv) return bb_dump_dump(dumper, argv); } -#endif /* ENABLE_DESKTOP */ +#endif /* !ENABLE_DESKTOP */ /*- * Copyright (c) 1990 The Regents of the University of California. diff --git a/include/dump.h b/include/dump.h index 11dcf4523..8fb92f07b 100644 --- a/include/dump.h +++ b/include/dump.h @@ -33,8 +33,12 @@ typedef struct dumper_t { int dump_length; /* max bytes to read */ smallint dump_vflag; /*enum dump_vflag_t*/ FS *fshead; +#if ENABLE_XXD const char *xxd_eofstring; +#endif +#if ENABLE_OD const char *od_eofstring; +#endif off_t address; /* address/offset in stream */ long long xxd_displayoff; } dumper_t; diff --git a/libbb/dump.c b/libbb/dump.c index 77d76611b..21c6c7083 100644 --- a/libbb/dump.c +++ b/libbb/dump.c @@ -563,17 +563,21 @@ static NOINLINE void display(priv_dumper_t* dumper) if (dumper->eaddress && dumper->pub.address >= dumper->eaddress ) { +#if ENABLE_XXD if (dumper->pub.xxd_eofstring) { /* xxd support: requested to not pad incomplete blocks */ fputs_stdout(dumper->pub.xxd_eofstring); return; } +#endif +#if ENABLE_OD if (dumper->pub.od_eofstring) { /* od support: requested to not pad incomplete blocks */ /* ... but do print final offset */ fputs_stdout(dumper->pub.od_eofstring); goto endfu; } +#endif if (!(pr->flags & (F_TEXT | F_BPAD))) bpad(pr); } @@ -637,7 +641,7 @@ static NOINLINE void display(priv_dumper_t* dumper) goto skip; } printf(pr->fmt, value); - skip: + IF_OD(skip:) break; } case F_P: From vda.linux at googlemail.com Fri May 26 10:56:17 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Fri, 26 May 2023 12:56:17 +0200 Subject: [git commit] od: support -DOHXIL Message-ID: <20230526105823.55D318693F@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=60d4d55b870757089cdae96920cf6c416ba2de37 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta od_main 1866 1917 +51 .rodata 105306 105321 +15 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 66/0) Total: 66 bytes Signed-off-by: Denys Vlasenko --- coreutils/od.c | 4 +++- coreutils/od_bloaty.c | 43 +++++++++++++++++++++++++++---------------- testsuite/od.tests | 44 ++++++++++++++++---------------------------- 3 files changed, 46 insertions(+), 45 deletions(-) diff --git a/coreutils/od.c b/coreutils/od.c index 46aba5a7c..98ae06ba7 100644 --- a/coreutils/od.c +++ b/coreutils/od.c @@ -22,7 +22,9 @@ //usage:#if !ENABLE_DESKTOP //usage:#define od_trivial_usage -//usage: "[-aBbcDdeFfHhIiLlOoXxsv] [FILE]" +//usage: "[-abcdeFfhIiLloxsv] [FILE]" +// We also support -BDOHXIL, but they are not documented in coreutils 9.1 +// manpage/help, so don't show them either. //usage:#define od_full_usage "\n\n" //usage: "Print FILE (or stdin) unambiguously, as octal bytes by default" //usage:#endif diff --git a/coreutils/od_bloaty.c b/coreutils/od_bloaty.c index 57a4fe163..2782adbf6 100644 --- a/coreutils/od_bloaty.c +++ b/coreutils/od_bloaty.c @@ -27,6 +27,8 @@ //usage:#if ENABLE_DESKTOP //usage:#define od_trivial_usage //usage: "[-abcdfhilovxs] [-t TYPE] [-A RADIX] [-N SIZE] [-j SKIP] [-S MINSTR] [-w WIDTH] [FILE]..." +// We also support -BDOHXIL, but they are not documented in coreutils 9.1 +// manpage/help, so don't show them either. // We don't support: // ... [FILE] [[+]OFFSET[.][b]] // Support is buggy for: @@ -43,27 +45,33 @@ enum { OPT_b = 1 << 3, OPT_c = 1 << 4, OPT_d = 1 << 5, - OPT_f = 1 << 6, - OPT_h = 1 << 7, - OPT_i = 1 << 8, - OPT_j = 1 << 9, - OPT_l = 1 << 10, - OPT_o = 1 << 11, - OPT_B = 1 << 12, /* undocumented synonym to -o */ - OPT_t = 1 << 13, + OPT_D = 1 << 6, /* undocumented in coreutils 9.1 */ + OPT_f = 1 << 7, + OPT_h = 1 << 8, + OPT_H = 1 << 9, /* undocumented in coreutils 9.1 */ + OPT_i = 1 << 10, + OPT_I = 1 << 11, /* undocumented in coreutils 9.1 */ + OPT_j = 1 << 12, + OPT_l = 1 << 13, + OPT_L = 1 << 14, /* undocumented in coreutils 9.1 */ + OPT_o = 1 << 15, + OPT_O = 1 << 16, /* undocumented in coreutils 9.1 */ + OPT_B = 1 << 17, /* undocumented synonym to -o */ + OPT_t = 1 << 18, /* When zero and two or more consecutive blocks are equal, format only the first block and output an asterisk alone on the following line to indicate that identical blocks have been elided: */ - OPT_v = 1 << 14, - OPT_x = 1 << 15, - OPT_s = 1 << 16, - OPT_S = 1 << 17, - OPT_w = 1 << 18, - OPT_traditional = (1 << 19) * ENABLE_LONG_OPTS, + OPT_v = 1 << 19, + OPT_x = 1 << 20, + OPT_X = 1 << 21, /* undocumented in coreutils 9.1 */ + OPT_s = 1 << 22, + OPT_S = 1 << 23, + OPT_w = 1 << 24, + OPT_traditional = (1 << 25) * ENABLE_LONG_OPTS, }; #define OD_GETOPT32() getopt32long(argv, \ - "A:N:abcdfhij:loBt:*vxsS:w:+:", od_longopts, \ + "A:N:abcdDfhHiIj:lLoOBt:*vxXsS:w:+:", od_longopts, \ /* -w with optional param */ \ /* -S was -s and also had optional parameter */ \ /* but in coreutils 6.3 it was renamed and now has */ \ @@ -1245,14 +1253,17 @@ int od_main(int argc UNUSED_PARAM, char **argv) if (opt & OPT_b) decode_format_string("oC"); if (opt & OPT_c) decode_format_string("c"); if (opt & OPT_d) decode_format_string("u2"); + if (opt & OPT_D) decode_format_string("uI"); if (opt & OPT_f) decode_format_string("fF"); if (opt & (OPT_h|OPT_x)) decode_format_string("x2"); + if (opt & (OPT_H|OPT_X)) decode_format_string("xI"); if (opt & OPT_i) decode_format_string("dI"); if (opt & OPT_j) n_bytes_to_skip = xstrtooff_sfx(str_j, 0, bkm_suffixes); /* This probably also depends on word width of the arch (what is "long"?) */ /* should be "d4" or "d8" depending on sizeof(long)? */ - if (opt & OPT_l) decode_format_string("d8"); + if (opt & (OPT_I|OPT_l|OPT_L)) decode_format_string("d8"); if (opt & (OPT_o|OPT_B)) decode_format_string("o2"); + if (opt & OPT_O) decode_format_string("oI"); while (lst_t) { decode_format_string(llist_pop(&lst_t)); } diff --git a/testsuite/od.tests b/testsuite/od.tests index d6f50a206..677968967 100755 --- a/testsuite/od.tests +++ b/testsuite/od.tests @@ -90,9 +90,8 @@ testing "od -d (little-endian)" \ "" "$input" SKIP= -optional !DESKTOP #DESKTOP: unrecognized option: D $le || SKIP=1 -testing "od -D (!DESKTOP little-endian)" \ +testing "od -D (little-endian)" \ "od -D" \ "\ 0000000 167969281 4265820737 @@ -133,9 +132,8 @@ testing "od -f (little-endian)" \ "" "$input" SKIP= -optional !DESKTOP #DESKTOP: unrecognized option: H $le || SKIP=1 -testing "od -H (!DESKTOP little-endian)" \ +testing "od -H (little-endian)" \ "od -H" \ "\ 0000000 0a030201 fe434241 @@ -144,9 +142,8 @@ testing "od -H (!DESKTOP little-endian)" \ "" "$input" SKIP= -optional !DESKTOP #DESKTOP: unrecognized option: X $le || SKIP=1 -testing "od -X (!DESKTOP little-endian)" \ +testing "od -X (little-endian)" \ "od -X" \ "\ 0000000 0a030201 fe434241 @@ -175,51 +172,42 @@ testing "od -x (little-endian)" \ "" "$input" SKIP= -optional !DESKTOP #DESKTOP: unrecognized option: I $le || SKIP=1 -testing "od -I (!DESKTOP little-endian)" \ - "od -I" \ +testing "od -i (little-endian)" \ + "od -i" \ "\ -0000000 -125183517527965183 +0000000 167969281 -29146559 0000010 " \ "" "$input" SKIP= -optional !DESKTOP #DESKTOP: unrecognized option: L $le || SKIP=1 -testing "od -L (!DESKTOP little-endian)" \ - "od -L" \ +testing "od -O (little-endian)" \ + "od -O" \ "\ -0000000 -125183517527965183 +0000000 01200601001 37620641101 0000010 " \ "" "$input" SKIP= +# This probably also depends on word width of the arch (what is "long"?) $le || SKIP=1 -testing "od -i (little-endian)" \ - "od -i" \ +testing "od -I (little-endian)" \ + "od -I" \ "\ -0000000 167969281 -29146559 +0000000 -125183517527965183 0000010 " \ "" "$input" -SKIP= - -optional !DESKTOP #DESKTOP: unrecognized option: O -$le || SKIP=1 -testing "od -O (!DESKTOP little-endian)" \ - "od -O" \ +testing "od -L (little-endian)" \ + "od -L" \ "\ -0000000 01200601001 37620641101 +0000000 -125183517527965183 0000010 " \ "" "$input" -SKIP= - -# This probably also depends on word width of the arch (what is "long"?) -$le || SKIP=1 testing "od -l (little-endian)" \ "od -l" \ "\ From vda.linux at googlemail.com Fri May 26 11:01:41 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Fri, 26 May 2023 13:01:41 +0200 Subject: [git commit] od: actually remove -IL from --help, as comment says Message-ID: <20230526110205.7CC098695B@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=25a10ffe1fcec1adc40d91d1f4ddfdf7fe12cc74 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master Signed-off-by: Denys Vlasenko --- coreutils/od.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coreutils/od.c b/coreutils/od.c index 98ae06ba7..3684e4ed3 100644 --- a/coreutils/od.c +++ b/coreutils/od.c @@ -22,7 +22,7 @@ //usage:#if !ENABLE_DESKTOP //usage:#define od_trivial_usage -//usage: "[-abcdeFfhIiLloxsv] [FILE]" +//usage: "[-abcdeFfhiloxsv] [FILE]" // We also support -BDOHXIL, but they are not documented in coreutils 9.1 // manpage/help, so don't show them either. //usage:#define od_full_usage "\n\n" From vda.linux at googlemail.com Fri May 26 11:33:08 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Fri, 26 May 2023 13:33:08 +0200 Subject: [git commit] od, hexdump: byte 0x11 is "dc1" not "dcl" Message-ID: <20230526113518.5AB5486962@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=de851bc9b2dcf3f5fad424172d08e850c8af7d62 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master Signed-off-by: Denys Vlasenko --- libbb/dump.c | 6 ++++-- testsuite/hexdump.tests | 16 ++++++++++++++++ testsuite/od.tests | 32 +++++++++++++++++++++++++------- 3 files changed, 45 insertions(+), 9 deletions(-) diff --git a/libbb/dump.c b/libbb/dump.c index 21c6c7083..fc145edf9 100644 --- a/libbb/dump.c +++ b/libbb/dump.c @@ -516,10 +516,12 @@ static void conv_u(PR *pr, unsigned char *p) static const char list[] ALIGN1 = "nul\0soh\0stx\0etx\0eot\0enq\0ack\0bel\0" "bs\0_ht\0_lf\0_vt\0_ff\0_cr\0_so\0_si\0_" - "dle\0dcl\0dc2\0dc3\0dc4\0nak\0syn\0etb\0" + "dle\0dc1\0dc2\0dc3\0dc4\0nak\0syn\0etb\0" "can\0em\0_sub\0esc\0fs\0_gs\0_rs\0_us"; + /* NB: bug: od uses %_u to implement -a, + * but it should use "nl", not "lf", for char #10. + */ - /* od used nl, not lf */ if (*p <= 0x1f) { *pr->cchar = 's'; printf(pr->fmt, list + (4 * (int)*p)); diff --git a/testsuite/hexdump.tests b/testsuite/hexdump.tests index cfb20187e..084156af4 100755 --- a/testsuite/hexdump.tests +++ b/testsuite/hexdump.tests @@ -34,4 +34,20 @@ testing "hexdump thinks last full block can match" \ '' \ '\0\0\0\0\0\0\0\0\0\0\0\0' +testing "hexdump e %3_u" \ + "hexdump -e '16/1 \" %3_u\" \"\n\"'" \ + "\ + nul soh stx etx eot enq ack bel bs ht lf vt ff cr so si + dle dc1 dc2 dc3 dc4 nak syn etb can em sub esc fs gs rs us + p q r s t u v w x y z { | } ~ del + 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f + f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe ff +" \ + "" \ +"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"\ +"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"\ +"\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f"\ +"\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"\ +"\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"\ + exit $FAILCOUNT diff --git a/testsuite/od.tests b/testsuite/od.tests index 677968967..fce66efbb 100755 --- a/testsuite/od.tests +++ b/testsuite/od.tests @@ -26,21 +26,39 @@ optional !DESKTOP testing "od -a (!DESKTOP)" \ "od -a" \ "\ -0000000 soh stx etx lf A B C fe -0000010 +0000000 nul soh stx etx eot enq ack bel bs ht lf vt ff cr so si +0000020 dle dc1 dc2 dc3 dc4 nak syn etb can em sub esc fs gs rs us +0000040 p q r s t u v w x y z { | } ~ del +0000060 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f +0000100 f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe ff +0000120 " \ - "" "$input" + "" \ +"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"\ +"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"\ +"\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f"\ +"\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"\ +"\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff" SKIP= -# ^^^ a bit incorrect handling of ctrl/high bytes. +# ^^^ a bit incorrect handling of ctrl ("lf" should be "nl") and high bytes. # vvv this output is correct. optional DESKTOP testing "od -a (DESKTOP)" \ "od -a" \ "\ -0000000 soh stx etx nl A B C ~ -0000010 +0000000 nul soh stx etx eot enq ack bel bs ht nl vt ff cr so si +0000020 dle dc1 dc2 dc3 dc4 nak syn etb can em sub esc fs gs rs us +0000040 p q r s t u v w x y z { | } ~ del +0000060 nul soh stx etx eot enq ack bel bs ht nl vt ff cr so si +0000100 p q r s t u v w x y z { | } ~ del +0000120 " \ - "" "$input" + "" \ +"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"\ +"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"\ +"\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f"\ +"\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"\ +"\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff" SKIP= testing "od -B" \ From vda.linux at googlemail.com Fri May 26 12:10:38 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Fri, 26 May 2023 14:10:38 +0200 Subject: [git commit] libbb/dump: correct handling of 1-byte signed int format Message-ID: <20230526121142.229E08696D@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=34751d8bf921a2c07cf9a7ce9074756a3d936013 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master Signed-off-by: Denys Vlasenko --- libbb/dump.c | 37 +++++++++++++++++-------------------- testsuite/hexdump.tests | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 21 deletions(-) diff --git a/libbb/dump.c b/libbb/dump.c index dace481c2..49340b5a5 100644 --- a/libbb/dump.c +++ b/libbb/dump.c @@ -619,31 +619,31 @@ static NOINLINE void display(priv_dumper_t* dumper) } case F_INT: { union { - uint16_t val16; - uint32_t val32; - uint64_t val64; + int16_t ival16; + int32_t ival32; + int64_t ival64; } u; - int value = *bp; + int value = (signed char)*bp; switch (pr->bcnt) { case 1: break; case 2: - memcpy(&u.val16, bp, 2); - value = u.val16; + move_from_unaligned16(u.ival16, bp); + value = u.ival16; break; case 4: - memcpy(&u.val32, bp, 4); - value = u.val32; + move_from_unaligned32(u.ival32, bp); + value = u.ival32; break; case 8: - memcpy(&u.val64, bp, 8); + move_from_unaligned64(u.ival64, bp); //A hack. Users _must_ use %llX formats to not truncate high bits - printf(pr->fmt, (long long) u.val64); + printf(pr->fmt, (long long)u.ival64); goto skip; } printf(pr->fmt, value); - IF_OD(skip:) + skip: break; } case F_P: @@ -659,22 +659,19 @@ static NOINLINE void display(priv_dumper_t* dumper) conv_u(pr, bp); break; case F_UINT: { - unsigned ival; - unsigned short sval; - + unsigned value = (unsigned char)*bp; switch (pr->bcnt) { case 1: - printf(pr->fmt, (unsigned) *bp); break; case 2: - memcpy(&sval, bp, sizeof(sval)); - printf(pr->fmt, (unsigned) sval); + move_from_unaligned16(value, bp); break; case 4: - memcpy(&ival, bp, sizeof(ival)); - printf(pr->fmt, ival); + move_from_unaligned32(value, bp); break; + /* case 8: no users yet */ } + printf(pr->fmt, value); break; } } @@ -686,7 +683,7 @@ static NOINLINE void display(priv_dumper_t* dumper) } } } - endfu: + IF_OD(endfu:) if (dumper->endfu) { PR *pr; /* diff --git a/testsuite/hexdump.tests b/testsuite/hexdump.tests index 084156af4..be0379cfc 100755 --- a/testsuite/hexdump.tests +++ b/testsuite/hexdump.tests @@ -34,7 +34,7 @@ testing "hexdump thinks last full block can match" \ '' \ '\0\0\0\0\0\0\0\0\0\0\0\0' -testing "hexdump e %3_u" \ +testing "hexdump -e %3_u" \ "hexdump -e '16/1 \" %3_u\" \"\n\"'" \ "\ nul soh stx etx eot enq ack bel bs ht lf vt ff cr so si @@ -50,4 +50,36 @@ testing "hexdump e %3_u" \ "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"\ "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"\ +testing "hexdump -e /1 %d" \ + "hexdump -e '16/1 \" %4d\" \"\n\"'" \ + "\ + 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 + 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 + 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 + -128 -127 -126 -125 -124 -123 -122 -121 -120 -119 -118 -117 -116 -115 -114 -113 + -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 +" \ + "" \ +"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"\ +"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"\ +"\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f"\ +"\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"\ +"\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"\ + +testing "hexdump -e /2 %d" \ + "hexdump -e '8/2 \" %6d\" \"\n\"'" \ + "\ + 256 770 1284 1798 2312 2826 3340 3854 + 4368 4882 5396 5910 6424 6938 7452 7966 + 29040 29554 30068 30582 31096 31610 32124 32638 + -32384 -31870 -31356 -30842 -30328 -29814 -29300 -28786 + -3600 -3086 -2572 -2058 -1544 -1030 -516 -2 +" \ + "" \ +"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"\ +"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"\ +"\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f"\ +"\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"\ +"\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"\ + exit $FAILCOUNT From vda.linux at googlemail.com Fri May 26 11:39:33 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Fri, 26 May 2023 13:39:33 +0200 Subject: [git commit] libbb/dump: use fputs_stdout where appropriate Message-ID: <20230526121142.1635E8696C@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=8fab21114122c9abf54a750523a12bf263d5b0b2 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta display 1485 1483 -2 Signed-off-by: Denys Vlasenko --- libbb/dump.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libbb/dump.c b/libbb/dump.c index fc145edf9..dace481c2 100644 --- a/libbb/dump.c +++ b/libbb/dump.c @@ -653,7 +653,7 @@ static NOINLINE void display(priv_dumper_t* dumper) printf(pr->fmt, (char *) bp); break; case F_TEXT: - printf(pr->fmt); + fputs_stdout(pr->fmt); break; case F_U: conv_u(pr, bp); @@ -705,7 +705,7 @@ static NOINLINE void display(priv_dumper_t* dumper) printf(pr->fmt, (unsigned long long) dumper->eaddress + dumper->pub.xxd_displayoff); break; case F_TEXT: - printf(pr->fmt); + fputs_stdout(pr->fmt); break; } } From vda.linux at googlemail.com Fri May 26 12:46:29 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Fri, 26 May 2023 14:46:29 +0200 Subject: [git commit] hexdump, xxd: shrink strings Message-ID: <20230526125244.2551786972@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=283cba78f2c9ea8478ef58ba616197df31640353 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta add_first 12 10 -2 .rodata 105321 105306 -15 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-17) Total: -17 bytes Signed-off-by: Denys Vlasenko --- util-linux/hexdump.c | 20 ++++++++++---------- util-linux/hexdump_xxd.c | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/util-linux/hexdump.c b/util-linux/hexdump.c index 307a84803..421fe025d 100644 --- a/util-linux/hexdump.c +++ b/util-linux/hexdump.c @@ -72,14 +72,14 @@ static void bb_dump_addfile(dumper_t *dumper, char *name) } static const char *const add_strings[] ALIGN_PTR = { - "\"%07.7_ax \"16/1 \"%03o \"\"\n\"", /* b */ - "\"%07.7_ax \"16/1 \"%3_c \"\"\n\"", /* c */ - "\"%07.7_ax \"8/2 \" %05u \"\"\n\"", /* d */ - "\"%07.7_ax \"8/2 \" %06o \"\"\n\"", /* o */ - "\"%07.7_ax \"8/2 \" %04x \"\"\n\"", /* x */ + "\"%07_ax\"16/1 \" %03o\"" "\"\n\"", /* b */ + "\"%07_ax\"16/1 \" %3_c\"" "\"\n\"", /* c */ + "\"%07_ax\"8/2 \" %05u\"" "\"\n\"", /* d */ + "\"%07_ax\"8/2 \" %06o\"" "\"\n\"", /* o */ + "\"%07_ax\"8/2 \" %04x\"" "\"\n\"", /* x */ }; -static const char add_first[] ALIGN1 = "\"%07.7_Ax\n\""; +static const char add_first[] ALIGN1 = "\"%07_Ax\n\""; static const char hexdump_opts[] ALIGN1 = "bcdoxCe:f:n:s:v"; @@ -110,9 +110,9 @@ int hexdump_main(int argc, char **argv) /* Save a little bit of space below by omitting the 'else's. */ if (ch == 'C') { hd_applet: - bb_dump_add(dumper, "\"%08.8_Ax\n\""); // final address line after dump - //------------------- "address " 8 * "xx " " " 8 * "xx " - bb_dump_add(dumper, "\"%08.8_ax \"8/1 \"%02x \"\" \"8/1 \"%02x \""); + bb_dump_add(dumper, "\"%08_Ax\n\""); // final address line after dump + //------------------- "address " 8 * " xx" " " 8 * " xx" + bb_dump_add(dumper, "\"%08_ax \"8/1 \" %02x\"\" \"8/1 \" %02x\""); //------------------- " |ASCII...........|\n" bb_dump_add(dumper, "\" |\"16/1 \"%_p\"\"|\n\""); } @@ -140,7 +140,7 @@ int hexdump_main(int argc, char **argv) if (!dumper->fshead) { bb_dump_add(dumper, add_first); - bb_dump_add(dumper, "\"%07.7_ax \"8/2 \"%04x \"\"\n\""); + bb_dump_add(dumper, "\"%07_ax\"8/2 \" %04x\"\"\n\""); } argv += optind; diff --git a/util-linux/hexdump_xxd.c b/util-linux/hexdump_xxd.c index 9738a76ad..636cbfeec 100644 --- a/util-linux/hexdump_xxd.c +++ b/util-linux/hexdump_xxd.c @@ -285,7 +285,7 @@ int xxd_main(int argc UNUSED_PARAM, char **argv) // output is " 0xXX, 0xXX, 0xXX...", add leading space bb_dump_add(dumper, "\" \""); } else - bb_dump_add(dumper, "\"%08.8_ax: \""); // "address: " + bb_dump_add(dumper, "\"%08_ax: \""); // "address: " } if (bytes < 1 || bytes >= cols) { From vda.linux at googlemail.com Fri May 26 14:43:40 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Fri, 26 May 2023 16:43:40 +0200 Subject: [git commit] hexdump: code shrink Message-ID: <20230526144406.AA4BD86977@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=d7814f572725f224fcef8870a75c2483043d3681 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta add_format - 50 +50 add_first 10 - -10 hexdump_main 401 366 -35 .rodata 105306 105255 -51 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 0/2 up/down: 50/-96) Total: -46 bytes Signed-off-by: Denys Vlasenko --- util-linux/hexdump.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/util-linux/hexdump.c b/util-linux/hexdump.c index 421fe025d..be4c1964f 100644 --- a/util-linux/hexdump.c +++ b/util-linux/hexdump.c @@ -72,14 +72,20 @@ static void bb_dump_addfile(dumper_t *dumper, char *name) } static const char *const add_strings[] ALIGN_PTR = { - "\"%07_ax\"16/1 \" %03o\"" "\"\n\"", /* b */ - "\"%07_ax\"16/1 \" %3_c\"" "\"\n\"", /* c */ - "\"%07_ax\"8/2 \" %05u\"" "\"\n\"", /* d */ - "\"%07_ax\"8/2 \" %06o\"" "\"\n\"", /* o */ - "\"%07_ax\"8/2 \" %04x\"" "\"\n\"", /* x */ + "16/1 \" %03o" , /* b */ + "16/1 \" %3_c" , /* c */ + "8/2 \" %05u" , /* d */ + "8/2 \" %06o" , /* o */ + "8/2 \" %04x", /* x */ }; -static const char add_first[] ALIGN1 = "\"%07_Ax\n\""; +static void add_format(dumper_t *dumper, const char *fmt) +{ + char fmtbuf[sizeof("\"%07_ax\"" "%s\"" "\"\n\"") + 16]; + sprintf(fmtbuf, "\"%%07_ax\"" "%s\"" "\"\n\"", fmt); + bb_dump_add(dumper, "\"%07_Ax\n\""); + bb_dump_add(dumper, fmtbuf); +} static const char hexdump_opts[] ALIGN1 = "bcdoxCe:f:n:s:v"; @@ -104,8 +110,7 @@ int hexdump_main(int argc, char **argv) if (!p) bb_show_usage(); if ((p - hexdump_opts) < 5) { - bb_dump_add(dumper, add_first); - bb_dump_add(dumper, add_strings[(int)(p - hexdump_opts)]); + add_format(dumper, add_strings[(int)(p - hexdump_opts)]); } /* Save a little bit of space below by omitting the 'else's. */ if (ch == 'C') { @@ -139,8 +144,7 @@ int hexdump_main(int argc, char **argv) } if (!dumper->fshead) { - bb_dump_add(dumper, add_first); - bb_dump_add(dumper, "\"%07_ax\"8/2 \" %04x\"\"\n\""); + add_format(dumper, "8/2 \" %04x"); } argv += optind; From vda.linux at googlemail.com Fri May 26 17:36:58 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Fri, 26 May 2023 19:36:58 +0200 Subject: [git commit] awk: fix use-after-realloc (CVE-2021-42380), closes 15601 Message-ID: <20230526173951.423E88697F@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=5dcc443dba039b305a510c01883e9f34e42656ae branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master Signed-off-by: Denys Vlasenko --- editors/awk.c | 26 +++++++++++++++++++------ testsuite/awk.tests | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 6 deletions(-) diff --git a/editors/awk.c b/editors/awk.c index 728ee8685..2af823808 100644 --- a/editors/awk.c +++ b/editors/awk.c @@ -555,7 +555,7 @@ struct globals { const char *g_progname; int g_lineno; int nfields; - int maxfields; /* used in fsrealloc() only */ + unsigned maxfields; var *Fields; char *g_pos; char g_saved_ch; @@ -1931,9 +1931,9 @@ static void fsrealloc(int size) { int i, newsize; - if (size >= maxfields) { - /* Sanity cap, easier than catering for overflows */ - if (size > 0xffffff) + if ((unsigned)size >= maxfields) { + /* Sanity cap, easier than catering for over/underflows */ + if ((unsigned)size > 0xffffff) bb_die_memory_exhausted(); i = maxfields; @@ -2891,6 +2891,7 @@ static var *evaluate(node *op, var *res) uint32_t opinfo; int opn; node *op1; + var *old_Fields_ptr; opinfo = op->info; opn = (opinfo & OPNMASK); @@ -2899,10 +2900,16 @@ static var *evaluate(node *op, var *res) debug_printf_eval("opinfo:%08x opn:%08x\n", opinfo, opn); /* execute inevitable things */ + old_Fields_ptr = NULL; if (opinfo & OF_RES1) { if ((opinfo & OF_REQUIRED) && !op1) syntax_error(EMSG_TOO_FEW_ARGS); L.v = evaluate(op1, TMPVAR0); + /* Does L.v point to $n variable? */ + if ((size_t)(L.v - Fields) < maxfields) { + /* yes, remember where Fields[] is */ + old_Fields_ptr = Fields; + } if (opinfo & OF_STR1) { L.s = getvar_s(L.v); debug_printf_eval("L.s:'%s'\n", L.s); @@ -2921,8 +2928,15 @@ static var *evaluate(node *op, var *res) */ if (opinfo & OF_RES2) { R.v = evaluate(op->r.n, TMPVAR1); - //TODO: L.v may be invalid now, set L.v to NULL to catch bugs? - //L.v = NULL; + /* Seen in $5=$$5=$0: + * Evaluation of R.v ($$5=$0 expression) + * made L.v ($5) invalid. It's detected here. + */ + if (old_Fields_ptr) { + //if (old_Fields_ptr != Fields) + // debug_printf_eval("L.v moved\n"); + L.v += Fields - old_Fields_ptr; + } if (opinfo & OF_STR2) { R.s = getvar_s(R.v); debug_printf_eval("R.s:'%s'\n", R.s); diff --git a/testsuite/awk.tests b/testsuite/awk.tests index bbf0fbff1..ddc51047b 100755 --- a/testsuite/awk.tests +++ b/testsuite/awk.tests @@ -485,4 +485,59 @@ testing 'awk assign while test' \ "" \ "foo" +# User-supplied bug (SEGV) example, was causing use-after-realloc +testing 'awk assign while assign' \ + "awk '\$5=\$\$5=\$0'; echo \$?" \ + "\ +??? process timing ?????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ??? process timing ?????????????????????????????????????????????????????????????????????????????????????????????????????????????????? overall results ??????????????? results ??????????????? +??? run time : ??? run time : 0 days, 0 hrs, 0 min, 56 sec ??? cycles done : 0 ??? days, 0 hrs, 0 min, 56 sec ??? cycles done : 0 ??? +??? last new find ??? last new find : 0 days, 0 hrs, 0 min, 1 sec ??? corpus count : 208 ??? 0 days, 0 hrs, 0 min, 1 sec ??? corpus count : 208 ??? +???last saved crash : ???last saved crash : none seen yet ???saved crashes : 0 ??? seen yet ???saved crashes : 0 ??? +??? last saved hang ??? last saved hang : none seen yet ??? saved hangs : 0 ??? none seen yet ??? saved hangs : 0 ??? +?????? cycle progress ????????????????????????????????????????????????????????????????????? ?????? cycle progress ????????????????????????????????????????????????????????????????????? map coverage???????????????????????????????????????????????????????????????????????? coverage???????????????????????????????????????????????????????????????????????? +??? now processing : ??? now processing : 184.1 (88.5%) ??? map density : 0.30% / 0.52% ??? (88.5%) ??? map density : 0.30% / 0.52% ??? ??? now processing : 184.1 (88.5%) ??? map density : 0.30% / 0.52% ??? +??? runs timed out ??? runs timed out : 0 (0.00%) ??? count coverage : 2.18 bits/tuple ??? 0 (0.00%) ??? count coverage : 2.18 bits/tuple ??? +?????? stage progress ????????????????????????????????????????????????????????????????????? ?????? stage progress ????????????????????????????????????????????????????????????????????? findings in depth ?????????????????????????????????????????????????????? in depth ?????????????????????????????????????????????????????? +??? now trying : ??? now trying : havoc ??? favored items : 43 (20.67%) ??? ??? favored items : 43 (20.67%) ??? +??? stage execs : ??? stage execs : 11.2k/131k (8.51%) ??? new edges on : 52 (25.00%) ??? (8.51%) ??? new edges on ??? stage execs : 11.2k/131k (8.51%) ??? new edges on : 52 (25.00%) ??? 52 (25.00%) ??? +??? total execs : ??? total execs : 179k ??? total crashes : 0 (0 saved) ??? ??? total crashes : 0 (0 saved) ??? ??? total execs : 179k ??? total crashes : 0 (0 saved) ??? +??? exec speed : ??? exec speed : 3143/sec ??? total tmouts : 0 (0 saved) ??? ??? total tmouts : 0 (0 saved) ??? ??? exec speed : 3143/sec ??? total tmouts : 0 (0 saved) ??? +?????? fuzzing strategy yields ?????? fuzzing strategy yields ???????????????????????????????????????????????????????????????????????????????????? item geometry ???????????????????????? item geometry ???????????????????????? +??? bit flips : ??? bit flips : 11/648, 4/638, 5/618 ??? levels : 4 ??? 4/638, 5/618 ??? levels : ??? bit flips : 11/648, 4/638, 5/618 ??? levels : 4 ??? ??? +??? byte flips : ??? byte flips : 0/81, 0/71, 0/52 ??? pending : 199 ??? 0/71, 0/52 ??? pending : 199 ??? +??? arithmetics : 11/4494, ??? arithmetics : 11/4494, 0/1153, 0/0 ??? pend fav : 35 ??? 0/0 ??? pend fav : 35 ??? +??? known ints : 1/448, 0/1986, 0/2288 ??? own finds : 207 ??? known ints : ??? known ints : 1/448, 0/1986, 0/2288 ??? own finds : 207 ??? 0/1986, 0/2288 ??? own finds : 207 ??? +??? dictionary : 0/0, ??? dictionary : 0/0, 0/0, 0/0, 0/0 ??? imported : 0 ??? 0/0, 0/0 ??? imported : 0 ??? +???havoc/splice : 142/146k, 23/7616 ???havoc/splice : 142/146k, 23/7616 ??? stability : 100.00% ??? stability : 100.00% ??? +???py/custom/rq : unused, unused, ???py/custom/rq : unused, unused, unused, unused ??????????????????????????????????????????????????????????????????????????? unused ??????????????????????????????????????????????????????????????????????????? +??? trim/eff : 57.02%/26, ??? trim/eff : 57.02%/26, 0.00% ??? [cpu000:100%] ??? [cpu000:100%] +??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????^C ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????^C +0 +" \ + "" \ + "\ +??? process timing ?????????????????????????????????????????????????????????????????????????????????????????????????????????????????? overall results ??????????????? +??? run time : 0 days, 0 hrs, 0 min, 56 sec ??? cycles done : 0 ??? +??? last new find : 0 days, 0 hrs, 0 min, 1 sec ??? corpus count : 208 ??? +???last saved crash : none seen yet ???saved crashes : 0 ??? +??? last saved hang : none seen yet ??? saved hangs : 0 ??? +?????? cycle progress ????????????????????????????????????????????????????????????????????? map coverage???????????????????????????????????????????????????????????????????????? +??? now processing : 184.1 (88.5%) ??? map density : 0.30% / 0.52% ??? +??? runs timed out : 0 (0.00%) ??? count coverage : 2.18 bits/tuple ??? +?????? stage progress ????????????????????????????????????????????????????????????????????? findings in depth ?????????????????????????????????????????????????????? +??? now trying : havoc ??? favored items : 43 (20.67%) ??? +??? stage execs : 11.2k/131k (8.51%) ??? new edges on : 52 (25.00%) ??? +??? total execs : 179k ??? total crashes : 0 (0 saved) ??? +??? exec speed : 3143/sec ??? total tmouts : 0 (0 saved) ??? +?????? fuzzing strategy yields ???????????????????????????????????????????????????????????????????????????????????? item geometry ???????????????????????? +??? bit flips : 11/648, 4/638, 5/618 ??? levels : 4 ??? +??? byte flips : 0/81, 0/71, 0/52 ??? pending : 199 ??? +??? arithmetics : 11/4494, 0/1153, 0/0 ??? pend fav : 35 ??? +??? known ints : 1/448, 0/1986, 0/2288 ??? own finds : 207 ??? +??? dictionary : 0/0, 0/0, 0/0, 0/0 ??? imported : 0 ??? +???havoc/splice : 142/146k, 23/7616 ??? stability : 100.00% ??? +???py/custom/rq : unused, unused, unused, unused ??????????????????????????????????????????????????????????????????????????? +??? trim/eff : 57.02%/26, 0.00% ??? [cpu000:100%] +??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????^C" + exit $FAILCOUNT From bugzilla at busybox.net Fri May 26 17:40:12 2023 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Fri, 26 May 2023 17:40:12 +0000 Subject: [Bug 15601] CVE-2021-42380 unrepaired or new issues introduced by fixing CVE-2021-42380. In-Reply-To: References: Message-ID: https://bugs.busybox.net/show_bug.cgi?id=15601 Denys Vlasenko changed: What |Removed |Added ---------------------------------------------------------------------------- Resolution|--- |FIXED Status|NEW |RESOLVED --- Comment #1 from Denys Vlasenko --- Excellent example! Thank you. Fixed in git. -- You are receiving this mail because: You are on the CC list for the bug. From vda.linux at googlemail.com Fri May 26 18:17:04 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Fri, 26 May 2023 20:17:04 +0200 Subject: [git commit] od: -l,I,L indeed depend on sizeof(long), fix this Message-ID: <20230526181958.D79C386987@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=6d9427420bab4ef756444fc8800dbf56d7dacf7d branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta .rodata 105255 105252 -3 od_main 1917 1901 -16 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-19) Total: -19 bytes Signed-off-by: Denys Vlasenko --- coreutils/od.c | 21 +++++++++++++-------- coreutils/od_bloaty.c | 10 +++++++--- testsuite/od.tests | 37 +++++++++++++++++++------------------ 3 files changed, 39 insertions(+), 29 deletions(-) diff --git a/coreutils/od.c b/coreutils/od.c index 3684e4ed3..a7b1ba444 100644 --- a/coreutils/od.c +++ b/coreutils/od.c @@ -170,12 +170,17 @@ static const char *const add_strings[] ALIGN_PTR = { "4/4 \" %15.7e\"" "\"\n\"", /* 7: f */ "4/4 \" %08x\"" "\"\n\"", /* 8: H, X */ "8/2 \" %04x\"" "\"\n\"", /* 9: h, x */ - /* This probably also depends on word width of the arch (what is "long"?) */ - /* should be "2/8" or "4/4" depending on sizeof(long)? */ - "2/8 \" %20lld\"" "\"\n\"", /* 10: I, L, l */ - "4/4 \" %11d\"" "\"\n\"", /* 11: i */ - "4/4 \" %011o\"" "\"\n\"", /* 12: O */ - "8/2 \" %6d\"" "\"\n\"", /* 13: s */ + "4/4 \" %11d\"" "\"\n\"", /* 10: i */ + "4/4 \" %011o\"" "\"\n\"", /* 11: O */ + "8/2 \" %6d\"" "\"\n\"", /* 12: s */ + /* -I,L,l: depend on word width of the arch (what is "long"?) */ +#if ULONG_MAX > 0xffffffff + "2/8 \" %20lld\"" "\"\n\"", /* 13: I, L, l */ +#define L_ 13 +#else + /* 32-bit arch: -I,L,l are the same as -i */ +#define L_ 10 +#endif }; static const char od_opts[] ALIGN1 = "aBbcDdeFfHhIiLlOoXxsv"; @@ -183,8 +188,8 @@ static const char od_opts[] ALIGN1 = "aBbcDdeFfHhIiLlOoXxsv"; static const char od_o2si[] ALIGN1 = { 0, 1, 2, 3, 5, /* aBbcD */ 4, 6, 6, 7, 8, /* deFfH */ - 9, 10, 11, 10, 10, /* hIiLl */ - 12, 1, 8, 9, 13 /* OoXxs */ + 9, L_, 10, L_, L_, /* hIiLl */ + 11, 1, 8, 9, 12 /* OoXxs */ }; int od_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; diff --git a/coreutils/od_bloaty.c b/coreutils/od_bloaty.c index 2782adbf6..e886a4ed2 100644 --- a/coreutils/od_bloaty.c +++ b/coreutils/od_bloaty.c @@ -1257,11 +1257,15 @@ int od_main(int argc UNUSED_PARAM, char **argv) if (opt & OPT_f) decode_format_string("fF"); if (opt & (OPT_h|OPT_x)) decode_format_string("x2"); if (opt & (OPT_H|OPT_X)) decode_format_string("xI"); + /* -I,L,l: depend on word width of the arch (what is "long"?) */ +#if ULONG_MAX > 0xffffffff if (opt & OPT_i) decode_format_string("dI"); + if (opt & (OPT_I|OPT_l|OPT_L)) decode_format_string("dL"); +#else + /* 32-bit arch: -I,L,l are the same as -i */ + if (opt & (OPT_i|OPT_I|OPT_l|OPT_L)) decode_format_string("dI"); +#endif if (opt & OPT_j) n_bytes_to_skip = xstrtooff_sfx(str_j, 0, bkm_suffixes); - /* This probably also depends on word width of the arch (what is "long"?) */ - /* should be "d4" or "d8" depending on sizeof(long)? */ - if (opt & (OPT_I|OPT_l|OPT_L)) decode_format_string("d8"); if (opt & (OPT_o|OPT_B)) decode_format_string("o2"); if (opt & OPT_O) decode_format_string("oI"); while (lst_t) { diff --git a/testsuite/od.tests b/testsuite/od.tests index fce66efbb..4f245a7e8 100755 --- a/testsuite/od.tests +++ b/testsuite/od.tests @@ -8,11 +8,11 @@ input="$(printf '\001\002\003\nABC\xfe')" -le=false -{ printf '\0\1' | od -s | grep -q 256; } && le=true -readonly le +little_endian=false +{ printf '\0\1' | od -s | grep -q 256; } && little_endian=true +readonly little_endian -$le || SKIP=1 +$little_endian || SKIP=1 testing "od (little-endian)" \ "od" \ "\ @@ -70,7 +70,7 @@ testing "od -B" \ "" "$input" SKIP= -$le || SKIP=1 +$little_endian || SKIP=1 testing "od -o (little-endian)" \ "od -o" \ "\ @@ -98,7 +98,7 @@ testing "od -c" \ "" "$input" SKIP= -$le || SKIP=1 +$little_endian || SKIP=1 testing "od -d (little-endian)" \ "od -d" \ "\ @@ -108,7 +108,7 @@ testing "od -d (little-endian)" \ "" "$input" SKIP= -$le || SKIP=1 +$little_endian || SKIP=1 testing "od -D (little-endian)" \ "od -D" \ "\ @@ -119,7 +119,7 @@ testing "od -D (little-endian)" \ SKIP= optional !DESKTOP #DESKTOP: unrecognized option: e -$le || SKIP=1 +$little_endian || SKIP=1 testing "od -e (!DESKTOP little-endian)" \ "od -e" \ "\ @@ -130,7 +130,7 @@ testing "od -e (!DESKTOP little-endian)" \ SKIP= optional !DESKTOP #DESKTOP: unrecognized option: F -$le || SKIP=1 +$little_endian || SKIP=1 testing "od -F (!DESKTOP little-endian)" \ "od -F" \ "\ @@ -140,7 +140,7 @@ testing "od -F (!DESKTOP little-endian)" \ "" "$input" SKIP= -$le || SKIP=1 +$little_endian || SKIP=1 testing "od -f (little-endian)" \ "od -f" \ "\ @@ -150,7 +150,7 @@ testing "od -f (little-endian)" \ "" "$input" SKIP= -$le || SKIP=1 +$little_endian || SKIP=1 testing "od -H (little-endian)" \ "od -H" \ "\ @@ -160,7 +160,7 @@ testing "od -H (little-endian)" \ "" "$input" SKIP= -$le || SKIP=1 +$little_endian || SKIP=1 testing "od -X (little-endian)" \ "od -X" \ "\ @@ -170,7 +170,7 @@ testing "od -X (little-endian)" \ "" "$input" SKIP= -$le || SKIP=1 +$little_endian || SKIP=1 testing "od -h (little-endian)" \ "od -h" \ "\ @@ -180,7 +180,7 @@ testing "od -h (little-endian)" \ "" "$input" SKIP= -$le || SKIP=1 +$little_endian || SKIP=1 testing "od -x (little-endian)" \ "od -x" \ "\ @@ -190,7 +190,7 @@ testing "od -x (little-endian)" \ "" "$input" SKIP= -$le || SKIP=1 +$little_endian || SKIP=1 testing "od -i (little-endian)" \ "od -i" \ "\ @@ -200,7 +200,7 @@ testing "od -i (little-endian)" \ "" "$input" SKIP= -$le || SKIP=1 +$little_endian || SKIP=1 testing "od -O (little-endian)" \ "od -O" \ "\ @@ -210,8 +210,9 @@ testing "od -O (little-endian)" \ "" "$input" SKIP= -# This probably also depends on word width of the arch (what is "long"?) -$le || SKIP=1 +# 32-bit? +printf '00000000' | od -l | grep -q '808464432 *808464432' && SKIP=1 #yes, skip +$little_endian || SKIP=1 testing "od -I (little-endian)" \ "od -I" \ "\ From vda.linux at googlemail.com Sat May 27 12:52:17 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Sat, 27 May 2023 14:52:17 +0200 Subject: [git commit] libbb/dump: make xxd_displayoff member conditional on xxd Message-ID: <20230527125249.3FB68867BC@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=9225f9684fedd5c997fc729fee29f8ac402b8db9 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master With xxd not selected: function old new delta display 1459 1444 -15 Signed-off-by: Denys Vlasenko --- include/dump.h | 8 ++++---- libbb/dump.c | 12 ++++++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/include/dump.h b/include/dump.h index 8fb92f07b..c6763a64d 100644 --- a/include/dump.h +++ b/include/dump.h @@ -33,14 +33,14 @@ typedef struct dumper_t { int dump_length; /* max bytes to read */ smallint dump_vflag; /*enum dump_vflag_t*/ FS *fshead; -#if ENABLE_XXD - const char *xxd_eofstring; -#endif #if ENABLE_OD const char *od_eofstring; #endif - off_t address; /* address/offset in stream */ +#if ENABLE_XXD + const char *xxd_eofstring; long long xxd_displayoff; +#endif + off_t address; /* address/offset in stream */ } dumper_t; dumper_t* alloc_dumper(void) FAST_FUNC; diff --git a/libbb/dump.c b/libbb/dump.c index 49340b5a5..70f15c9bd 100644 --- a/libbb/dump.c +++ b/libbb/dump.c @@ -590,7 +590,11 @@ static NOINLINE void display(priv_dumper_t* dumper) } switch (pr->flags) { case F_ADDRESS: - printf(pr->fmt, (unsigned long long) dumper->pub.address + dumper->pub.xxd_displayoff); + printf(pr->fmt, (unsigned long long) dumper->pub.address +#if ENABLE_XXD + + dumper->pub.xxd_displayoff +#endif + ); break; case F_BPAD: printf(pr->fmt, ""); @@ -699,7 +703,11 @@ static NOINLINE void display(priv_dumper_t* dumper) for (pr = dumper->endfu->nextpr; pr; pr = pr->nextpr) { switch (pr->flags) { case F_ADDRESS: - printf(pr->fmt, (unsigned long long) dumper->eaddress + dumper->pub.xxd_displayoff); + printf(pr->fmt, (unsigned long long) dumper->eaddress +#if ENABLE_XXD + + dumper->pub.xxd_displayoff +#endif + ); break; case F_TEXT: fputs_stdout(pr->fmt); From vda.linux at googlemail.com Sat May 27 14:17:38 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Sat, 27 May 2023 16:17:38 +0200 Subject: [git commit] awk: fix splitting with default FS Message-ID: <20230527141747.5E2AF86815@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=84ff1825dd82e8de45020e3def34d1430d8e5a99 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta awk_split 543 544 +1 Signed-off-by: Denys Vlasenko --- editors/awk.c | 13 ++++++++----- testsuite/awk.tests | 7 +++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/editors/awk.c b/editors/awk.c index 2af823808..b3748b502 100644 --- a/editors/awk.c +++ b/editors/awk.c @@ -2049,13 +2049,17 @@ static int awk_split(const char *s, node *spl, char **slist) } return n; } - /* space split */ + /* space split: "In the special case that FS is a single space, + * fields are separated by runs of spaces and/or tabs and/or newlines" + */ while (*s) { - s = skip_whitespace(s); + /* s = skip_whitespace(s); -- WRONG (also skips \v \f \r) */ + while (*s == ' ' || *s == '\t' || *s == '\n') + s++; if (!*s) break; n++; - while (*s && !isspace(*s)) + while (*s && !(*s == ' ' || *s == '\t' || *s == '\n')) *s1++ = *s++; *s1++ = '\0'; } @@ -2304,7 +2308,6 @@ static int awk_getline(rstream *rsm, var *v) setvar_i(intvar[ERRNO], errno); } b[p] = '\0'; - } while (p > pp); if (p == 0) { @@ -3145,7 +3148,7 @@ static var *evaluate(node *op, var *res) /* 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 source is a temporary string, just relink it to dest */ if (R.v == TMPVAR1 && !(R.v->type & VF_NUMBER) /* Why check !NUMBER? if R.v is a number but has cached R.v->string, diff --git a/testsuite/awk.tests b/testsuite/awk.tests index ddc51047b..8ab1c6891 100755 --- a/testsuite/awk.tests +++ b/testsuite/awk.tests @@ -540,4 +540,11 @@ testing 'awk assign while assign' \ ??? trim/eff : 57.02%/26, 0.00% ??? [cpu000:100%] ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????^C" +# If field separator FS=' ' (default), fields are split only on +# space or tab or linefeed, NOT other whitespace. +testing 'awk does not split on CR (char 13)' \ + "awk '{ \$1=\$0; print }'" \ + 'word1 word2 word3\r word2 word3\r\n' \ + '' 'word1 word2 word3\r' + exit $FAILCOUNT From vda.linux at googlemail.com Sat May 27 16:05:42 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Sat, 27 May 2023 18:05:42 +0200 Subject: [git commit] awk: get rid of one indirection level for iF (input file structure) Message-ID: <20230527162811.3E437868CB@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=528808bcd25f7d237874dc82fad2adcddf354b42 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta try_to_assign - 91 +91 next_input_file 214 216 +2 awk_main 827 826 -1 evaluate 3403 3396 -7 is_assignment 91 - -91 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 1/2 up/down: 93/-99) Total: -6 bytes Signed-off-by: Denys Vlasenko --- editors/awk.c | 78 +++++++++++++++++++++++++++++++---------------------------- 1 file changed, 41 insertions(+), 37 deletions(-) diff --git a/editors/awk.c b/editors/awk.c index b3748b502..22f52417d 100644 --- a/editors/awk.c +++ b/editors/awk.c @@ -546,7 +546,6 @@ struct globals { chain beginseq, mainseq, endseq; chain *seq; node *break_ptr, *continue_ptr; - rstream *iF; xhash *ahash; /* argument names, used only while parsing function bodies */ xhash *fnhash; /* function names, used only in parsing stage */ xhash *vhash; /* variables and arrays */ @@ -579,11 +578,12 @@ struct globals2 { var *intvar[NUM_INTERNAL_VARS]; /* often used */ + rstream iF; + /* former statics from various functions */ char *split_f0__fstrings; - rstream next_input_file__rsm; - smallint next_input_file__files_happen; + smallint next_input_file__input_file_seen; smalluint exitcode; @@ -618,7 +618,6 @@ struct globals2 { #define seq (G1.seq ) #define break_ptr (G1.break_ptr ) #define continue_ptr (G1.continue_ptr) -#define iF (G1.iF ) #define ahash (G1.ahash ) #define fnhash (G1.fnhash ) #define vhash (G1.vhash ) @@ -644,6 +643,7 @@ struct globals2 { #define t_string (G.t_string ) #define t_lineno (G.t_lineno ) #define intvar (G.intvar ) +#define iF (G.iF ) #define fsplitter (G.fsplitter ) #define rsplitter (G.rsplitter ) #define g_buf (G.g_buf ) @@ -2799,7 +2799,7 @@ static NOINLINE var *exec_builtin(node *op, var *res) /* if expr looks like "var=value", perform assignment and return 1, * otherwise return 0 */ -static int is_assignment(const char *expr) +static int try_to_assign(const char *expr) { char *exprc, *val; @@ -2819,39 +2819,44 @@ static int is_assignment(const char *expr) } /* switch to next input file */ -static rstream *next_input_file(void) +static int next_input_file(void) { -#define rsm (G.next_input_file__rsm) -#define files_happen (G.next_input_file__files_happen) - - const char *fname, *ind; +#define input_file_seen (G.next_input_file__input_file_seen) + const char *fname; - if (rsm.F) - fclose(rsm.F); - rsm.F = NULL; - rsm.pos = rsm.adv = 0; + if (iF.F) { + fclose(iF.F); + iF.F = NULL; + iF.pos = iF.adv = 0; + } for (;;) { + const char *ind; + if (getvar_i(intvar[ARGIND])+1 >= getvar_i(intvar[ARGC])) { - if (files_happen) - return NULL; + if (input_file_seen) + return FALSE; fname = "-"; - rsm.F = stdin; + iF.F = stdin; break; } ind = getvar_s(incvar(intvar[ARGIND])); fname = getvar_s(findvar(iamarray(intvar[ARGV]), ind)); - if (fname && *fname && !is_assignment(fname)) { - rsm.F = xfopen_stdin(fname); + if (fname && *fname) { + /* "If a filename on the command line has the form + * var=val it is treated as a variable assignment" + */ + if (try_to_assign(fname)) + continue; + iF.F = xfopen_stdin(fname); break; } } - files_happen = TRUE; setvar_s(intvar[FILENAME], fname); - return &rsm; -#undef rsm -#undef files_happen + input_file_seen = TRUE; + return TRUE; +#undef input_file_seen } /* @@ -3231,12 +3236,12 @@ static var *evaluate(node *op, var *res) } } } else { - if (!iF) - iF = next_input_file(); - rsm = iF; + if (!iF.F) + next_input_file(); + rsm = &iF; } - if (!rsm || !rsm->F) { + if (!rsm->F) { setvar_i(intvar[ERRNO], errno); setvar_i(res, -1); break; @@ -3659,7 +3664,7 @@ int awk_main(int argc UNUSED_PARAM, char **argv) setvar_s(intvar[FS], opt_F); } while (list_v) { - if (!is_assignment(llist_pop(&list_v))) + if (!try_to_assign(llist_pop(&list_v))) bb_show_usage(); } @@ -3718,15 +3723,14 @@ int awk_main(int argc UNUSED_PARAM, char **argv) awk_exit(); /* input file could already be opened in BEGIN block */ - if (!iF) - iF = next_input_file(); - - /* passing through input files */ - while (iF) { + if (!iF.F) + goto next_file; /* no, it wasn't, go try opening */ + /* Iterate over input files */ + for (;;) { nextfile = FALSE; setvar_i(intvar[FNR], 0); - while ((i = awk_getline(iF, intvar[F0])) > 0) { + while ((i = awk_getline(&iF, intvar[F0])) > 0) { nextrec = FALSE; incvar(intvar[NR]); incvar(intvar[FNR]); @@ -3735,11 +3739,11 @@ int awk_main(int argc UNUSED_PARAM, char **argv) if (nextfile) break; } - if (i < 0) syntax_error(strerror(errno)); - - iF = next_input_file(); + next_file: + if (!next_input_file()) + break; } awk_exit(); From vda.linux at googlemail.com Sat May 27 16:21:38 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Sat, 27 May 2023 18:21:38 +0200 Subject: [git commit] awk: remove a local variable "caching" a struct member Message-ID: <20230527162811.48F02868CE@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=5c8a9dfd976493e4351abadf6686b621763b564c branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master Since we take its address, the variable lives on stack (not a GPR). Thus, nothing is improved by caching it. function old new delta awk_getline 642 639 -3 Signed-off-by: Denys Vlasenko --- editors/awk.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/editors/awk.c b/editors/awk.c index 22f52417d..4a0eb9281 100644 --- a/editors/awk.c +++ b/editors/awk.c @@ -2236,7 +2236,7 @@ static int awk_getline(rstream *rsm, var *v) { char *b; regmatch_t pmatch[1]; - int size, a, p, pp = 0; + int a, p, pp = 0; int fd, so, eo, r, rp; char c, *m, *s; @@ -2249,12 +2249,11 @@ static int awk_getline(rstream *rsm, var *v) m = rsm->buffer; a = rsm->adv; p = rsm->pos; - size = rsm->size; c = (char) rsplitter.n.info; rp = 0; if (!m) - m = qrealloc(m, 256, &size); + m = qrealloc(m, 256, &rsm->size); do { b = m + a; @@ -2298,10 +2297,10 @@ static int awk_getline(rstream *rsm, var *v) a = 0; } - m = qrealloc(m, a+p+128, &size); + m = qrealloc(m, a+p+128, &rsm->size); b = m + a; pp = p; - p += safe_read(fd, b+p, size-p-1); + p += safe_read(fd, b+p, rsm->size - p - 1); if (p < pp) { p = 0; r = 0; @@ -2325,7 +2324,6 @@ static int awk_getline(rstream *rsm, var *v) rsm->buffer = m; rsm->adv = a + eo; rsm->pos = p - eo; - rsm->size = size; debug_printf_eval("returning from %s(): %d\n", __func__, r); From vda.linux at googlemail.com Sat May 27 17:11:28 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Sat, 27 May 2023 19:11:28 +0200 Subject: [git commit] awk: do not read ARGIND, only set it (gawk compat) Message-ID: <20230527171206.293C18693F@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=21dce1c3c3d74a60959b6d8b0c76f38d463b8187 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta next_input_file 216 243 +27 evaluate 3396 3402 +6 awk_main 826 829 +3 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 36/0) Total: 36 bytes Signed-off-by: Denys Vlasenko --- editors/awk.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/editors/awk.c b/editors/awk.c index 4a0eb9281..77e0b0aab 100644 --- a/editors/awk.c +++ b/editors/awk.c @@ -583,6 +583,7 @@ struct globals2 { /* former statics from various functions */ char *split_f0__fstrings; + unsigned next_input_file__argind; smallint next_input_file__input_file_seen; smalluint exitcode; @@ -2820,6 +2821,7 @@ static int try_to_assign(const char *expr) static int next_input_file(void) { #define input_file_seen (G.next_input_file__input_file_seen) +#define argind (G.next_input_file__argind) const char *fname; if (iF.F) { @@ -2829,17 +2831,22 @@ static int next_input_file(void) } for (;;) { - const char *ind; - - if (getvar_i(intvar[ARGIND])+1 >= getvar_i(intvar[ARGC])) { + /* GNU Awk 5.1.1 does not _read_ ARGIND (but does read ARGC). + * It only sets ARGIND to 1, 2, 3... for every command-line filename + * (VAR=VAL params cause a gap in numbering). + * If there are none and stdin is used, then ARGIND is not modified: + * if it is set by e.g. 'BEGIN { ARGIND="foo" }', that value will + * still be there. + */ + argind++; + if (argind >= getvar_i(intvar[ARGC])) { if (input_file_seen) return FALSE; fname = "-"; iF.F = stdin; break; } - ind = getvar_s(incvar(intvar[ARGIND])); - fname = getvar_s(findvar(iamarray(intvar[ARGV]), ind)); + fname = getvar_s(findvar(iamarray(intvar[ARGV]), utoa(argind))); if (fname && *fname) { /* "If a filename on the command line has the form * var=val it is treated as a variable assignment" @@ -2847,6 +2854,7 @@ static int next_input_file(void) if (try_to_assign(fname)) continue; iF.F = xfopen_stdin(fname); + setvar_i(intvar[ARGIND], argind); break; } } @@ -2854,6 +2862,7 @@ static int next_input_file(void) setvar_s(intvar[FILENAME], fname); input_file_seen = TRUE; return TRUE; +#undef argind #undef input_file_seen } From vda.linux at googlemail.com Sun May 28 15:25:56 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Sun, 28 May 2023 17:25:56 +0200 Subject: [git commit] awk: fix closing of non-opened file Message-ID: <20230528160906.E35A786988@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=b76b420b5da1aadad823faf12327b610614f5951 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta setvar_ERRNO - 53 +53 .rodata 105252 105246 -6 awk_getline 639 620 -19 evaluate 3402 3377 -25 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/3 up/down: 53/-50) Total: 3 bytes Signed-off-by: Denys Vlasenko --- editors/awk.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/editors/awk.c b/editors/awk.c index 77e0b0aab..83a08aa95 100644 --- a/editors/awk.c +++ b/editors/awk.c @@ -1006,6 +1006,11 @@ static var *setvar_i(var *v, double value) return v; } +static void setvar_ERRNO(void) +{ + setvar_i(intvar[ERRNO], errno); +} + static const char *getvar_s(var *v) { /* if v is numeric and has no cached string, convert it to string */ @@ -2305,7 +2310,7 @@ static int awk_getline(rstream *rsm, var *v) if (p < pp) { p = 0; r = 0; - setvar_i(intvar[ERRNO], errno); + setvar_ERRNO(); } b[p] = '\0'; } while (p > pp); @@ -3249,7 +3254,7 @@ static var *evaluate(node *op, var *res) } if (!rsm->F) { - setvar_i(intvar[ERRNO], errno); + setvar_ERRNO(); setvar_i(res, -1); break; } @@ -3388,16 +3393,18 @@ static var *evaluate(node *op, var *res) */ if (rsm->F) err = rsm->is_pipe ? pclose(rsm->F) : fclose(rsm->F); -//TODO: fix this case: -// $ awk 'BEGIN { print close(""); print ERRNO }' -// -1 -// close of redirection that was never opened -// (we print 0, 0) free(rsm->buffer); hash_remove(fdhash, L.s); + } else { + err = -1; + /* gawk 'BEGIN { print close(""); print ERRNO }' + * -1 + * close of redirection that was never opened + */ + errno = ENOENT; } if (err) - setvar_i(intvar[ERRNO], errno); + setvar_ERRNO(); R_d = (double)err; break; } From vda.linux at googlemail.com Sun May 28 15:51:59 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Sun, 28 May 2023 17:51:59 +0200 Subject: [git commit] awk: code shrink Message-ID: <20230528160906.EEE398699D@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=05e60007d42b8e4005085a22e122ef70bf888fa5 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta awk_getline 620 591 -29 Signed-off-by: Denys Vlasenko --- editors/awk.c | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/editors/awk.c b/editors/awk.c index 83a08aa95..eb419e063 100644 --- a/editors/awk.c +++ b/editors/awk.c @@ -2242,9 +2242,9 @@ static int awk_getline(rstream *rsm, var *v) { char *b; regmatch_t pmatch[1]; - int a, p, pp = 0; - int fd, so, eo, r, rp; - char c, *m, *s; + int p, pp; + int fd, so, eo, retval, rp; + char *m, *s; debug_printf_eval("entered %s()\n", __func__); @@ -2253,22 +2253,22 @@ static int awk_getline(rstream *rsm, var *v) */ fd = fileno(rsm->F); m = rsm->buffer; - a = rsm->adv; - p = rsm->pos; - c = (char) rsplitter.n.info; - rp = 0; - if (!m) m = qrealloc(m, 256, &rsm->size); + p = rsm->pos; + rp = 0; + pp = 0; do { - b = m + a; + b = m + rsm->adv; so = eo = p; - r = 1; + retval = 1; if (p > 0) { + char c = (char) rsplitter.n.info; if (rsplitter.n.info == TI_REGEXP) { if (regexec(icase ? rsplitter.n.r.ire : rsplitter.n.l.re, - b, 1, pmatch, 0) == 0) { + b, 1, pmatch, 0) == 0 + ) { so = pmatch[0].rm_so; eo = pmatch[0].rm_eo; if (b[eo] != '\0') @@ -2297,43 +2297,44 @@ static int awk_getline(rstream *rsm, var *v) } } - if (a > 0) { - memmove(m, m+a, p+1); + if (rsm->adv > 0) { + memmove(m, m+rsm->adv, p+1); b = m; - a = 0; + rsm->adv = 0; } - m = qrealloc(m, a+p+128, &rsm->size); - b = m + a; + b = m = qrealloc(m, p+128, &rsm->size); pp = p; p += safe_read(fd, b+p, rsm->size - p - 1); if (p < pp) { p = 0; - r = 0; + retval = 0; setvar_ERRNO(); } b[p] = '\0'; } while (p > pp); if (p == 0) { - r--; + retval--; } else { - c = b[so]; b[so] = '\0'; + char c = b[so]; + b[so] = '\0'; setvar_s(v, b+rp); v->type |= VF_USER; b[so] = c; - c = b[eo]; b[eo] = '\0'; + c = b[eo]; + b[eo] = '\0'; setvar_s(intvar[RT], b+so); b[eo] = c; } rsm->buffer = m; - rsm->adv = a + eo; + rsm->adv += eo; rsm->pos = p - eo; - debug_printf_eval("returning from %s(): %d\n", __func__, r); + debug_printf_eval("returning from %s(): %d\n", __func__, retval); - return r; + return retval; } /* formatted output into an allocated buffer, return ptr to buffer */ From vda.linux at googlemail.com Sun May 28 16:08:06 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Sun, 28 May 2023 18:08:06 +0200 Subject: [git commit] awk: shrink - use setvar_sn() to set variables from non-NUL terminated strings Message-ID: <20230528160907.05B138699F@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=4d7339204f9f823f592562d9903db3ae79a6c640 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta setvar_sn - 39 +39 exec_builtin 1145 1136 -9 awk_getline 591 559 -32 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/2 up/down: 39/-41) Total: -2 bytes Signed-off-by: Denys Vlasenko --- editors/awk.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/editors/awk.c b/editors/awk.c index eb419e063..b5774a339 100644 --- a/editors/awk.c +++ b/editors/awk.c @@ -979,6 +979,11 @@ static var *setvar_s(var *v, const char *value) return setvar_p(v, (value && *value) ? xstrdup(value) : NULL); } +static var *setvar_sn(var *v, const char *value, int len) +{ + return setvar_p(v, (value && *value && len > 0) ? xstrndup(value, len) : NULL); +} + /* same as setvar_s but sets USER flag */ static var *setvar_u(var *v, const char *value) { @@ -2317,15 +2322,9 @@ static int awk_getline(rstream *rsm, var *v) if (p == 0) { retval--; } else { - char c = b[so]; - b[so] = '\0'; - setvar_s(v, b+rp); + setvar_sn(v, b+rp, so-rp); v->type |= VF_USER; - b[so] = c; - c = b[eo]; - b[eo] = '\0'; - setvar_s(intvar[RT], b+so); - b[eo] = c; + setvar_sn(intvar[RT], b+so, eo-so); } rsm->buffer = m; @@ -2677,8 +2676,6 @@ static NOINLINE var *exec_builtin(node *op, var *res) } case B_ss: { - char *s; - l = strlen(as[0]); i = getvar_i(av[1]) - 1; if (i > l) @@ -2688,8 +2685,7 @@ static NOINLINE var *exec_builtin(node *op, var *res) n = (nargs > 2) ? getvar_i(av[2]) : l-i; if (n < 0) n = 0; - s = xstrndup(as[0]+i, n); - setvar_p(res, s); + setvar_sn(res, as[0]+i, n); break; } @@ -2766,8 +2762,7 @@ static NOINLINE var *exec_builtin(node *op, var *res) i = strftime(g_buf, MAXVARFMT, ((nargs > 0) ? as[0] : "%a %b %d %H:%M:%S %Z %Y"), localtime(&tt)); - g_buf[i] = '\0'; - setvar_s(res, g_buf); + setvar_sn(res, g_buf, i); break; case B_mt: From vda.linux at googlemail.com Sun May 28 11:32:07 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Sun, 28 May 2023 13:32:07 +0200 Subject: [git commit] libbb/dump: code shrink Message-ID: <20230528160906.D91C086986@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=9790eb73c8b7ed1a1015f58e1fe85de0508c0526 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta .rodata 105252 105246 -6 Signed-off-by: Denys Vlasenko --- libbb/dump.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/libbb/dump.c b/libbb/dump.c index 70f15c9bd..b406a2428 100644 --- a/libbb/dump.c +++ b/libbb/dump.c @@ -47,8 +47,10 @@ typedef struct priv_dumper_t { static const char dot_flags_width_chars[] ALIGN1 = ".#-+ 0123456789"; static const char size_conv_str[] ALIGN1 = -"\x1\x4\x4\x4\x4\x4\x4\x8\x8\x8\x8\010cdiouxXeEfgG"; - +"\x1\x4\x4\x4\x4\x4\x4\x8\x8\x8\x8\x8""cdiouxXeEfgG"; +/* c d i o u x X e E f g G - bytes contain 'bcnt' for the type */ +#define SCS_OFS 12 +#define float_convs (size_conv_str + SCS_OFS + sizeof("cdiouxX")-1) static const char int_convs[] ALIGN1 = "diouxX"; dumper_t* FAST_FUNC alloc_dumper(void) @@ -88,7 +90,7 @@ static NOINLINE int bb_dump_size(FS *fs) while (isdigit(*++fmt)) continue; } - p = strchr(size_conv_str + 12, *fmt); + p = strchr(size_conv_str + SCS_OFS, *fmt); if (!p) { if (*fmt == 's') { bcnt += prec; @@ -100,7 +102,7 @@ static NOINLINE int bb_dump_size(FS *fs) } } } else { - bcnt += p[-12]; + bcnt += p[-SCS_OFS]; } } cur_size += bcnt * fu->reps; @@ -204,7 +206,7 @@ static NOINLINE void rewrite(priv_dumper_t *dumper, FS *fs) if (strchr(int_convs, *p1)) { /* %d etc */ goto DO_INT_CONV; } else - if (strchr("eEfgG", *p1)) { /* floating point */ + if (strchr(float_convs, *p1)) { /* floating point */ pr->flags = F_DBL; byte_count_str = "\010\004"; goto DO_BYTE_COUNT; From vda.linux at googlemail.com Mon May 29 08:55:40 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Mon, 29 May 2023 10:55:40 +0200 Subject: [git commit] awk: printf(INVALID_FMT) prints it verbatim Message-ID: <20230529090920.6D2F886A2F@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=721bf6eaf4739a2865b071b38d3478f334234d26 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta awk_printf 628 640 +12 Signed-off-by: Denys Vlasenko --- editors/awk.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/editors/awk.c b/editors/awk.c index b5774a339..c49ad6e02 100644 --- a/editors/awk.c +++ b/editors/awk.c @@ -2389,7 +2389,7 @@ static char *awk_printf(node *n, size_t *len) while (1) { if (isalpha(c)) break; - if (c == '*') + if (c == '*') /* gawk supports %*d and %*.*f, we don't... */ syntax_error("%*x formats are not supported"); c = *++f; if (!c) { /* "....%...." and no letter found after % */ @@ -2422,12 +2422,18 @@ static char *awk_printf(node *n, size_t *len) double d = getvar_i(arg); if (strchr("diouxX", c)) { //TODO: make it wider here (%x -> %llx etc)? +//Can even print the value into a temp string with %.0f, +//then replace diouxX with s and print that string. +//This will correctly print even very large numbers, +//but some replacements are not equivalent: +//%09d -> %09s: breaks zero-padding; +//%+d -> %+s: won't prepend +; etc s = xasprintf(s, (int)d); } else if (strchr("eEfFgGaA", c)) { s = xasprintf(s, d); } else { -//TODO: GNU Awk 5.0.1: printf "%W" prints "%W", does not error out - syntax_error(EMSG_INV_FMT); + /* gawk 5.1.1 printf("%W") prints "%W", does not error out */ + s = xstrndup(s, f - s); } } slen = strlen(s); From vda.linux at googlemail.com Mon May 29 12:47:10 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Mon, 29 May 2023 14:47:10 +0200 Subject: [git commit] tunctl: code shrink Message-ID: <20230529124739.BC10786A33@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=fe0b7985483a93d3416e0e5c9e761b6ee1ba310b branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master function old new delta .rodata 105246 105243 -3 tunctl_main 349 344 -5 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-8) Total: -8 bytes Signed-off-by: Denys Vlasenko --- networking/tunctl.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/networking/tunctl.c b/networking/tunctl.c index 97e6917aa..28571ae7f 100644 --- a/networking/tunctl.c +++ b/networking/tunctl.c @@ -124,8 +124,7 @@ int tunctl_main(int argc UNUSED_PARAM, char **argv) if (opts & OPT_b) { puts(ifr.ifr_name); } else { - printf("Set '%s' %spersistent", ifr.ifr_name, ""); - printf(" and owned by uid %ld", user); + printf("Set '%s' persistent and owned by uid %ld", ifr.ifr_name, user); if (group != -1) printf(" gid %ld", group); bb_putchar('\n'); From vda.linux at googlemail.com Tue May 30 14:44:04 2023 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Tue, 30 May 2023 16:44:04 +0200 Subject: [git commit] awk: fix precedence of = relative to == Message-ID: <20230530144706.7D51386A6A@busybox.osuosl.org> commit: https://git.busybox.net/busybox/commit/?id=0256e00a9d077588bd3a39f5a1ef7e2eaa2911e4 branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master Discovered while adding code to disallow assignments to non-lvalues function old new delta parse_expr 936 991 +55 .rodata 105243 105247 +4 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 59/0) Total: 59 bytes Signed-off-by: Denys Vlasenko --- editors/awk.c | 66 ++++++++++++++++++++++++++++++++++++----------------- testsuite/awk.tests | 5 ++++ 2 files changed, 50 insertions(+), 21 deletions(-) diff --git a/editors/awk.c b/editors/awk.c index c49ad6e02..0f062dcdb 100644 --- a/editors/awk.c +++ b/editors/awk.c @@ -337,7 +337,9 @@ static void debug_parse_print_tc(uint32_t n) #undef P #undef PRIMASK #undef PRIMASK2 -#define P(x) (x << 24) +/* Smaller 'x' means _higher_ operator precedence */ +#define PRECEDENCE(x) (x << 24) +#define P(x) PRECEDENCE(x) #define PRIMASK 0x7F000000 #define PRIMASK2 0x7E000000 @@ -360,7 +362,7 @@ enum { OC_MOVE = 0x1f00, OC_PGETLINE = 0x2000, OC_REGEXP = 0x2100, OC_REPLACE = 0x2200, OC_RETURN = 0x2300, OC_SPRINTF = 0x2400, OC_TERNARY = 0x2500, OC_UNARY = 0x2600, OC_VAR = 0x2700, - OC_DONE = 0x2800, + OC_CONST = 0x2800, OC_DONE = 0x2900, ST_IF = 0x3000, ST_DO = 0x3100, ST_FOR = 0x3200, ST_WHILE = 0x3300 @@ -440,9 +442,9 @@ static const uint32_t tokeninfo[] ALIGN4 = { #define TI_PREINC (OC_UNARY|xV|P(9)|'P') #define TI_PREDEC (OC_UNARY|xV|P(9)|'M') TI_PREINC, TI_PREDEC, OC_FIELD|xV|P(5), - OC_COMPARE|VV|P(39)|5, OC_MOVE|VV|P(74), OC_REPLACE|NV|P(74)|'+', OC_REPLACE|NV|P(74)|'-', - OC_REPLACE|NV|P(74)|'*', OC_REPLACE|NV|P(74)|'/', OC_REPLACE|NV|P(74)|'%', OC_REPLACE|NV|P(74)|'&', - OC_BINARY|NV|P(29)|'+', OC_BINARY|NV|P(29)|'-', OC_REPLACE|NV|P(74)|'&', OC_BINARY|NV|P(15)|'&', + OC_COMPARE|VV|P(39)|5, OC_MOVE|VV|P(38), OC_REPLACE|NV|P(38)|'+', OC_REPLACE|NV|P(38)|'-', + OC_REPLACE|NV|P(38)|'*', OC_REPLACE|NV|P(38)|'/', OC_REPLACE|NV|P(38)|'%', OC_REPLACE|NV|P(38)|'&', + OC_BINARY|NV|P(29)|'+', OC_BINARY|NV|P(29)|'-', OC_REPLACE|NV|P(38)|'&', OC_BINARY|NV|P(15)|'&', OC_BINARY|NV|P(25)|'/', OC_BINARY|NV|P(25)|'%', OC_BINARY|NV|P(15)|'&', OC_BINARY|NV|P(25)|'*', OC_COMPARE|VV|P(39)|4, OC_COMPARE|VV|P(39)|3, OC_COMPARE|VV|P(39)|0, OC_COMPARE|VV|P(39)|1, #define TI_LESS (OC_COMPARE|VV|P(39)|2) @@ -1301,7 +1303,7 @@ static uint32_t next_token(uint32_t expected) save_tclass = tc; save_info = t_info; tc = TC_BINOPX; - t_info = OC_CONCAT | SS | P(35); + t_info = OC_CONCAT | SS | PRECEDENCE(35); } t_tclass = tc; @@ -1361,9 +1363,8 @@ static node *parse_expr(uint32_t term_tc) { node sn; node *cn = &sn; - node *vn, *glptr; + node *glptr; uint32_t tc, expected_tc; - var *v; debug_printf_parse("%s() term_tc(%x):", __func__, term_tc); debug_parse_print_tc(term_tc); @@ -1374,11 +1375,12 @@ static node *parse_expr(uint32_t term_tc) expected_tc = TS_OPERAND | TS_UOPPRE | TC_REGEXP | term_tc; while (!((tc = next_token(expected_tc)) & term_tc)) { + node *vn; if (glptr && (t_info == TI_LESS)) { /* input redirection (<) attached to glptr node */ debug_printf_parse("%s: input redir\n", __func__); - cn = glptr->l.n = new_node(OC_CONCAT | SS | P(37)); + cn = glptr->l.n = new_node(OC_CONCAT | SS | PRECEDENCE(37)); cn->a.n = glptr; expected_tc = TS_OPERAND | TS_UOPPRE; glptr = NULL; @@ -1390,24 +1392,42 @@ static node *parse_expr(uint32_t term_tc) * previous operators with higher priority */ vn = cn; while (((t_info & PRIMASK) > (vn->a.n->info & PRIMASK2)) - || ((t_info == vn->info) && t_info == TI_COLON) + || (t_info == vn->info && t_info == TI_COLON) ) { vn = vn->a.n; if (!vn->a.n) syntax_error(EMSG_UNEXP_TOKEN); } if (t_info == TI_TERNARY) //TODO: why? - t_info += P(6); + t_info += PRECEDENCE(6); cn = vn->a.n->r.n = new_node(t_info); cn->a.n = vn->a.n; if (tc & TS_BINOP) { cn->l.n = vn; -//FIXME: this is the place to detect and reject assignments to non-lvalues. -//Currently we allow "assignments" to consts and temporaries, nonsense like this: -// awk 'BEGIN { "qwe" = 1 }' -// awk 'BEGIN { 7 *= 7 }' -// awk 'BEGIN { length("qwe") = 1 }' -// awk 'BEGIN { (1+1) += 3 }' + + /* Prevent: + * awk 'BEGIN { "qwe" = 1 }' + * awk 'BEGIN { 7 *= 7 }' + * awk 'BEGIN { length("qwe") = 1 }' + * awk 'BEGIN { (1+1) += 3 }' + */ + /* Assignment? (including *= and friends) */ + if (((t_info & OPCLSMASK) == OC_MOVE) + || ((t_info & OPCLSMASK) == OC_REPLACE) + ) { + debug_printf_parse("%s: MOVE/REPLACE vn->info:%08x\n", __func__, vn->info); + /* Left side is a (variable or array element) + * or function argument + * or $FIELD ? + */ + if ((vn->info & OPCLSMASK) != OC_VAR + && (vn->info & OPCLSMASK) != OC_FNARG + && (vn->info & OPCLSMASK) != OC_FIELD + ) { + syntax_error(EMSG_UNEXP_TOKEN); /* no. bad */ + } + } + expected_tc = TS_OPERAND | TS_UOPPRE | TC_REGEXP; if (t_info == TI_PGETLINE) { /* it's a pipe */ @@ -1443,6 +1463,8 @@ static node *parse_expr(uint32_t term_tc) /* one should be very careful with switch on tclass - * only simple tclasses should be used (TC_xyz, not TS_xyz) */ switch (tc) { + var *v; + case TC_VARIABLE: case TC_ARRAY: debug_printf_parse("%s: TC_VARIABLE | TC_ARRAY\n", __func__); @@ -1463,14 +1485,14 @@ static node *parse_expr(uint32_t term_tc) case TC_NUMBER: case TC_STRING: debug_printf_parse("%s: TC_NUMBER | TC_STRING\n", __func__); - cn->info = OC_VAR; + cn->info = OC_CONST; v = cn->l.v = xzalloc(sizeof(var)); - if (tc & TC_NUMBER) + if (tc & TC_NUMBER) { setvar_i(v, t_double); - else { + } else { setvar_s(v, t_string); - expected_tc &= ~TC_UOPPOST; /* "str"++ is not allowed */ } + expected_tc &= ~TC_UOPPOST; /* NUM++, "str"++ not allowed */ break; case TC_REGEXP: @@ -3124,6 +3146,8 @@ static var *evaluate(node *op, var *res) /* -- recursive node type -- */ + case XC( OC_CONST ): + debug_printf_eval("CONST "); case XC( OC_VAR ): debug_printf_eval("VAR\n"); L.v = op->l.v; diff --git a/testsuite/awk.tests b/testsuite/awk.tests index 8ab1c6891..cdab93d21 100755 --- a/testsuite/awk.tests +++ b/testsuite/awk.tests @@ -547,4 +547,9 @@ testing 'awk does not split on CR (char 13)' \ 'word1 word2 word3\r word2 word3\r\n' \ '' 'word1 word2 word3\r' +testing "awk = has higher precedence than == (despite what gawk manpage claims)" \ + "awk 'BEGIN { v=1; print 2==v; print 2==v=2; print v; print v=3==3; print v}'" \ + '0\n1\n2\n1\n3\n' \ + '' '' + exit $FAILCOUNT From bugzilla at busybox.net Wed May 31 13:59:57 2023 From: bugzilla at busybox.net (bugzilla at busybox.net) Date: Wed, 31 May 2023 13:59:57 +0000 Subject: [Bug 15614] New: ash: case weird behavior with ] character Message-ID: https://bugs.busybox.net/show_bug.cgi?id=15614 Bug ID: 15614 Summary: ash: case weird behavior with ] character Product: Busybox Version: unspecified Hardware: Other OS: Linux Status: NEW Severity: normal Priority: P5 Component: Other Assignee: unassigned at busybox.net Reporter: t_i_a_w_l at yahoo.com CC: busybox-cvs at busybox.net Target Milestone: --- Hello, I installed busybox 1_36_1 from the source code on an alpine 3.18.0 container: $ git clone 'https://git.busybox.net/busybox' /opt/busybox > /dev/null 2>&1 && echo OK OK $ git -C /opt/busybox checkout 1_36_1 > /dev/null 2>&1 && echo OK OK $ make -C /opt/busybox defconfig > /dev/null 2>&1 && echo OK OK $ make -C /opt/busybox busybox > /dev/null 2>&1 && echo OK OK $ make -C /opt/busybox CONFIG_PREFIX=/usr install > /dev/null 2>&1 && echo OK OK $ /usr/bin/busybox | head -n 1 BusyBox v1.36.1 (2023-05-31 13:28:40 UTC) multi-call binary. $ /usr/bin/busybox ash -c 'char="a"; case "$char" in ["$char"]) echo TRUE ;; *) echo FALSE ;; esac' TRUE $ /usr/bin/busybox ash -c 'char="]"; case "$char" in ["$char"]) echo TRUE ;; *) echo FALSE ;; esac' FALSE char variable is double quoted so the value should be interpreted as a string, not a special character. Is this a normal behavior ? Thank you. -- You are receiving this mail because: You are on the CC list for the bug.