Re: awk: CONVFMT format string causes crash

"Michael D. Setzer II via busybox" <[email protected]> Tue, 5 May 2026 22:34:03 +1000
Newsgroups gmane.linux.busybox
Message-ID <[email protected]>
On 5 May 2026 at 10:59, Hans Ulli Kroll wrote:

Subject:        	Re: Sv: awk: CONVFMT format string causes 
crash
From:           	Hans Ulli Kroll <[email protected]>
To:             	Atle Østrem Tøge <[email protected]>, Busybox
 	<[email protected]>, "[email protected]" 
<[email protected]>
Copies to:      	Sebastian Ellingsen 
<[email protected]>
Date sent:      	Tue, 05 May 2026 10:59:33 +0200

Did a test on letters a - z differences between Awk and Busybox 
Awk. Seems there are 7 differences in outputs? Also differences in 
number Segment faults?

Not sure if this will display correctly on list?

AWK Output
Code
BusyBox AWK Output
Code


a0x1.91eb851eb851fp+1f
                                                                   0
a0x1.91eb851eb851fp+1f
                                                                   0
Same

b%bf
                                                                   0
b11f
                                                                   0
Diff

cf
                                                                   0
cf
                                                                   0
Same

d3f
                                                                   0
d3f
                                                                   0
Same

e3.140000e+00f
                                                                   0
e3.140000e+00f
                                                                   0
Same

f3.140000f
                                                                   0
f3.140000f
                                                                   0
Same

g3.14f
                                                                   0
g3.14f
                                                                   0
Same

h3.140000
                                                                   0
h3.140000
                                                                   0
Same

i3f
                                                                   0
i3f
                                                                   0
Same

j3.140000
                                                                   0
j3.140000
                                                                   0
Same

k%kf
                                                                   0
k%kf
                                                                   0
Same

l3.140000
                                                                   0
l3.140000
                                                                   0
Same

m%mf
                                                                   0
mSuccessf
                                                                   0
Diff

n%nf
                                                                   0
n./testawk2: line 14: 486792 
Segmentation fault         (core 
dumped) busybox awk 'BEGIN 
{ CONVFMT="%nf"; x=3.14; 
print x "" }'
                                                                 139
Diff

o3f
                                                                   0
o3f
                                                                   0
Same

p%pf
                                                                   0
p0x3f
                                                                   0
Diff

q%qf
                                                                   0
qnan
                                                                   0
Diff

r%rf
                                                                   0
r%rf
                                                                   0
Same

s./testawk: line 19: 486869 
Segmentation fault         (core 
dumped) awk 'BEGIN { 
CONVFMT="%sf"; x=3.14; 
print x "" }'
                                                                 139
s./testawk2: line 19: 486807 
Segmentation fault         (core 
dumped) busybox awk 'BEGIN 
{ CONVFMT="%sf"; x=3.14; 
print x "" }'
                                                                 139
Diff

t3.140000
                                                                   0
t3.140000
                                                                   0
Same

u3f
                                                                   0
u3f
                                                                   0
Same

v%vf
                                                                   0
v%vf
                                                                   0
Same

w3.140000
                                                                   0
w
                                                                   0
Diff

x3f
                                                                   0
x3f
                                                                   0
Same

y%yf
                                                                   0
y%yf
                                                                   0
Same

z3.140000
                                                                   0
z3.140000
                                                                   0
Same


So, is Ideal to match Awk output. Also, note s gives segment fault 
on both AWK and Busybox AWK?


> On Fri, 2026-05-01 at 12:21 +0000, Atle Østrem Tøge via busybox wrote:
> > To clarify: %n is a printf conversion specifier that writes the number of
> > bytes written so far to the address of the next argument, it is unrelated
> > to numeric width specifiers like %.2f.
> > 
> > BusyBox awk validates only the last character of CONVFMT,  "%nf" passes
> > (last char 'f' is valid) and the full string reaches snprintf. "%n" alone
> > is correctly rejected.
> > 
> > We reproduced the segfault by building current master (vda-linux/busybox_mirror)
> > against musl libc (Alpine Linux container):
> > 
> >     $ ./busybox awk 'BEGIN { CONVFMT="%nf"; x=3.14; print x "" }'
> >     Segmentation fault
> > 
> > The root cause is in fmt_num() in editors/awk.c.
> > 
> > - Atle
> > 
> > 
> 
> interesting enough gnu awk emits this
> 
> $ awk 'BEGIN { CONVFMT="%nf"; x=3.14; print x "" }'; echo $?
> %nf
> 0
> 
> with CONVFMT and no error.
> 
> also for %p 
> 
> $ awk 'BEGIN { CONVFMT="%pf"; x=3.16; print x "" }'; echo $?
> %pf
> 0
> 
> as for busybox
> $ ./busybox awk 'BEGIN { CONVFMT="%pf"; x=3.16; print x "" }'; echo $?
> 0x3f
> 0
> 
> For both cases I have a patch ready to submit
> 
> Ulli



+------------------------------------------------------------+
 Michael D. Setzer II - Computer Science Instructor (Retired)     
 mailto:[email protected]                            
 mailto:[email protected]
 mailto:[email protected]
 Guam - Where America's Day Begins                        
 G4L Disk Imaging Project maintainer 
 https://sourceforge.net/projects/g4l/ 
+------------------------------------------------------------+

_______________________________________________
busybox mailing list
[email protected]
https://lists.busybox.net/mailman/listinfo/busybox