Skip to content

Commit

Permalink
Fix possible crash in dd_patched_zend_call_known_function (#2548)
Browse files Browse the repository at this point in the history
* Fix possible crash in dd_patched_zend_call_known_function

Fixes #2547.

Signed-off-by: Bob Weinand <[email protected]>

* Test extension for 8.1.2

Signed-off-by: Bob Weinand <[email protected]>

* Fix possible segfault when removing hooks

Signed-off-by: Bob Weinand <[email protected]>

---------

Signed-off-by: Bob Weinand <[email protected]>
  • Loading branch information
bwoebi committed Mar 4, 2024
1 parent 807a8aa commit c78f6d4
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 1 deletion.
25 changes: 25 additions & 0 deletions .circleci/continue_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,29 @@ jobs:
path: /tmp/artifacts
- <<: *STEP_GET_TEST_AGENT_RESULTS

test_early_php_81:
working_directory: ~/datadog
machine:
image: ubuntu-2004:2023.04.2
steps:
- restore_cache:
keys:
- source-v1-{{ .Branch }}-{{ .Revision }}
- <<: *STEP_CHECKOUT
- <<: *STEP_ATTACH_WORKSPACE
- run:
command: |
docker run --rm -v $(pwd):/root -i ubuntu:jammy bash -s \<<COMMANDS
set -e
apt-get update -y
DEBIAN_FRONTEND=noninteractive apt-get install -y php8.1 php8.1-dom php-pear
cd /root
php ./build/packages/datadog-setup.php --php-bin all --file $(ls build/packages/dd-library-php-*-x86_64-linux-gnu.tar.gz)
rm /etc/php/8.1/cli/conf.d/10-opcache.ini
sed -i 's/datadog.trace.request_init_hook/\;datadog.trace.request_init_hook/' /etc/php/8.1/cli/conf.d/98-ddtrace.ini
pecl run-tests --showdiff --ini=" -d datadog.trace.cli_enabled=1" \$(find tests/ext -type d)
COMMANDS
test_arm:
machine:
image: ubuntu-2004:2023.04.2
Expand Down Expand Up @@ -4026,6 +4049,8 @@ workflows:
batch: [ 6, 7, 8, 9, 10 ]
- installer_tests:
requires: [ 'package extension' ]
- test_early_php_81:
requires: [ 'package extension' ]
- placeholder:
requires: [ 'package extension' ]
name: Framework tests
Expand Down
2 changes: 1 addition & 1 deletion ext/ddtrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ static void dd_patched_zend_call_known_function(

// If current_execute_data is on the stack, move it to the VM stack
zend_execute_data *execute_data = EG(current_execute_data);
if ((uintptr_t)&retval > (uintptr_t)EX(func) && (uintptr_t)&retval - 0xfffff < (uintptr_t)EX(func)) {
if (execute_data && (uintptr_t)&retval > (uintptr_t)EX(func) && (uintptr_t)&retval - 0xfffff < (uintptr_t)EX(func)) {
zend_execute_data *call = zend_vm_stack_push_call_frame_ex(
ZEND_MM_ALIGNED_SIZE_EX(sizeof(zend_execute_data), sizeof(zval)) +
ZEND_MM_ALIGNED_SIZE_EX(sizeof(zend_op), sizeof(zval)) +
Expand Down
1 change: 1 addition & 0 deletions tests/ext/sandbox/deferred_load_attempt_loading_once.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ _DD_LOAD_TEST_INTEGRATIONS=1
DD_TRACE_LOG_LEVEL=info,startup=off
--INI--
ddtrace.request_init_hook={PWD}/deferred_loading_helper.php
zend.assertions=1
--FILE--
<?php

Expand Down
1 change: 1 addition & 0 deletions tests/ext/sandbox/deferred_load_using_function.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ deferred loading dispatch can be overridden
_DD_LOAD_TEST_INTEGRATIONS=1
--INI--
ddtrace.request_init_hook={PWD}/deferred_loading_helper.php
zend.assertions=1
--FILE--
<?php

Expand Down
1 change: 1 addition & 0 deletions tests/ext/telemetry/integration.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ DD_INSTRUMENTATION_TELEMETRY_ENABLED=1
--INI--
datadog.trace.agent_url="file://{PWD}/integration-telemetry.out"
ddtrace.request_init_hook="{PWD}/../sandbox/deferred_loading_helper.php"
zend.assertions=1
--FILE--
<?php

Expand Down
1 change: 1 addition & 0 deletions zend_abstract_interface/hook/hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ static void zai_hook_entries_destroy(zai_hooks_entry *hooks, zend_ulong install_
ZEND_MAP_PTR_INIT(func.common.run_time_cache, hooks->run_time_cache);
#else
ZEND_MAP_PTR_INIT(func.op_array.run_time_cache, hooks->run_time_cache);
func.common.scope = NULL; // attributes are checked on PHP 8.0, 8.1
#endif
zai_hook_on_update(&func, true, &zai_hook_last_observer);
}
Expand Down

0 comments on commit c78f6d4

Please sign in to comment.