Skip to content

Commit

Permalink
Fix exception property offset computation for PHP 8.1+ (#2901)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
bwoebi authored Oct 17, 2024
1 parent 3f3547d commit ed256f3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
11 changes: 9 additions & 2 deletions ext/handlers_exception.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions ext/serializer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit ed256f3

Please sign in to comment.