#50830 [Com]: FILTER_VALIDATE_IP incorrectly validates a compressed IPv4-mapped IPv6 address

From: Date: Mon, 01 Feb 2010 15:34:14 +0000
Subject: #50830 [Com]: FILTER_VALIDATE_IP incorrectly validates a compressed IPv4-mapped IPv6 address
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-147113@lists.php.net to get a copy of this message
ID: 50830 Comment by: mikerushton at hotmail dot co dot uk Reported By: mikerushton at hotmail dot co dot uk Status: Open Bug Type: Filter related Operating System: * PHP Version: 5.*, 6 New Comment: An addition: here's my solution (as a regular expression): (?:(?:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9](? ::|$)){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(? ::[a-f0-9]{1,4}){0,5})?)))|(?:(?:(?:[a-f0-9]{1,4}(?::[a-f0- 9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0- 9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?))?(?:(? :25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\.(?:(?:25[0- 5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3})) Previous Comments: ------------------------------------------------------------------------ [2010-01-24 15:45:29] mikerushton at hotmail dot co dot uk Description: ------------ FILTER_VALIDATE_IP validates the incorrect 0:::255.255.255.255 and does not validate the correct 0::255.255.255.255 According to RFC 5321, the correct syntax is: [IPv6-hex *3(":" IPv6-hex)] "::" [IPv6-hex *3(":" IPv6-hex) ":"] IPv4- address-literal This does not allow for three consecutive colons. Reproduce code: --------------- // First filter_var('FFFF:::255.255.255.255', FILTER_VALIDATE_IP); // Second filter_var('FFFF::255.255.255.255', FILTER_VALIDATE_IP); Expected result: ---------------- // First bool(false) // Second string(21) 'FFFF::255.255.255.255' Actual result: -------------- // First string(22) 'FFFF:::255.255.255.255' // Second bool(false) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=50830&edit=1

« previous php.bugs (#147113) next »