Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RegExp parsing fails on character classes which contain a match for NUL character #560

Open
Fordi opened this issue Jun 30, 2016 · 5 comments

Comments

@Fordi
Copy link

Fordi commented Jun 30, 2016

Attached jslint.js (zipped)
jslint.js.zip

Version: ea633dd

  • Steps to reproduce:

    • Check out clean v7: git clone https://github.com/cesanta/v7.git
    • Build v7 standalone: make v7 'V7_FLAGS+=-DV7_LARGE_AST'
    • Run jslint.js: ./v7 ../jslint.js
    • Run ./v7 -e '/[\x00]/'
  • Expected: About 350 88ms wait, no output, no errors

  • Actual: 35 4ms wait, no output, following error:

    Exec error [bilded/fixture/jslint.js]: "Invalid regex"
    undefined

@Fordi
Copy link
Author

Fordi commented Jun 30, 2016

Tracked down the offending regexp:

var rx_unsafe = /[\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/;

Can get the same result with ./v7 -e '/[\x00]/'

Updating ticket title to reflect real bug.

@Fordi Fordi changed the title Interpretation of JSLint fails with "Invalid regex", no line number or stack trace. RegExp parsing fails on character classes which contain a match for NUL character Jun 30, 2016
@Fordi
Copy link
Author

Fordi commented Jun 30, 2016

I was able to locate the error message, and piece out that slre_compile is returning SLRE_MALFORMED_CHARSET, which implies to me that the escapes are getting preprocessed somewhere? I don't know how to run a debugger in C, so that's about as far as I got, since I got no stack.

@goniz
Copy link

goniz commented Jun 30, 2016

I've encountered this today as well..
this code seems to be present in pure js json parsers as well and gets broken by this issue.

@Fordi
Copy link
Author

Fordi commented Jun 30, 2016

Seems to come down to the fact that "Rune" is a uint_16 and slre_env uses slre_env->curr_rune == 0 as an error flag.

@Fordi
Copy link
Author

Fordi commented Jun 30, 2016

Another RX that throws SLRE_MALFORMED_CHARSET:

/[`\\]/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants