Skip to content

Commit 7c54a0a

Browse files
committed
fix drupal dangling segment
1 parent da5ee2e commit 7c54a0a

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

278278
NR_PHP_WRAPPER_REQUIRE_FRAMEWORK(NR_FW_DRUPAL);
279279

280+
nr_segment_external_params_t external_params
281+
= {.library = "Drupal",
282+
.uri = NULL};
283+
280284
/*
281285
* Grab the URL for the external metric, which is the first parameter in all
282286
* versions of Drupal.
@@ -286,17 +290,19 @@ NR_PHP_WRAPPER(nr_drupal_http_request_after) {
286290
goto end;
287291
}
288292

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

@@ -311,17 +317,22 @@ NR_PHP_WRAPPER(nr_drupal_http_request_after) {
311317
X_NEWRELIC_APP_DATA,
312318
NRP_CAT(external_params.encoded_response_header));
313319
}
320+
}
314321

315-
nr_segment_external_end(&NRPRG(drupal_http_request_segment),
316-
&external_params);
322+
end:
323+
if (1 == NRPRG(drupal_http_request_depth)) {
324+
if (external_params.uri == NULL) {
325+
nr_segment_discard(&NRPRG(drupal_http_request_segment));
326+
} else {
327+
nr_segment_external_end(&NRPRG(drupal_http_request_segment),
328+
&external_params);
329+
}
317330
NRPRG(drupal_http_request_segment) = NULL;
318331

319332
nr_free(external_params.encoded_response_header);
320333
nr_free(external_params.procedure);
321334
nr_free(external_params.uri);
322335
}
323-
324-
end:
325336
nr_php_arg_release(&arg1);
326337
NRPRG(drupal_http_request_depth) -= 1;
327338
}

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)