Skip to content

Commit f4c8604

Browse files
authored
Merge pull request #836 from newrelic/dev
Release 10.17 Amendment
2 parents 01c67c5 + bc86066 commit f4c8604

File tree

5 files changed

+48
-35
lines changed

5 files changed

+48
-35
lines changed

agent/fw_drupal8.c

+29-11
Original file line numberDiff line numberDiff line change
@@ -533,20 +533,38 @@ NR_PHP_WRAPPER(nr_drupal8_name_the_wt_via_symfony) {
533533
}
534534
NR_PHP_WRAPPER_END
535535

536+
/*
537+
* Drupal stores the version of the framework in the class constant
538+
* Drupal::VERSION. This code first verifies the 'Drupal' class exists (note
539+
* having to pass the lower case name of the class). If present then an attempt
540+
* is made to retrieve the 'VERSION' class constant. Both of these checks rely
541+
* on existing "nr_" routines that have been designed to be robust and will not
542+
* cause an issue in user's application if either check were to fail.
543+
*/
536544
void nr_drupal_version() {
537-
char* string = "Drupal::VERSION;";
538-
zval retval;
539-
int result
540-
= zend_eval_string(string, &retval, "Retrieve Drupal Version");
541-
545+
zval* zval_version = NULL;
546+
zend_class_entry* class_entry = NULL;
547+
548+
class_entry = nr_php_find_class("drupal");
549+
if (NULL == class_entry) {
550+
nrl_verbosedebug(NRL_INSTRUMENT, "%s: 'Drupal' class not found", __func__);
551+
return;
552+
}
553+
554+
zval_version = nr_php_get_class_constant(class_entry, "VERSION");
555+
if (NULL == zval_version) {
556+
nrl_verbosedebug(NRL_INSTRUMENT, "%s: Drupal does not have VERSION",
557+
__func__);
558+
return;
559+
}
560+
542561
// Add php package to transaction
543-
if (result == SUCCESS) {
544-
if (Z_TYPE(retval) == IS_STRING) {
545-
char* version = Z_STRVAL(retval);
546-
nr_txn_add_php_package(NRPRG(txn), "drupal/core", version);
547-
}
548-
zval_dtor(&retval);
562+
if (nr_php_is_zval_valid_string(zval_version)) {
563+
char* version = Z_STRVAL_P(zval_version);
564+
nr_txn_add_php_package(NRPRG(txn), "drupal/core", version);
549565
}
566+
567+
nr_php_zval_free(&zval_version);
550568
}
551569

552570
void nr_drupal8_enable(TSRMLS_D) {

agent/fw_hooks.h

-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,5 @@ extern void nr_monolog_enable(TSRMLS_D);
5858
/* Vulnerability Management Packages */
5959
extern void nr_drupal_version(void);
6060
extern void nr_wordpress_version(void);
61-
extern void nr_phpunit_version(void);
6261

6362
#endif /* FW_HOOKS_HDR */

agent/fw_wordpress.c

+19-6
Original file line numberDiff line numberDiff line change
@@ -658,14 +658,27 @@ NR_PHP_WRAPPER_END
658658
#endif /* PHP 7.4+ */
659659

660660
void nr_wordpress_version() {
661-
char* string = "$GLOBALS['wp_version'];";
661+
char* func_string
662+
= ""
663+
"(function() {"
664+
" try {"
665+
" if (array_key_exists('wp_version', $GLOBALS)) {"
666+
" return $GLOBALS['wp_version'];"
667+
" }"
668+
" else {"
669+
" return ' ';"
670+
" }"
671+
" } catch (Exception $e) {"
672+
" return ' ';"
673+
" }"
674+
"})();";
675+
662676
zval retval;
663-
int result = zend_eval_string(string, &retval,
664-
"Retrieve Wordpress Version");
665-
677+
int result
678+
= zend_eval_string(func_string, &retval, "Get Wordpress Version");
666679
// Add php package to transaction
667-
if (result == SUCCESS) {
668-
if (Z_TYPE(retval) == IS_STRING) {
680+
if (SUCCESS == result) {
681+
if (nr_php_is_zval_valid_string(&retval)) {
669682
char* version = Z_STRVAL(retval);
670683
nr_txn_add_php_package(NRPRG(txn), "wordpress", version);
671684
}

agent/lib_phpunit.c

-16
Original file line numberDiff line numberDiff line change
@@ -666,22 +666,6 @@ static int nr_phpunit_are_statuses_valid(TSRMLS_D) {
666666
return 1;
667667
}
668668

669-
void nr_phpunit_version() {
670-
char* string = "PHPUnit\\Runner\\Version::id();";
671-
zval retval;
672-
int result
673-
= zend_eval_string(string, &retval, "Retrieve PHPUnit Version");
674-
675-
// Add php package to transaction
676-
if (result == SUCCESS) {
677-
if (Z_TYPE(retval) == IS_STRING) {
678-
char* version = Z_STRVAL(retval);
679-
nr_txn_add_php_package(NRPRG(txn), "phpunit/phpunit", version);
680-
}
681-
zval_dtor(&retval);
682-
}
683-
}
684-
685669
void nr_phpunit_enable(TSRMLS_D) {
686670
if (!NRINI(phpunit_events_enabled)) {
687671
return;

agent/php_execute.c

-1
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,6 @@ typedef struct _nr_vuln_mgmt_table_t {
605605
/* Note that all paths should be in lowercase. */
606606
static const nr_vuln_mgmt_table_t vuln_mgmt_packages[] = {
607607
{"Drupal", "core/lib/drupal.php", nr_drupal_version},
608-
{"PHPUnit", "runner/version.php", nr_phpunit_version},
609608
{"Wordpress", "wp-includes/version.php", nr_wordpress_version},
610609
};
611610

0 commit comments

Comments
 (0)