Skip to content

Commit

Permalink
Merge pull request #836 from newrelic/dev
Browse files Browse the repository at this point in the history
Release 10.17 Amendment
  • Loading branch information
hahuja2 authored Feb 16, 2024
2 parents 01c67c5 + bc86066 commit f4c8604
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 35 deletions.
40 changes: 29 additions & 11 deletions agent/fw_drupal8.c
Original file line number Diff line number Diff line change
Expand Up @@ -533,20 +533,38 @@ NR_PHP_WRAPPER(nr_drupal8_name_the_wt_via_symfony) {
}
NR_PHP_WRAPPER_END

/*
* Drupal stores the version of the framework in the class constant
* Drupal::VERSION. This code first verifies the 'Drupal' class exists (note
* having to pass the lower case name of the class). If present then an attempt
* is made to retrieve the 'VERSION' class constant. Both of these checks rely
* on existing "nr_" routines that have been designed to be robust and will not
* cause an issue in user's application if either check were to fail.
*/
void nr_drupal_version() {
char* string = "Drupal::VERSION;";
zval retval;
int result
= zend_eval_string(string, &retval, "Retrieve Drupal Version");

zval* zval_version = NULL;
zend_class_entry* class_entry = NULL;

class_entry = nr_php_find_class("drupal");
if (NULL == class_entry) {
nrl_verbosedebug(NRL_INSTRUMENT, "%s: 'Drupal' class not found", __func__);
return;
}

zval_version = nr_php_get_class_constant(class_entry, "VERSION");
if (NULL == zval_version) {
nrl_verbosedebug(NRL_INSTRUMENT, "%s: Drupal does not have VERSION",
__func__);
return;
}

// Add php package to transaction
if (result == SUCCESS) {
if (Z_TYPE(retval) == IS_STRING) {
char* version = Z_STRVAL(retval);
nr_txn_add_php_package(NRPRG(txn), "drupal/core", version);
}
zval_dtor(&retval);
if (nr_php_is_zval_valid_string(zval_version)) {
char* version = Z_STRVAL_P(zval_version);
nr_txn_add_php_package(NRPRG(txn), "drupal/core", version);
}

nr_php_zval_free(&zval_version);
}

void nr_drupal8_enable(TSRMLS_D) {
Expand Down
1 change: 0 additions & 1 deletion agent/fw_hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,5 @@ extern void nr_monolog_enable(TSRMLS_D);
/* Vulnerability Management Packages */
extern void nr_drupal_version(void);
extern void nr_wordpress_version(void);
extern void nr_phpunit_version(void);

#endif /* FW_HOOKS_HDR */
25 changes: 19 additions & 6 deletions agent/fw_wordpress.c
Original file line number Diff line number Diff line change
Expand Up @@ -658,14 +658,27 @@ NR_PHP_WRAPPER_END
#endif /* PHP 7.4+ */

void nr_wordpress_version() {
char* string = "$GLOBALS['wp_version'];";
char* func_string
= ""
"(function() {"
" try {"
" if (array_key_exists('wp_version', $GLOBALS)) {"
" return $GLOBALS['wp_version'];"
" }"
" else {"
" return ' ';"
" }"
" } catch (Exception $e) {"
" return ' ';"
" }"
"})();";

zval retval;
int result = zend_eval_string(string, &retval,
"Retrieve Wordpress Version");

int result
= zend_eval_string(func_string, &retval, "Get Wordpress Version");
// Add php package to transaction
if (result == SUCCESS) {
if (Z_TYPE(retval) == IS_STRING) {
if (SUCCESS == result) {
if (nr_php_is_zval_valid_string(&retval)) {
char* version = Z_STRVAL(retval);
nr_txn_add_php_package(NRPRG(txn), "wordpress", version);
}
Expand Down
16 changes: 0 additions & 16 deletions agent/lib_phpunit.c
Original file line number Diff line number Diff line change
Expand Up @@ -666,22 +666,6 @@ static int nr_phpunit_are_statuses_valid(TSRMLS_D) {
return 1;
}

void nr_phpunit_version() {
char* string = "PHPUnit\\Runner\\Version::id();";
zval retval;
int result
= zend_eval_string(string, &retval, "Retrieve PHPUnit Version");

// Add php package to transaction
if (result == SUCCESS) {
if (Z_TYPE(retval) == IS_STRING) {
char* version = Z_STRVAL(retval);
nr_txn_add_php_package(NRPRG(txn), "phpunit/phpunit", version);
}
zval_dtor(&retval);
}
}

void nr_phpunit_enable(TSRMLS_D) {
if (!NRINI(phpunit_events_enabled)) {
return;
Expand Down
1 change: 0 additions & 1 deletion agent/php_execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,6 @@ typedef struct _nr_vuln_mgmt_table_t {
/* Note that all paths should be in lowercase. */
static const nr_vuln_mgmt_table_t vuln_mgmt_packages[] = {
{"Drupal", "core/lib/drupal.php", nr_drupal_version},
{"PHPUnit", "runner/version.php", nr_phpunit_version},
{"Wordpress", "wp-includes/version.php", nr_wordpress_version},
};

Expand Down

0 comments on commit f4c8604

Please sign in to comment.