zserge / partcl

ParTcl - a micro Tcl implementation
https://zserge.com/posts/tcl-interpreter/
MIT License
470 stars 50 forks source link

Division by Zero #8

Open shrezaei opened 5 years ago

shrezaei commented 5 years ago

After second round of fuzzing, I realized that you do not check division by zero. It is in tcl_cmd_math() function. You can simply add an if statement and solve the problem. Additionally, I suggest that you check arguments of math operation before passing it to tcl_int(). Because you used atoi() function in tcl_int() and it basically convert the digits from the beginning of the string until it reaches any non-digit character. That means, you can pass "22sdfe" (which gives 22) or even "sdfdsf" (which gives 0) and it will work. But, it is better to show an error ("?!" string in your app) to let the user know that.?!