-
Notifications
You must be signed in to change notification settings - Fork 450
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
String subscript out of range #151
Comments
Thanks for the detailed report. I agree strip_ws should be changed. Do you have a test case that demonstrates this at the Jsonnet code level? I would like to determine how many people would be affected by this. |
Thanks for the fix. I stumbled upon this when Jsonnet was going through std.jsonnet.h. There are empty lines in the license header. |
Yeah that \n\n would definitely cause strip_ws to be called with a empty string, and that would have affected every execution of Jsonnet. Interestingly, this passes valgrind even with -O0. This seems to be because of the particular std::string implementation, i.e. s[j] == ' ' and friends was reading arbitrary memory inside the string object. I.e. j was essentially -1 so it was looking one byte left from the start of the char block. On my machine (64 bit ubuntu trusty gcc & clang), that caused no problem as the char to the left of the start of the char block was \0 so it immediately exited the loop and returned "". For you, either the std::string internal buffer was a separate malloc'd buffer, or maybe the buffer is nullptr (because it's an empty string) or maybe it walked far enough to walk off the end of the std::string. What OS & compiler did you see this on? thanks |
Sorry about the delay. I am actually compiling it under Windows 10 with VS 2015. I would say this is not the kind of scenario you would like to support, but I have been using Jsonnet flawlessly for a few months for managing configuration, just like you would do with GCL for instance. Thanks |
Windows support sounds great. I tried it myself once but it crashed msvc (the old version I had around at that time). Probably this was due to incomplete c++11 support at that time. I'm glad to hear you can compile it now.
The only problem is lack of automatic testing and additionally the lack of casual use Jsonnet gets in Windows. In particular I'm quite concerned with dos line endings and whether they work properly. |
I was just testing v0.8.8 and ran into a problem at lexer.cpp:35. On strip_ws(const std::string &s, unsigned margin), s can sometimes be an empty string, so size_t j = s.size() - 1 will be an overflow and an error will occur when the code tries to access s[j].
The text was updated successfully, but these errors were encountered: