guybedford / es-module-lexer

Low-overhead lexer dedicated to ES module parsing for fast analysis
MIT License
912 stars 47 forks source link

Possibly memory issue in templateString() #158

Closed connor4312 closed 10 months ago

connor4312 commented 10 months ago

I came across this potential issue when repurposing this module for my own nefarious purposes.

https://github.com/guybedford/es-module-lexer/blob/605184a98713afdd6f3a16d5004c6a9fec136f5f/src/lexer.c#L717-L722

In this function, openTokenStack is not aliased to as an array like it is in parse(). Therefore, if there's an openTokenDepth of 2 for example, it actually writes it at memory offset 2 from the address of openTokenStack rather than 2 * sizeof(OpenToken).

I don't know whether this actually causes any issues for end users.

connor4312 commented 10 months ago

oh, nevermind. My C is rusty and I was misinterpreting a different issue, one of my own causing. Sorry for the noise.