Open nmeum opened 5 years ago
Recursion limit is a good idea. I will try to see if I can find some time to test that out.
I added a recursion limit in ea778d1b8dabace291453b650808a9773a21d382. Right now it is controlled by a define in the source code but we could also make it defined by some user specified parameter. Of course I don't think it makes mpc completely secure in the slightest but should be a good first line of defense and might help debugging too.
Since
mpc_parse_run
isn't tail recursive it is possible to trigger a stack overflow with input languages allowing infinite nesting. An example of such an input language is the one used byexamples/maths.c
. Consider the following input generation program:And run
maths
as:This is somewhat problematic if mpc is used for parsing a network protocol as it potentially allows a denial-of-service. Not sure if there is any easy way to fix this but including some kind of recursion limit would probably be one way of doing it.