Skip to content

Commit 88485df

Browse files
committed
verify wraprec belongs to process before using it
1 parent 6ed1863 commit 88485df

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

agent/php_execute.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,11 @@
9595

9696
static inline nruserfn_t* nr_php_get_wraprec_from_op_array_extension(const char* fn, zend_function* zf) {
9797
nruserfn_t* wraprec = (nruserfn_t*)ZEND_OP_ARRAY_EXTENSION(&zf->op_array, NR_PHP_PROCESS_GLOBALS(op_array_extension_handle));
98-
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);
98+
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);
99+
if (NULL != wraprec && NRPRG(pid) != wraprec->pid) {
100+
nrl_debug(NRL_AGENT, "wraprec pid mismatch: %d != %d", wraprec->pid, NRPRG(pid));
101+
return NULL;
102+
}
99103
return wraprec;
100104
}
101105

agent/php_newrelic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,13 +615,13 @@ nrinibool_t
615615
nrinibool_t
616616
message_tracer_segment_parameters_enabled; /* newrelic.segment_tracer.segment_parameters.enabled */
617617

618+
uint64_t pid;
618619
#if ZEND_MODULE_API_NO < ZEND_7_4_X_API_NO
619620
/*
620621
* pid and user_function_wrappers are used to store user function wrappers.
621622
* Storing this on a request level (as opposed to storing it on transaction
622623
* level) is more robust when using multiple transactions in one request.
623624
*/
624-
uint64_t pid;
625625
nr_vector_t* user_function_wrappers;
626626
#endif
627627

agent/php_rinit.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "nr_slowsqls.h"
1919
#include "util_logging.h"
2020
#include "util_strings.h"
21+
#include "util_syscalls.h"
2122

2223
static void nr_php_datastore_instance_destroy(
2324
nr_datastore_instance_t* instance) {
@@ -60,9 +61,9 @@ PHP_RINIT_FUNCTION(newrelic) {
6061
NRPRG(drupal_http_request_depth) = 0;
6162
#endif
6263
#else
63-
NRPRG(pid) = getpid();
6464
NRPRG(user_function_wrappers) = nr_vector_create(64, NULL, NULL);
6565
#endif
66+
NRPRG(pid) = nr_getpid();
6667

6768
if ((0 == NR_PHP_PROCESS_GLOBALS(enabled)) || (0 == NRINI(enabled))) {
6869
return SUCCESS;

agent/php_user_instrument.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ static void nr_php_wrap_user_function_internal(nruserfn_t* wraprec TSRMLS_DC) {
296296

297297
static nruserfn_t* nr_php_user_wraprec_create(void) {
298298
nruserfn_t* wr = (nruserfn_t*)nr_zalloc(sizeof(nruserfn_t));
299-
wr->pid = nr_getpid();
299+
wr->pid = NRPRG(pid);
300300
return wr;
301301
}
302302

0 commit comments

Comments
 (0)