Skip to content

Commit

Permalink
refactor(agent): Remove hardcodes from queueUrl string parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
zsistla committed Jan 14, 2025
1 parent b1e868f commit 09f10e8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 8 additions & 4 deletions agent/lib_aws_sdk_php.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions agent/lib_aws_sdk_php.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 09f10e8

Please sign in to comment.