Skip to content

Commit 3cc2311

Browse files
committed
use a different mechanism to validate value retrieved from ZEND_OP_ARRAY_EXTENSION
1 parent 55ea3c5 commit 3cc2311

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

agent/php_rinit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ PHP_RINIT_FUNCTION(newrelic) {
6363
NRPRG(drupal_http_request_depth) = 0;
6464
#endif
6565
#else
66+
NRPRG(pid) = nr_getpid();
6667
NRPRG(user_function_wrappers) = nr_vector_create(64, NULL, NULL);
6768
#endif
68-
NRPRG(pid) = nr_getpid();
6969

7070
if ((0 == NR_PHP_PROCESS_GLOBALS(enabled)) || (0 == NRINI(enabled))) {
7171
return SUCCESS;

agent/php_user_instrument.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,13 @@ static inline nruserfn_t* nr_php_wraprec_lookup_get(zend_function* zf) {
164164
if (NULL != RUN_TIME_CACHE(&zf->op_array)) {
165165
wraprec = ZEND_OP_ARRAY_EXTENSION(&zf->op_array, NR_PHP_PROCESS_GLOBALS(op_array_extension_handle));
166166
}
167-
if (NULL != wraprec && NRPRG(pid) != wraprec->pid) {
167+
if (NULL != wraprec && wraprec->magic != NR_USERFN_T_MAGIC) {
168+
if (nrl_should_print(NRL_VERBOSEDEBUG, NRL_INSTRUMENT)) {
169+
char* name = nr_php_function_debug_name(zf);
170+
nrl_verbosedebug(NRL_INSTRUMENT, "%s - wraprec for {%s} is invalid",
171+
__func__, name);
172+
nr_free(name);
173+
}
168174
wraprec = NULL;
169175
}
170176
return wraprec;
@@ -346,9 +352,7 @@ static void nr_php_wrap_user_function_internal(nruserfn_t* wraprec TSRMLS_DC) {
346352

347353
nruserfn_t* nr_php_user_wraprec_create(void) {
348354
nruserfn_t* wr = (nruserfn_t*)nr_zalloc(sizeof(nruserfn_t));
349-
/* NRPRG(pid) is set in rinit but it's sometimes needed before rinit,
350-
* i.e. when wraprec is added via INI */
351-
wr->pid = (0 != NRPRG(pid) ? NRPRG(pid) : nr_getpid());
355+
wr->magic = NR_USERFN_T_MAGIC;
352356
return wr;
353357
}
354358

agent/php_user_instrument.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "php_user_instrument_hashmap_key.h"
1515

1616
struct _nruserfn_t;
17+
#define NR_USERFN_T_MAGIC 0x6e72757372666e74ULL /* "nrusrfnt" */
1718

1819
/*
1920
* This is an unused structure that is used to ensure that a bare return won't
@@ -35,6 +36,7 @@ typedef void (*nruserfn_declared_t)(TSRMLS_D);
3536
* and so the strings must be discarded in nr_php_user_wraprec_destroy;
3637
*/
3738
typedef struct _nruserfn_t {
39+
uint64_t magic; /* memory marker */
3840
struct _nruserfn_t* next; /* singly linked list next pointer */
3941

4042
#if ZEND_MODULE_API_NO == ZEND_7_4_X_API_NO
@@ -108,7 +110,6 @@ typedef struct _nruserfn_t {
108110
#if ZEND_MODULE_API_NO >= ZEND_7_4_X_API_NO
109111
char* wordpress_plugin_theme;
110112
#endif
111-
int pid; /* pid of a process that created this wraprec */
112113
} nruserfn_t;
113114

114115
#if ZEND_MODULE_API_NO >= ZEND_8_0_X_API_NO

0 commit comments

Comments
 (0)