From 09f10e854f9818202179412645b59fc8039b6c27 Mon Sep 17 00:00:00 2001 From: Amber Sistla Date: Tue, 14 Jan 2025 11:17:41 -0700 Subject: [PATCH] refactor(agent): Remove hardcodes from queueUrl string parsing --- agent/lib_aws_sdk_php.c | 12 ++++++++---- agent/lib_aws_sdk_php.h | 4 ++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/agent/lib_aws_sdk_php.c b/agent/lib_aws_sdk_php.c index 9f151eb3a..489d17ea5 100644 --- a/agent/lib_aws_sdk_php.c +++ b/agent/lib_aws_sdk_php.c @@ -200,7 +200,9 @@ void nr_lib_aws_sdk_php_sqs_parse_queueurl( * Find the pattern of the AWS queueurl that should immediately precede the * region. */ - if (0 != strncmp(queueurl_pointer, "https://sqs.", 12)) { + if (0 + != strncmp(queueurl_pointer, AWS_QUEUEURL_PREFIX, + AWS_QUEUEURL_PREFIX_LEN)) { /* Malformed queueurl, we can't decode this. */ return; } @@ -210,7 +212,7 @@ void nr_lib_aws_sdk_php_sqs_parse_queueurl( * and continues until the next '.' It is safe to move the pointer along at * this point since we allocated a sufficiently big buffer. */ - queueurl_pointer += 12; + queueurl_pointer += AWS_QUEUEURL_PREFIX_LEN; if (nr_strempty(queueurl_pointer)) { /* Malformed queueurl, we can't decode this. */ return; @@ -238,7 +240,9 @@ void nr_lib_aws_sdk_php_sqs_parse_queueurl( } /* Move past the next pattern to find the start of the account id. */ - if (0 != strncmp(queueurl_pointer, "amazonaws.com/", 14)) { + if (0 + != strncmp(queueurl_pointer, AWS_QUEUEURL_AWS_POSTFIX, + AWS_QUEUEURL_AWS_POSTFIX_LEN)) { /* Malformed queueurl, we can't decode this. */ return; } @@ -248,7 +252,7 @@ void nr_lib_aws_sdk_php_sqs_parse_queueurl( * pointer beyond that point should be safe and give us either more string or * the end of the string. */ - queueurl_pointer += 14; + queueurl_pointer += AWS_QUEUEURL_AWS_POSTFIX_LEN; if (nr_strempty(queueurl_pointer)) { /* Malformed queueurl, we can't decode this. */ return; diff --git a/agent/lib_aws_sdk_php.h b/agent/lib_aws_sdk_php.h index 8bfa30785..b345076bd 100644 --- a/agent/lib_aws_sdk_php.h +++ b/agent/lib_aws_sdk_php.h @@ -29,6 +29,10 @@ #define AWS_SQS_RECEIVE_MESSAGE_COMMAND "receiveMessage" #define AWS_SQS_RECEIVE_MESSAGE_COMMAND_LEN \ sizeof(AWS_SQS_RECEIVE_MESSAGE_COMMAND) - 1 +#define AWS_QUEUEURL_PREFIX "https://sqs." +#define AWS_QUEUEURL_PREFIX_LEN sizeof(AWS_QUEUEURL_PREFIX) - 1 +#define AWS_QUEUEURL_AWS_POSTFIX "amazonaws.com/" +#define AWS_QUEUEURL_AWS_POSTFIX_LEN sizeof(AWS_QUEUEURL_AWS_POSTFIX) - 1 /* DynamoDb */ #define AWS_SDK_PHP_DYNAMODBCLIENT_CLASS "Aws\\DynamoDb\\DynamoDbClient"