ThomasDickey / original-mawk

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

mawk crashes if the stack size is exceeded #48

Closed dkogan closed 6 years ago

dkogan commented 6 years ago

Hi. Currently if a function is called with too many arguments, mawk crashes. It'd be nice if it at least produced an error message instead of silently dying.

To reproduce:

  1. Create program that prints a whole lot of "1":
perl -e ' print "{ print " . join(",", (1) x 259 ) . "}" ' > /tmp/tst.awk
  1. Run
seq 1 | mawk -f /tmp/tst.awk

On my box (using the latest mawk from Debian) I get a segfault.

The relevant value being exceeded is EVAL_STACK_SIZE.

Thanks

ThomasDickey commented 6 years ago

That's the Debian package which crashes. I tried this with mawk 1.3.4 20161120, and it gave this for output (no crash): 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

ThomasDickey commented 6 years ago

You might want to add this report to the list for Debian's antique.

dkogan commented 6 years ago

Aha. Thanks for that. Before filing the bug I did try to check the bleeding-edge version to see if it crashes. But I couldn't figure out which is the bleeding edge. You have multiple "mawk" repos in github for instance. Is "original-mawk" the bleeding edge?

ThomasDickey commented 6 years ago
----- Original Message ----- From: "Dima Kogan" notifications@github.com To: "ThomasDickey/original-mawk" original-mawk@noreply.github.com Cc: "ThomasDickey" dickey@his.com, "State change" state_change@noreply.github.com Sent: Sunday, October 15, 2017 7:57:58 PM Subject: Re: [ThomasDickey/original-mawk] mawk crashes if the stack size is exceeded (#48)
Aha. Thanks for that. Before filing the bug I did try to check the
bleeding-edge version to see if it crashes. But I couldn't figure
out which is the bleeding edge. You have multiple "mawk" repos in
github for instance. Is "original-mawk" the bleeding edge?

"original-mawk" is just the bug reports. "mawk-snapshots" is what you're looking for. The other (dated ones) were full exports while attempting to appease Debian's ostensible maintainer, and aren't current.

-- Thomas E. Dickey dickey@invisible-island.net http://invisible-island.net ftp://invisible-island.net

dkogan commented 6 years ago

OK. I didn't realize that Debian is shipping a very old mawk. I might join that discussion too, but that's orthogonal to this one.

I just tried the latest snapshot in "mawk-snapshots": t20161120. It shows the issue described here, you just need a larger numbe of '1's. On my Debian box it works with <= 1333 '1's but crashes with >= 1334 '1's. Let me know if you can't reproduce, and I'll dig a bit deeper.

dkogan commented 6 years ago

And I think it's important to mention that this isn't a made-up corner case. I maintain a little application (not free software yet, but soon) that uses mawk internally, and this crash was reported to me as a crash of my tool.

ThomasDickey commented 6 years ago

I took a look, can see why it does that (and am considering how to solve it).

The actual program logic for checking the stack overflow was only in debug-code (and incomplete since it did not account for the separate stack for user-functions). The simple fix is just making those checks work. As an alternative, they could be reallocated rather than exiting with an error message (but I'm not convinced that's necessary).

ThomasDickey commented 6 years ago

fixed in 1.3.4.20171017

dkogan commented 6 years ago

ThomasDickey notifications@github.com writes:

fixed in 1.3.4.20171017

Thanks much.

ThomasDickey commented 6 years ago

no problem