From 43643378d44899c44fb148454a4d8162e7b1a78f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Mon, 20 Jul 2026 13:52:21 +0200 Subject: [PATCH 1/6] ext/lexbor: Enable ASAN support in Lexbor --- ext/lexbor/config.m4 | 5 +++++ ext/lexbor/config.w32 | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/ext/lexbor/config.m4 b/ext/lexbor/config.m4 index 43123578a727..2621cdb02fda 100644 --- a/ext/lexbor/config.m4 +++ b/ext/lexbor/config.m4 @@ -1,4 +1,9 @@ PHP_LEXBOR_CFLAGS="-Wno-unknown-warning-option -Wno-unterminated-string-initialization -I@ext_srcdir@/" + +if test "$PHP_ADDRESS_SANITIZER" = "yes"; then + PHP_LEXBOR_CFLAGS="$PHP_LEXBOR_CFLAGS -DLEXBOR_HAVE_ADDRESS_SANITIZER=1" +fi + LEXBOR_DIR="lexbor" AC_DEFINE([HAVE_LEXBOR], [1], [Define to 1 if the PHP extension 'lexbor' is available.]) diff --git a/ext/lexbor/config.w32 b/ext/lexbor/config.w32 index 403c3b98afb5..7ac8ec9bb471 100644 --- a/ext/lexbor/config.w32 +++ b/ext/lexbor/config.w32 @@ -25,6 +25,10 @@ ADD_SOURCES("ext/lexbor/lexbor/unicode", "idna.c unicode.c","lexbor"); ADD_SOURCES("ext/lexbor/lexbor/url", "url.c","lexbor"); ADD_FLAG("CFLAGS_LEXBOR", "/D LEXBOR_BUILDING /utf-8"); +if (PHP_ADDRESS_SANITIZER == "yes") { + ADD_FLAG("CFLAGS_LEXBOR", "/D LEXBOR_HAVE_ADDRESS_SANITIZER=1"); +} + AC_DEFINE("HAVE_LEXBOR", 1, "Define to 1 if the PHP extension 'lexbor' is available."); PHP_INSTALL_HEADERS("ext/lexbor", "php_lexbor.h lexbor/"); From f389497c69babcf8ec84f048d67d1834748ee146 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Tue, 21 Jul 2026 16:22:08 +0200 Subject: [PATCH 2/6] Try to fix Windows build --- ext/lexbor/config.w32 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/lexbor/config.w32 b/ext/lexbor/config.w32 index 7ac8ec9bb471..2b81bc60397f 100644 --- a/ext/lexbor/config.w32 +++ b/ext/lexbor/config.w32 @@ -25,7 +25,7 @@ ADD_SOURCES("ext/lexbor/lexbor/unicode", "idna.c unicode.c","lexbor"); ADD_SOURCES("ext/lexbor/lexbor/url", "url.c","lexbor"); ADD_FLAG("CFLAGS_LEXBOR", "/D LEXBOR_BUILDING /utf-8"); -if (PHP_ADDRESS_SANITIZER == "yes") { +if (PHP_SANITIZER == "yes") { ADD_FLAG("CFLAGS_LEXBOR", "/D LEXBOR_HAVE_ADDRESS_SANITIZER=1"); } From 0e135692747e8d32c07c4a2fb1c53434482a694f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Tue, 21 Jul 2026 16:27:16 +0200 Subject: [PATCH 3/6] Test in CI --- ext/lexbor/lexbor/core/mraw.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ext/lexbor/lexbor/core/mraw.c b/ext/lexbor/lexbor/core/mraw.c index c9904050dd84..7031a03333f9 100644 --- a/ext/lexbor/lexbor/core/mraw.c +++ b/ext/lexbor/lexbor/core/mraw.c @@ -166,6 +166,7 @@ lexbor_mraw_mem_alloc(lexbor_mraw_t *mraw, size_t length) mem->chunk_length++; #if defined(LEXBOR_HAVE_ADDRESS_SANITIZER) + printf("asd"); ASAN_POISON_MEMORY_REGION(mem->chunk->data, mem->chunk->size); #endif } From e27bec6390afe68964a29ee16a4ad1226d12990c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Wed, 22 Jul 2026 09:07:14 +0200 Subject: [PATCH 4/6] Fix config.m4 for CI --- ext/lexbor/config.m4 | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ext/lexbor/config.m4 b/ext/lexbor/config.m4 index 2621cdb02fda..a5261d630f88 100644 --- a/ext/lexbor/config.m4 +++ b/ext/lexbor/config.m4 @@ -1,7 +1,14 @@ PHP_LEXBOR_CFLAGS="-Wno-unknown-warning-option -Wno-unterminated-string-initialization -I@ext_srcdir@/" if test "$PHP_ADDRESS_SANITIZER" = "yes"; then - PHP_LEXBOR_CFLAGS="$PHP_LEXBOR_CFLAGS -DLEXBOR_HAVE_ADDRESS_SANITIZER=1" + PHP_LEXBOR_CFLAGS="$PHP_LEXBOR_CFLAGS -DLEXBOR_HAVE_ADDRESS_SANITIZER=1" +else + case "$CFLAGS" in + *-fsanitize=address*|\ + *-fsanitize=*,address*) + PHP_LEXBOR_CFLAGS="$PHP_LEXBOR_CFLAGS -DLEXBOR_HAVE_ADDRESS_SANITIZER=1" + ;; + esac fi LEXBOR_DIR="lexbor" From 04222a82d56a58579c6ed698cfbf4c9fa7472ef7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Wed, 22 Jul 2026 09:33:11 +0200 Subject: [PATCH 5/6] Remove testing code --- ext/lexbor/lexbor/core/mraw.c | 1 - 1 file changed, 1 deletion(-) diff --git a/ext/lexbor/lexbor/core/mraw.c b/ext/lexbor/lexbor/core/mraw.c index 7031a03333f9..c9904050dd84 100644 --- a/ext/lexbor/lexbor/core/mraw.c +++ b/ext/lexbor/lexbor/core/mraw.c @@ -166,7 +166,6 @@ lexbor_mraw_mem_alloc(lexbor_mraw_t *mraw, size_t length) mem->chunk_length++; #if defined(LEXBOR_HAVE_ADDRESS_SANITIZER) - printf("asd"); ASAN_POISON_MEMORY_REGION(mem->chunk->data, mem->chunk->size); #endif } From 5593b0125e1fcd227ce045aed0320421fc98c166 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Wed, 22 Jul 2026 16:22:07 +0200 Subject: [PATCH 6/6] Try to fix ASAN use-after-poison --- ext/lexbor/lexbor/url/url.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/ext/lexbor/lexbor/url/url.c b/ext/lexbor/lexbor/url/url.c index 8099c12089bb..abd376986f4a 100644 --- a/ext/lexbor/lexbor/url/url.c +++ b/ext/lexbor/lexbor/url/url.c @@ -3443,9 +3443,6 @@ lxb_url_host_parse(lxb_url_parser_t *parser, const lxb_char_t *data, 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); - if (status != LXB_STATUS_OK) { return status; }