Skip to content

Navigation Menu

Sign in
Appearance settings
Sign up
Appearance settings

Protect string comparisons against segfaults - #547

#547
Open
JSydll wants to merge 2 commits into
electronicarts:masterelectronicarts/EASTL:masterfrom
JSydll:protect_string_comparisons_against_segfaultsJSydll/EASTL-contrib:protect_string_comparisons_against_segfaultsCopy head branch name to clipboard
Open

Protect string comparisons against segfaults#547
JSydll wants to merge 2 commits into
electronicarts:masterelectronicarts/EASTL:masterfrom
JSydll:protect_string_comparisons_against_segfaultsJSydll/EASTL-contrib:protect_string_comparisons_against_segfaultsCopy head branch name to clipboard

Conversation

@JSydll

@JSydll JSydll commented Dec 3, 2024

Copy link
Copy Markdown

This intends to resolve #546.

Comparing string objects to nullptr is not prevented by the implementation. Therefore, it should check before starting the actual comparison - which currently leads to a segfault due to the unprotected use of CharStrlen. Given that CharStrlen fulfills the standard specification of showing UB when called like that, the issue should be fixed on the calling site.

The first commit introduces minimal test cases for the global equality operators for basic_string, the second the (quite small) fix.

@virt00l

virt00l commented Feb 4, 2025

Copy link
Copy Markdown
Contributor

Im pretty sure that's intentionaly for perfomance sake
strlen("foo", NULL) would also segfault (I assuming for the same reason)

@JSydll

JSydll commented Feb 4, 2025

Copy link
Copy Markdown
Author

I do acknowledge that strlen (or the EASTL variant of it, CharStrlen) may segfault, as this is allowed by the specification. What is far less obvious to me is the described use of comparison operators. The current behavior is especially brittle in template contexts.

Do you have an indication on performance impact in this use case? And maybe a recommendation on an alternative solution?

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.

string.h: Missing nullptr handling in operator== leading to segfaults

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.