Skip to content

Commit

Permalink
verify wraprec belongs to process before using it
Browse files Browse the repository at this point in the history
  • Loading branch information
lavarou committed Jan 31, 2025
1 parent 0ac2a0b commit d9dca49
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
6 changes: 5 additions & 1 deletion agent/php_execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@

static inline nruserfn_t* nr_php_get_wraprec_from_op_array_extension(const char* fn, zend_function* zf) {
nruserfn_t* wraprec = (nruserfn_t*)ZEND_OP_ARRAY_EXTENSION(&zf->op_array, NR_PHP_PROCESS_GLOBALS(op_array_extension_handle));
nrl_verbosedebug(NRL_AGENT, "%s from %s, op_array_extension=%p, wraprec=%p, wraprec->pid=%d", __func__, fn, ZEND_OP_ARRAY_EXTENSION(&zf->op_array, NR_PHP_PROCESS_GLOBALS(op_array_extension_handle)), wraprec, wraprec->pid);
nrl_verbosedebug(NRL_AGENT, "%s from %s, op_array_extension=%p, wraprec=%p, wraprec->pid=%d", __func__, fn, ZEND_OP_ARRAY_EXTENSION(&zf->op_array, NR_PHP_PROCESS_GLOBALS(op_array_extension_handle)), wraprec, wraprec? wraprec->pid : 0);
if (NULL != wraprec && NRPRG(pid) != wraprec->pid) {
nrl_debug(NRL_AGENT, "wraprec pid mismatch: %d != %d", wraprec->pid, NRPRG(pid));
return NULL;
}
return wraprec;
}

Expand Down
2 changes: 1 addition & 1 deletion agent/php_newrelic.h
Original file line number Diff line number Diff line change
Expand Up @@ -602,13 +602,13 @@ nrinibool_t
nrinibool_t
message_tracer_segment_parameters_enabled; /* newrelic.segment_tracer.segment_parameters.enabled */

uint64_t pid;
#if ZEND_MODULE_API_NO < ZEND_7_4_X_API_NO
/*
* pid and user_function_wrappers are used to store user function wrappers.
* Storing this on a request level (as opposed to storing it on transaction
* level) is more robust when using multiple transactions in one request.
*/
uint64_t pid;
nr_vector_t* user_function_wrappers;
#endif

Expand Down
3 changes: 2 additions & 1 deletion agent/php_rinit.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "nr_slowsqls.h"
#include "util_logging.h"
#include "util_strings.h"
#include "util_syscalls.h"

static void nr_php_datastore_instance_destroy(
nr_datastore_instance_t* instance) {
Expand Down Expand Up @@ -60,9 +61,9 @@ PHP_RINIT_FUNCTION(newrelic) {
NRPRG(drupal_http_request_depth) = 0;
#endif
#else
NRPRG(pid) = getpid();
NRPRG(user_function_wrappers) = nr_vector_create(64, NULL, NULL);
#endif
NRPRG(pid) = nr_getpid();

if ((0 == NR_PHP_PROCESS_GLOBALS(enabled)) || (0 == NRINI(enabled))) {
return SUCCESS;
Expand Down
2 changes: 1 addition & 1 deletion agent/php_user_instrument.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ static void nr_php_wrap_user_function_internal(nruserfn_t* wraprec TSRMLS_DC) {

static nruserfn_t* nr_php_user_wraprec_create(void) {
nruserfn_t* wr = (nruserfn_t*)nr_zalloc(sizeof(nruserfn_t));
wr->pid = nr_getpid();
wr->pid = NRPRG(pid);
return wr;
}

Expand Down

0 comments on commit d9dca49

Please sign in to comment.