Skip to content

Commit 7998fed

Browse files
ZNeumannlavarou
authored andcommitted
fix drupal dangling segment
1 parent 5e4bbff commit 7998fed

File tree

5 files changed

+19
-122
lines changed

5 files changed

+19
-122
lines changed

agent/fw_drupal.c

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,10 @@ NR_PHP_WRAPPER(nr_drupal_http_request_after) {
281281

282282
NR_PHP_WRAPPER_REQUIRE_FRAMEWORK(NR_FW_DRUPAL);
283283

284+
nr_segment_external_params_t external_params
285+
= {.library = "Drupal",
286+
.uri = NULL};
287+
284288
/*
285289
* Grab the URL for the external metric, which is the first parameter in all
286290
* versions of Drupal.
@@ -290,17 +294,19 @@ NR_PHP_WRAPPER(nr_drupal_http_request_after) {
290294
goto end;
291295
}
292296

297+
if (NULL == NR_GET_RETURN_VALUE_PTR) {
298+
goto end;
299+
}
300+
301+
external_params.uri = nr_strndup(Z_STRVAL_P(arg1), Z_STRLEN_P(arg1));
302+
293303
/*
294304
* We only want to create a metric here if this isn't a recursive call to
295305
* drupal_http_request() caused by the original call returning a redirect.
296306
* We can check how many drupal_http_request() calls are on the stack by
297307
* checking a counter.
298308
*/
299309
if (1 == NRPRG(drupal_http_request_depth)) {
300-
nr_segment_external_params_t external_params
301-
= {.library = "Drupal",
302-
.uri = nr_strndup(Z_STRVAL_P(arg1), Z_STRLEN_P(arg1))};
303-
304310
external_params.procedure
305311
= nr_drupal_http_request_get_method(NR_EXECUTE_ORIG_ARGS);
306312

@@ -315,17 +321,22 @@ NR_PHP_WRAPPER(nr_drupal_http_request_after) {
315321
X_NEWRELIC_APP_DATA,
316322
NRP_CAT(external_params.encoded_response_header));
317323
}
324+
}
318325

319-
nr_segment_external_end(&NRPRG(drupal_http_request_segment),
320-
&external_params);
326+
end:
327+
if (1 == NRPRG(drupal_http_request_depth)) {
328+
if (external_params.uri == NULL) {
329+
nr_segment_discard(&NRPRG(drupal_http_request_segment));
330+
} else {
331+
nr_segment_external_end(&NRPRG(drupal_http_request_segment),
332+
&external_params);
333+
}
321334
NRPRG(drupal_http_request_segment) = NULL;
322335

323336
nr_free(external_params.encoded_response_header);
324337
nr_free(external_params.procedure);
325338
nr_free(external_params.uri);
326339
}
327-
328-
end:
329340
nr_php_arg_release(&arg1);
330341
NRPRG(drupal_http_request_depth) -= 1;
331342
}

tests/integration/external/drupal7/test_bad_params_integer_headers.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
/*SKIPIF
1515
<?php
1616
require("skipif.inc");
17-
if (version_compare(PHP_VERSION, "8.0", ">=")) {
18-
die("skip: PHP >= 8.0 not supported\n");
19-
}
2017
*/
2118

2219
/*EXPECT_METRICS
@@ -35,11 +32,6 @@
3532
[{"name":"OtherTransactionTotalTime"}, [1, "??", "??", "??", "??", "??"]],
3633
[{"name":"OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
3734
[{"name":"Supportability/framework/Drupal/forced"}, [1, 0, 0, 0, 0, 0]],
38-
[{"name":"External/127.0.0.1/all"}, [1, "??", "??", "??", "??", "??"]],
39-
[{"name":"External/all"}, [1, "??", "??", "??", "??", "??"]],
40-
[{"name":"External/allOther"}, [1, "??", "??", "??", "??", "??"]],
41-
[{"name":"External/127.0.0.1/all",
42-
"scope":"OtherTransaction/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
4335
[{"name":"Supportability/Logging/LocalDecorating/PHP/disabled"}, [1, "??", "??", "??", "??", "??"]]
4436
]
4537
]

tests/integration/external/drupal7/test_bad_params_integer_headers.php8.php

Lines changed: 0 additions & 49 deletions
This file was deleted.

tests/integration/external/drupal7/test_bad_params_null_headers.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
/*SKIPIF
1515
<?php
1616
require("skipif.inc");
17-
if (version_compare(PHP_VERSION, "8.0", ">=")) {
18-
die("skip: PHP >= 8.0 not supported\n");
19-
}
2017
*/
2118

2219
/*EXPECT_METRICS
@@ -35,11 +32,6 @@
3532
[{"name":"OtherTransactionTotalTime"}, [1, "??", "??", "??", "??", "??"]],
3633
[{"name":"OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
3734
[{"name":"Supportability/framework/Drupal/forced"}, [1, 0, 0, 0, 0, 0]],
38-
[{"name":"External/127.0.0.1/all"}, [1, "??", "??", "??", "??", "??"]],
39-
[{"name":"External/all"}, [1, "??", "??", "??", "??", "??"]],
40-
[{"name":"External/allOther"}, [1, "??", "??", "??", "??", "??"]],
41-
[{"name":"External/127.0.0.1/all",
42-
"scope":"OtherTransaction/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
4335
[{"name":"Supportability/Logging/LocalDecorating/PHP/disabled"}, [1, "??", "??", "??", "??", "??"]]
4436
]
4537
]

tests/integration/external/drupal7/test_bad_params_null_headers.php8.php

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)