ThomasDickey / original-mawk

bug-reports for mawk (originally on GoogleCode)
http://invisible-island.net/mawk/mawk.html
17 stars 2 forks source link

SEGV introduced between 20230804->20230808 #71

Closed sthen closed 8 months ago

sthen commented 8 months ago

Seen on OpenBSD -current amd64.

Seems there's a problem with the input buffer resizing done in https://github.com/ThomasDickey/mawk-snapshots/commit/139ba08238f68425ff51daf4deed68f8f8599e05.

The initial report was from somebody using an ugly domain blocklist processor; here's a simpler reproducer:

$ yes | dd count=262144 bs=1 status=none > a
$ mawk '{ print $1 }' a
Segmentation fault (core dumped)
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x000006640d67210e in fillbuff (fd=3, target=0x6662dd36000 <error: Cannot access memory at address 0x6662dd36000>, size=0) at fin.c:413
413         *target = 0;
(gdb) bt
#0  0x000006640d67210e in fillbuff (fd=3, target=0x6662dd36000 <error: Cannot access memory at address 0x6662dd36000>, size=0) at fin.c:413
#1  0x000006640d6714e2 in FINgets (fin=0x666a8410258, len_p=0x772ef7dedfb8) at fin.c:246
#2  0x000006640d6584e2 in execute (cdp=0x666a840ac78, sp=0x6640d67b248 <execute.missing+8>, fp=0x0) at execute.c:1188                                                                                     #3  0x000006640d65411d in main (argc=4, argv=0x772ef7dee108)
at main.c:71
sthen commented 8 months ago

(Seems triggered by any file above 256k)

ThomasDickey commented 8 months ago

thanks - with valgrind I can see a problem which may be the same issue.

ThomasDickey commented 8 months ago

simple fix (which works for the test cases I have at hand):

--- fin.c   2023/08/08 21:57:08 1.51
+++ fin.c   2023/10/31 21:10:12
@@ -410,7 +410,6 @@
    }

   out:
-    *target = 0;
     return (size_t) (entry_size - size);
 }
sthen commented 8 months ago

Thanks - this works for the other cases I've tried too.

ThomasDickey commented 8 months ago

I applied that on top of some other fixes, and will probably upload a new snapshot today or tomorrow.

ThomasDickey commented 8 months ago

done - https://invisible-island.net/mawk/CHANGES.html#t20231102