From 6273156469f9ad8aaad5af6e3541d44454b6c4e3 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 19 Apr 2007 13:33:13 +0000 Subject: [PATCH] wfGetLastIPfromXFF() was clearly never tested either because it also DOESN'T FUCKING WORK and HAS NO FUCKING DOCUMENTATION and CAUSES ERRORS AND FAILURES This quick hack should make it appear to basically work, assuming it does anything useful at all. --- includes/ProxyTools.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/includes/ProxyTools.php b/includes/ProxyTools.php index fcd6a90186..e72a338d14 100644 --- a/includes/ProxyTools.php +++ b/includes/ProxyTools.php @@ -25,6 +25,9 @@ function wfGetForwardedFor() { } } +/** + * @todo FUCKING DOCUMENT THIS FUCKING FUNCTION + */ function wfGetLastIPfromXFF( $xff ) { if ( $xff ) { // Avoid annoyingly long xff hacks @@ -34,12 +37,12 @@ function wfGetLastIPfromXFF( $xff ) { if ( strrpos !== false ) { $last = trim( substr( $xff, $n + 1 ) ); // Make sure it is an IP - $m = preg_match('#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#', $last, $last_ip4); - $n = preg_match('#:(:[0-9A-Fa-f]{1,4}){1,7}|[0-9A-Fa-f]{1,4}(:{1,2}[0-9A-Fa-f]{1,4}|::$){1,7}#', $last, $last_ip6); + $m = preg_match('#^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$#', $last); + $n = preg_match('#^:(:[0-9A-Fa-f]{1,4}){1,7}|[0-9A-Fa-f]{1,4}(:{1,2}[0-9A-Fa-f]{1,4}|::$){1,7}$#', $last); if ( $m > 0 ) - $xff_ip = $last_ip4; + $xff_ip = $last; else if ( $n > 0 ) - $xff_ip = $last_ip6; + $xff_ip = $last; else $xff_ip = null; } else { -- 2.20.1