From ed256f3fc2ee784b98995a593d172862b10f3eca Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Thu, 17 Oct 2024 18:35:24 +0200 Subject: [PATCH] Fix exception property offset computation for PHP 8.1+ (#2901) They're shared across all inheritors on PHP 8.1+ and thus only need to be incremented on the specific ce. This issue arises when a property from an inherited internal class extending Exception is itself inherited by another class. Also fix an accidentally discovered use-after-free with peer.service. Fixes #2898. Signed-off-by: Bob Weinand --- ext/handlers_exception.c | 11 +++++++++-- ext/serializer.c | 4 ++-- libdatadog | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/ext/handlers_exception.c b/ext/handlers_exception.c index 17a4e0ec5e..fd5827bfdf 100644 --- a/ext/handlers_exception.c +++ b/ext/handlers_exception.c @@ -546,8 +546,15 @@ void ddtrace_exception_handlers_startup(void) { zend_property_info *property_info; ZEND_HASH_MAP_FOREACH_PTR(&ce->properties_info, property_info) { - if (property_info->offset >= parent_info->offset && property_info->ce != base_ce && (property_info->flags & ZEND_ACC_STATIC) == 0) { - property_info->offset += sizeof(zval); + if (property_info->offset >= parent_info->offset && (property_info->flags & ZEND_ACC_STATIC) == 0) { +#if PHP_VERSION_ID >= 80100 + if (property_info->ce == ce) +#else + if (property_info->ce != base_ce) +#endif + { + property_info->offset += sizeof(zval); + } } } ZEND_HASH_FOREACH_END(); diff --git a/ext/serializer.c b/ext/serializer.c index 805a377735..173a87dd3b 100644 --- a/ext/serializer.c +++ b/ext/serializer.c @@ -1236,9 +1236,9 @@ static void _serialize_meta(zval *el, ddtrace_span_data *span, zend_string *serv if (Z_TYPE_P(tag) == IS_STRING) { // Use the first tag that is found in the span, if any zval *peer_service = zend_hash_find(Z_ARRVAL_P(meta), Z_STR_P(tag)); if (peer_service && Z_TYPE_P(peer_service) == IS_STRING) { - add_assoc_str(meta, "_dd.peer.service.source", zend_string_copy(Z_STR_P(tag))); - zend_string *peer = zval_get_string(peer_service); + + add_assoc_str(meta, "_dd.peer.service.source", zend_string_copy(Z_STR_P(tag))); if (!dd_set_mapped_peer_service(meta, peer)) { add_assoc_str(meta, "peer.service", peer); } diff --git a/libdatadog b/libdatadog index 356f76a818..2820fd0761 160000 --- a/libdatadog +++ b/libdatadog @@ -1 +1 @@ -Subproject commit 356f76a818d164c954d2a09e54e2e8c41537a053 +Subproject commit 2820fd07617fed238d21da99ba7da3d3712a95f5