Skip to content

Commit

Permalink
Fix segmentation fault in modtile.c:delay_allowed (#395)
Browse files Browse the repository at this point in the history
  • Loading branch information
hummeltech authored Feb 25, 2024
1 parent a0e9681 commit 04a0bf0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/mod_tile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
}
Expand Down
14 changes: 8 additions & 6 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down

0 comments on commit 04a0bf0

Please sign in to comment.