Skip to content

Conversation

@rakitzis
Copy link
Owner

This commit guards the case for range matches (e.g., "[a-z]") with an end-of-string check for the source string.

This prevents an inadvertent interpretation of the nul terminator as a matching character, as well as preventing bugs as in issue #115.

@rakitzis
Copy link
Owner Author

rakitzis commented May 18, 2025

@borkovic I think this fixes the out-of-bounds access in match.c, thanks for your fix.

match.c Outdated
p += r, m += r, s++;
continue;
}
break;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should break; (line 36) be outside if (*s) {...} (lines 30-37)?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Aha. Good catch. Now, I wonder if I can add a test to trip.rc to catch this misuse of the C switch statement.

Copy link
Owner Author

Choose a reason for hiding this comment

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

As far as as I can tell the accidental fall through would consume some of the pattern string, though it's hard in this moment to provoke it into doing something bad. Nevertheless, I fixed the break statement.

@rakitzis rakitzis force-pushed the trailing-rangematch branch from e8f4d40 to 23eae3d Compare May 18, 2025 20:48
This commit guards the case for range matches (e.g., "[a-z]") with
an end-of-string check for the source string.

This prevents an inadvertent interpretation of the nul
terminator as a matching character, as well as preventing
bugs as in issue #115.
@rakitzis rakitzis force-pushed the trailing-rangematch branch from 23eae3d to e7cb583 Compare May 18, 2025 23:37
@xyb3rt
Copy link
Collaborator

xyb3rt commented Sep 21, 2025

Sorry for me being inactive for so long. Can we merge this, @rakitzis?

@rakitzis
Copy link
Owner Author

Yes, of course.

@rakitzis rakitzis merged commit e474d36 into master Sep 21, 2025
4 checks passed
@xyb3rt xyb3rt deleted the trailing-rangematch branch September 22, 2025 16:37
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.

4 participants