Skip to content

Commit 0d133c3

Browse files
ZNeumannlavarou
authored andcommitted
fix drupal dangling segment
1 parent 6e8319c commit 0d133c3

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
@@ -279,6 +279,10 @@ NR_PHP_WRAPPER(nr_drupal_http_request_after) {
279279

280280
NR_PHP_WRAPPER_REQUIRE_FRAMEWORK(NR_FW_DRUPAL);
281281

282+
nr_segment_external_params_t external_params
283+
= {.library = "Drupal",
284+
.uri = NULL};
285+
282286
/*
283287
* Grab the URL for the external metric, which is the first parameter in all
284288
* versions of Drupal.
@@ -288,17 +292,19 @@ NR_PHP_WRAPPER(nr_drupal_http_request_after) {
288292
goto end;
289293
}
290294

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

@@ -313,17 +319,22 @@ NR_PHP_WRAPPER(nr_drupal_http_request_after) {
313319
X_NEWRELIC_APP_DATA,
314320
NRP_CAT(external_params.encoded_response_header));
315321
}
322+
}
316323

317-
nr_segment_external_end(&NRPRG(drupal_http_request_segment),
318-
&external_params);
324+
end:
325+
if (1 == NRPRG(drupal_http_request_depth)) {
326+
if (external_params.uri == NULL) {
327+
nr_segment_discard(&NRPRG(drupal_http_request_segment));
328+
} else {
329+
nr_segment_external_end(&NRPRG(drupal_http_request_segment),
330+
&external_params);
331+
}
319332
NRPRG(drupal_http_request_segment) = NULL;
320333

321334
nr_free(external_params.encoded_response_header);
322335
nr_free(external_params.procedure);
323336
nr_free(external_params.uri);
324337
}
325-
326-
end:
327338
nr_php_arg_release(&arg1);
328339
NRPRG(drupal_http_request_depth) -= 1;
329340
}

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)