ThrowTheSwitch / CMock

CMock - Mock/stub generator for C
http://throwtheswitch.org
MIT License
653 stars 269 forks source link

Runaway regular expressions #380

Closed Tschet1 closed 2 years ago

Tschet1 commented 2 years ago

I've run into an issue where generation with CMock takes significant time (multiple minutes for a single mock).

The issue seems to be a runaway regular expression https://www.regular-expressions.info/catastrophic.html

here: https://github.com/ThrowTheSwitch/CMock/blob/3806f7ebe34b17b002b8e2d6b9fdcd72e67c4f24/lib/cmock_header_parser.rb#L503

To recreate, check the following snippet on regex101: https://regex101.com/r/cx91Wh/1

I did not fully understand the meaning of the first part of the regex, but I would propose changing /([\w\s\*]+)+\s+(\w+)\s*\(((?:[\w\s\*]*,?)*)\s*\)*/ to /([\w\s\*]+)\s+(\w+)\s*\(((?:[\w\s\*]*,?)*)\s*\)*/

Tschet1 commented 2 years ago

Proposed fix in https://github.com/ThrowTheSwitch/CMock/pull/381

Tschet1 commented 2 years ago

Fixed in https://github.com/ThrowTheSwitch/CMock/pull/381