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

Avoid invalid length when building name symbol (#348) #349

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

albanpeignier
Copy link

Small fix to avoid shorten element name or error on last closed not opened (aka orphan) element reported into #348.

  • Use strlen instead of calculation on dr->buf to manage both strings with and without \0 last character.
  • Add tests on last element closed not opened (aka orphan).

Fixes #348

Use strlen instead of calculation on dr->buf to manage both strings with and
without \0 last character.

Add tests on last element closed not opened (aka orphan).
@@ -984,7 +984,7 @@ static char read_element_end(SaxDrive dr) {
} else {
snprintf(msg, sizeof(msg) - 1, "%selement '%s' closed but not opened", EL_MISMATCH, dr->buf.str);
ox_sax_drive_error_at(dr, msg, pos, line, col);
name = str2sym(dr, dr->buf.str, dr->buf.tail - dr->buf.str - 2, 0);
name = str2sym(dr, dr->buf.str, strlen(dr->buf.str), 0);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you pointed out, dr->buf.str may not be null terminated which will give an incorrect length. A different approach will be needed to handle when the end tag is empty if the existing code fails. It seems like it should work though.

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

Successfully merging this pull request may close these issues.

Invalid name for an orphan end tag
2 participants