Skip to content

Commit

Permalink
merge #777
Browse files Browse the repository at this point in the history
  • Loading branch information
bduranleau-nr committed Dec 1, 2023
1 parent 2604470 commit d295ecd
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 14 deletions.
14 changes: 13 additions & 1 deletion agent/fw_wordpress.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#define NR_WORDPRESS_HOOK_PREFIX "Framework/WordPress/Hook/"
#define NR_WORDPRESS_PLUGIN_PREFIX "Framework/WordPress/Plugin/"

static nr_regex_t* wordpress_hook_regex;

static nr_matcher_t* create_matcher_for_constant(const char* constant,
const char* suffix) {
zval* value = nr_php_get_constant(constant);
Expand Down Expand Up @@ -374,7 +376,7 @@ static char* nr_wordpress_clean_tag(const zval* tag TSRMLS_DC) {
return NULL;
}

regex = NRPRG(wordpress_hook_regex);
regex = wordpress_hook_regex;
if (NULL == regex) {
return NULL;
}
Expand Down Expand Up @@ -553,3 +555,13 @@ void nr_wordpress_enable(TSRMLS_D) {
nr_php_add_call_user_func_array_pre_callback(
nr_wordpress_call_user_func_array TSRMLS_CC);
}

void nr_wordpress_minit(void) {
wordpress_hook_regex = nr_regex_create(
"(^([a-z_-]+[_-])([0-9a-f_.]+[0-9][0-9a-f.]+)(_{0,1}.*)$|(.*))",
NR_REGEX_CASELESS, 0);
}

void nr_wordpress_mshutdown(void) {
nr_regex_destroy(&wordpress_hook_regex);
}
3 changes: 3 additions & 0 deletions agent/fw_wordpress.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,7 @@ char* nr_php_wordpress_plugin_match_matcher(const char* filename);
*/
char* nr_php_wordpress_theme_match_matcher(const char* filename);

extern void nr_wordpress_minit(void);
extern void nr_wordpress_mshutdown(void);

#endif /* FW_WORDPRESS_HDR */
5 changes: 2 additions & 3 deletions agent/php_minit.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "php_vm.h"
#include "php_wrapper.h"
#include "fw_laravel.h"
#include "fw_wordpress.h"
#include "lib_guzzle4.h"
#include "lib_guzzle6.h"
#include "nr_agent.h"
Expand All @@ -35,9 +36,6 @@
#include "util_syscalls.h"
#include "util_threads.h"

#include "fw_laravel.h"
#include "lib_guzzle4.h"

static void php_newrelic_init_globals(zend_newrelic_globals* nrg) {
if (nrunlikely(NULL == nrg)) {
return;
Expand Down Expand Up @@ -709,6 +707,7 @@ PHP_MINIT_FUNCTION(newrelic) {
nr_guzzle4_minit(TSRMLS_C);
nr_guzzle6_minit(TSRMLS_C);
nr_laravel_minit(TSRMLS_C);
nr_wordpress_minit();
nr_php_set_opcode_handlers();

nrl_debug(NRL_INIT, "MINIT processing done");
Expand Down
3 changes: 3 additions & 0 deletions agent/php_mshutdown.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "php_vm.h"
#include "nr_agent.h"
#include "util_logging.h"
#include "fw_wordpress.h"

#ifdef TAGS
void zm_shutdown_newrelic(void); /* ctags landing pad only */
Expand All @@ -39,6 +40,8 @@ PHP_MSHUTDOWN_FUNCTION(newrelic) {
*/
nrl_debug(NRL_INIT, "MSHUTDOWN processing started");

nr_wordpress_mshutdown();

/* restore header handler */
sapi_module.header_handler = NR_PHP_PROCESS_GLOBALS(orig_header_handler);
NR_PHP_PROCESS_GLOBALS(orig_header_handler) = NULL;
Expand Down
1 change: 0 additions & 1 deletion agent/php_newrelic.h
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,6 @@ bool check_cufa; /* Whether we need to check cufa because we are
instrumenting hooks, or whether we can skip cufa */

char* wordpress_tag; /* The current WordPress tag */
nr_regex_t* wordpress_hook_regex; /* Regex to sanitize hook names */
nr_matcher_t* wordpress_plugin_matcher; /* Matcher for plugin filenames */
nr_matcher_t* wordpress_theme_matcher; /* Matcher for theme filenames */
nr_matcher_t* wordpress_core_matcher; /* Matcher for plugin filenames */
Expand Down
8 changes: 0 additions & 8 deletions agent/php_rinit.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,6 @@ PHP_RINIT_FUNCTION(newrelic) {
nr_php_extension_instrument_rescan(NRPRG(extensions) TSRMLS_CC);
}

/*
* Compile regex for WordPress: includes logic for
* hook sanitization regex.
*/
NRPRG(wordpress_hook_regex) = nr_regex_create(
"(^([a-z_-]+[_-])([0-9a-f_.]+[0-9][0-9a-f.]+)(_{0,1}.*)$|(.*))",
NR_REGEX_CASELESS, 0);

NRPRG(check_cufa) = false;

NRPRG(mysql_last_conn) = NULL;
Expand Down
1 change: 0 additions & 1 deletion agent/php_rshutdown.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ int nr_php_post_deactivate(void) {
nr_php_exception_filters_destroy(&NRPRG(exception_filters));
nr_matcher_destroy(&NRPRG(wordpress_plugin_matcher));
nr_matcher_destroy(&NRPRG(wordpress_core_matcher));
nr_regex_destroy(&NRPRG(wordpress_hook_regex));
nr_matcher_destroy(&NRPRG(wordpress_theme_matcher));
nr_hashmap_destroy(&NRPRG(wordpress_file_metadata));

Expand Down

0 comments on commit d295ecd

Please sign in to comment.