ext/lexbor: Enable ASAN support in Lexbor#22826
Conversation
ndossche
left a comment
There was a problem hiding this comment.
This doesn't fully work, right?
For example in core/dobject.c in lexbor, it check for LEXBOR_HAVE_ADDRESS_SANITIZER but LEXBOR_HAVE_ADDRESS_SANITIZER is only defined in php_config.h...
I just tried this hypothesis by putting a syntax error under that define and PHP still compiled fine, so that indicates it indeed isn't being picked up there
|
Yeah, sorry for the premature PR, I also tested the change (after I opened the PR), and it indeed didn't work that way... But now we'll have a proof that it works: |
| CFLAGS="-fsanitize=undefined,address -fno-sanitize=function -DZEND_TRACK_ARENA_ALLOC" | ||
| LDFLAGS="-fsanitize=undefined,address -fno-sanitize=function" | ||
| CFLAGS="-fno-sanitize=function -DZEND_TRACK_ARENA_ALLOC" | ||
| LDFLAGS="-fno-sanitize=function" |
There was a problem hiding this comment.
Oh, thanks for the info.. I didn't understand why not the --enable-*-sanitizer flags were used.
There was a problem hiding this comment.
Desperate times call for desperate measures: https://github.com/php/php-src/pull/22826/changes#diff-8f50e816adac6afb8f364de04db3ca061f2e64f92834d17dc0ceec2a0da9cc21R6
|
Finally, I can see the same failure what I saw locally: |
| if (lxb_url_is_ipv4(parser, domain->data, end)) { | ||
| status = lxb_url_ipv4_parse(parser, domain->data, end, &ipv4); | ||
|
|
||
| (void) lexbor_str_destroy(domain, mraw, false); |
There was a problem hiding this comment.
The lexbor_str_destroy() call frees and subsequently poisons the domain string's memory region, but the character where parsing failed is added to the logs, causing a use-after-poison error during returing the error in fill_errors().
Since lexbor uses an arena allocator, skipping the explicit lexbor_str_destroy() call should not cause a memory leak (but correct me if I'm wrong) — the memory will be reclaimed at the end of the request.
The lexbor_str_destroy() call frees and subsequently poisons the domain string's memory region, but the character where parsing failed is added to the logs (https://github.com/lexbor/lexbor/blob/21c907010afbace3df43e9cb42071d988428084a/source/lexbor/url/url.c#L3617), causing a use-after-poison error if the logs are consumed. Since lexbor uses an arena allocator, skipping the explicit lexbor_str_destroy() call should not cause a memory leak — the memory will be reclaimed when the arena itself is freed. Found in php/php-src#22826
No description provided.