Re: [PATCH] fix:awk: CONVFMT segfaults with %n, wrong output with %p
Hans Ulli Kroll via busybox <[email protected]> Tue, 05 May 2026 14:31:16 +0200
| Newsgroups | gmane.linux.busybox |
|---|---|
| Message-ID | <[email protected]> |
On Tue, 2026-05-05 at 12:54 +0200, Roberto A. Foglietta wrote: > On Tue, 5 May 2026 at 11:15, Hans Ulli Kroll via busybox > <[email protected]> wrote: > > > diff --git a/editors/awk.c b/editors/awk.c > > index dd8f4ac420..b26793e792 100644 > > --- a/editors/awk.c > > +++ b/editors/awk.c > > @@ -969,7 +969,14 @@ static const char *fmt_num(const char *format, double n) > > const char *s = format; > > char c; > > > > - do { c = *s; } while (c && *++s); > > + do { > > + c = *s; > > + if (c == 'n' || c == 'p') { > > + puts(format); > > + exit(0); > > > ./busybox awk 'BEGIN { CONVFMT="%.2f n" ; x=3.14; print x "" }' > Your patch prints: > %.2f n > Instead of > 3.14 n so the whole CONVFMT is a mess. There is *curently* no proper way in busybox to support floating point specifiers > > gawk compliance isn't possible to achieve within busybox constraints > and also useless: > > 1 - as long as awk syntax acceptance is valid also for gawk (awk subset of gawk) > 2 - every unacceptable / rejected syntax provide exit 1 to warning users > 3 - no silent failures or crashed are generated point taken > > Finally, in my V2 patch "p" isn't a numeric identifier but a pointer > (indexing s = format content) > > > + } > > + } while (c && *++s); > > + > > if (strchr("diouxX", c)) { > > snprintf(g_buf, MAXVARFMT, format, (int)n); > > } else if (strchr("eEfFgGaA", c)) { > > -- > > 2.54.0 > > Best regards, R- patch ? Ulli