nickg / nvc

VHDL compiler and simulator
https://www.nickg.me.uk/nvc/
GNU General Public License v3.0
636 stars 80 forks source link

Fix crash on unexpected psl builtin function in primary #1051

Closed NikLeberg closed 2 weeks ago

NikLeberg commented 3 weeks ago

Continuation of the fuzzing crashes found by @avelure. See https://github.com/nickg/nvc/issues/1038#issuecomment-2452959299.

While parsing an unexpected PSL builtin function in a primary nvc does crash on an assertion. I relaxed the assertion to an if check. If the check fails, then the switch falls-through to the already existing error message.

Cheers

nickg commented 3 weeks ago

A neater fix to this would be to define a new tPSLNEXT token so it can't be confused with the VHDL tNEXT. So in lexer.l:

<PSL>{NEXT}              { TOKEN(tNEXT); }

Would be replaced with

<PSL>{PSLNEXT}           { TOKEN(tPSLNEXT); }
nickg commented 2 weeks ago

Need to add "next" to the end of the long array in token_str in src/scan.c, otherwise looks fine.