From 04a0bf0f0985bfe568001b0de4520468bdc971e2 Mon Sep 17 00:00:00 2001 From: Hummeltech <6109326+hummeltech@users.noreply.github.com> Date: Sat, 24 Feb 2024 19:11:02 -0700 Subject: [PATCH] Fix segmentation fault in modtile.c:delay_allowed (#395) --- src/mod_tile.c | 10 +++++----- tests/CMakeLists.txt | 14 ++++++++------ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/mod_tile.c b/src/mod_tile.c index ad7b3009..49afcf4c 100644 --- a/src/mod_tile.c +++ b/src/mod_tile.c @@ -800,7 +800,7 @@ static int delay_allowed(request_rec *r, enum tileState state) delaypool * delayp; int delay = 0; int i, j; - char ** strtok_state; + char * strtok_state; char * tmp; const char * ip_addr = NULL; apr_time_t now; @@ -825,20 +825,20 @@ static int delay_allowed(request_rec *r, enum tileState state) if (ip_addrs) { #ifdef APACHE24 - ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "Checking throttling delays: Found X-Forward-For header \"%s\", forwarded by %s", ip_addrs, r->connection->client_ip); + ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "Checking throttling delays: Found X-Forwarded-For header \"%s\", forwarded by %s", ip_addrs, r->connection->client_ip); #else - ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "Checking throttling delays: Found X-Forward-For header \"%s\", forwarded by %s", ip_addrs, r->connection->remote_ip); + ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "Checking throttling delays: Found X-Forwarded-For header \"%s\", forwarded by %s", ip_addrs, r->connection->remote_ip); #endif //X-Forwarded-For can be a chain of proxies deliminated by , The first entry in the list is the client, the last entry is the remote address seen by the proxy //closest to the tileserver. strtok_state = NULL; - tmp = apr_strtok(ip_addrs, ", ", strtok_state); + tmp = apr_strtok(ip_addrs, ", ", &strtok_state); ip_addr = tmp; //Use the last entry in the chain of X-Forwarded-For instead of the client, i.e. the entry added by the proxy closest to the tileserver //If this is a reverse proxy under our control, its X-Forwarded-For can be trusted. if (scfg->enableTileThrottlingXForward == 2) { - while ((tmp = apr_strtok(NULL, ", ", strtok_state)) != NULL) { + while ((tmp = apr_strtok(NULL, ", ", &strtok_state)) != NULL) { ip_addr = tmp; } } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2710ac48..fc386f65 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -649,12 +649,14 @@ foreach(STORAGE_BACKEND_INDEX RANGE ${STORAGE_BACKENDS_LENGTH}) ) add_test(NAME throttling_xforward_${MAP_NAME}_${STORAGE_BACKEND} COMMAND ${BASH} -c " - if ! ${CURL_CMD} --header \"X-Forwarded-For: ${CTEST_HOST}, ${CTEST_HOST}\" --output /dev/null ${HTTPD1_URL}; then - echo \"${HTTPD1_URL}\"; - fi - if ! ${CURL_CMD} --header \"X-Forwarded-For: ${CTEST_HOST}, ${CTEST_HOST}\" --output /dev/null ${HTTPD2_URL}; then - echo \"${HTTPD2_URL}\"; - fi + for i in {0..10}; do + if ! ${CURL_CMD} --header \"X-Forwarded-For: ${CTEST_HOST}, ${CTEST_HOST}\" --output /dev/null ${HTTPD1_URL}; then + echo \"${HTTPD1_URL}\"; + fi + if ! ${CURL_CMD} --header \"X-Forwarded-For: ${CTEST_HOST}, ${CTEST_HOST}\" --output /dev/null ${HTTPD2_URL}; then + echo \"${HTTPD2_URL}\"; + fi + done " WORKING_DIRECTORY tests )