From 1a4bc7452bdb1b1eca5f36e8fa92204d8ebbe15d Mon Sep 17 00:00:00 2001 From: Michal Nowacki Date: Wed, 26 Jun 2024 14:24:01 -0400 Subject: [PATCH] simplify return value - always a string This approach adds some level of protection (compiler type checking) from misusing the API. --- agent/csec_metadata.c | 12 ++++++------ agent/csec_metadata.h | 7 ++++--- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/agent/csec_metadata.c b/agent/csec_metadata.c index 0f9571a7b..af8af2d91 100644 --- a/agent/csec_metadata.c +++ b/agent/csec_metadata.c @@ -14,7 +14,7 @@ #include "php_compat.h" #include "php_newrelic.h" -int nr_php_csec_get_metadata(const nr_php_csec_metadata_key_t key, void** p) { +int nr_php_csec_get_metadata(const nr_php_csec_metadata_key_t key, char** p) { const char* value = NULL; if (NULL == p) { @@ -27,12 +27,12 @@ int nr_php_csec_get_metadata(const nr_php_csec_metadata_key_t key, void** p) { switch (key) { case NR_PHP_CSEC_METADATA_HIGH_SECURITY: - *p = nr_zalloc(sizeof(int)); - if (NULL == *p) { - return -3; + if (NRPRG(app)->info.high_security) { + value = "true"; + } else { + value = "false"; } - *((int*)*p) = NRPRG(app)->info.high_security; - return 0; + break; case NR_PHP_CSEC_METADATA_ENTITY_NAME: value = nr_app_get_entity_name(NRPRG(app)); break; diff --git a/agent/csec_metadata.h b/agent/csec_metadata.h index c47bf97d9..a98b79339 100644 --- a/agent/csec_metadata.h +++ b/agent/csec_metadata.h @@ -21,7 +21,8 @@ typedef enum { /* * Purpose : Copy requested app meta data into allocated *value. * The caller is responsible for freeing the memory - * allocated. + * allocated. The value is a string representation of + * the requested metadata. * * Params : Pointer to a nr_php_csec_metadata_t structure * @@ -32,7 +33,7 @@ typedef enum { * -4 for invalid metadata key * -5 for inability to retrieve metadata value */ -extern int nr_php_csec_get_metadata(const nr_php_csec_metadata_key_t k, void** value); -typedef int (*nr_php_csec_get_metadata_t)(const nr_php_csec_metadata_key_t k, void** value); +extern int nr_php_csec_get_metadata(const nr_php_csec_metadata_key_t k, char** value); +typedef int (*nr_php_csec_get_metadata_t)(const nr_php_csec_metadata_key_t k, char** value); #define NR_PHP_CSEC_GET_METADATA "nr_php_csec_get_metadata" #endif