-
Notifications
You must be signed in to change notification settings - Fork 661
Fix segmentations failure in error.c gumbo_caret_diagnostic_to_string #371
base: master
Are you sure you want to change the base?
Fix segmentations failure in error.c gumbo_caret_diagnostic_to_string #371
Conversation
|
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
|
I signed it! |
|
CLAs look good, thanks! |
Without this patch method find_last_newline returns value bigger than find_next_newline and in line `original_line.length = line_end - line_start;` overflow happens. Before changes newly added test failed with segmentation failure: ``` ./test-driver: line 107: 12171 Segmentation fault (core dumped) "$@" > $log_file 2>&1 ``` This slightly changed copy of code used in nokogumbo gem. [Link](https://github.com/rubys/nokogumbo/blob/8b4446847dea5c614759684ebcae4c580c47f4ad/ext/nokogumboc/nokogumbo.c#L230)
5da65e7 to
ef94f4b
Compare
| assert(*c || c == error_location); | ||
| } | ||
| return c == original_text ? c : c + 1; | ||
| return c == original_text || c == error_location ? c : c + 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this actually the correct fix? If *error_location is \n, shouldn't this move to the previous \n (if any)? For example, given the source text "<\n", that line is the one with the error. With your patch, wouldn't original_line in gumbo_caret_diagnostic_to_string() point to the new line and have length 0?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you're right. Actually i did not care about error message and did not thinking about that. But i think that is are edge case and handling of that case should be done in caller function.
|
FWIW, here is how we are fixing it in our fork of gumbo used inside Sigil: Hope this helps. |
|
Initial loop test prevents special case decrement from ever being a problem. Tested with our own well_formed test: |
|
@kevinhendricks That looks about how I worked around the bug for nokogumbo. rubys/nokogumbo@bd62355 I'm not sure if it's possible for an error to occur at a newline that is the first byte in All of which is to say that I think if (*c == '\n' && c != original_text)
--c;is a better fix. |
|
@stevecheckoway Not sure if upstream (this) gumbo is still being actively maintained, but there is an error in tag name from original text that can be nasty in a parse - serialize loop. You may want to pull that fix in as well. thanks |
|
@kevinhendricks Do you have a pointer to the bug/fix? I'm not a maintainer for nokogumbo, merely a user, but they might want to do something about it. (Right now, it uses a git submodule to pull in gumbo-parser, but if this project isn't maintained any more, a local version or a fork might make more sense.) |
|
See
#375
The bug is only really dangerous if you parse and then re-serialize the resulting tree.
…Sent from my iPad
On Feb 24, 2017, at 5:05 PM, Stephen Checkoway ***@***.***> wrote:
@kevinhendricks Do you have a pointer to the bug/fix? I'm not a maintainer for nokogumbo, merely a user, but they might want to do something about it. (Right now, it uses a git submodule to pull in gumbo-parser, but if this project isn't maintained any more, a local version or a fork might make more sense.)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Without this patch method find_last_newline returns value bigger than
find_next_newline and in line
original_line.length = line_end - line_start;overflow happens.
Before changes newly added test failed with segmentation failure:
This slightly changed copy of code used in nokogumbo gem.
Link