EASTL icon indicating copy to clipboard operation
EASTL copied to clipboard

Protect string comparisons against segfaults

Open JSydll opened this issue 1 year ago • 2 comments

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.

JSydll avatar Dec 03 '24 08:12 JSydll

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

virt00l avatar Feb 04 '25 17:02 virt00l

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?

JSydll avatar Feb 04 '25 19:02 JSydll