From 4c9527044bb0790abfd546b1d0c6d18c07229ad9 Mon Sep 17 00:00:00 2001 From: Sara Golemon Date: Tue, 27 Apr 2004 19:21:36 +0000 Subject: [PATCH] MFH BugFix 28187 parse_url does not handle scheme://[0123:4567::89]:12345/etc style IPv6 embedded address URLs --- NEWS | 1 + ext/standard/url.c | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 10e45f12a5..9cc73c9f07 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,7 @@ PHP 4 NEWS then 1 character long. (Ilia) - Fixed handling of return values from storred procedures in mssql_execute() with multiple result sets returned. (Frank) +- Fixed bug #28187 (parse_url() not handling embedded IPv6 in URLs). (Sara) - Fixed bug #28147 (Crash with drawing anti-aliased lines). (Derick) - Fixed bug #28112 (sqlite_query() crashing apache on malformed query). (Ilia, Marcus) diff --git a/ext/standard/url.c b/ext/standard/url.c index 05e549c422..06d5b2a678 100644 --- a/ext/standard/url.c +++ b/ext/standard/url.c @@ -194,7 +194,18 @@ PHPAPI php_url *php_url_parse(char *str) } /* check for port */ - if ((p = memchr(s, ':', (e-s)))) { + if (*s == '[' && *(e-1) == ']') { + /* Short circuit portscan + we're dealing with an + IPv6 embedded address */ + p = s; + } else { + /* memchr is a GNU specific extension + Emulate for wide compatability */ + for(p = e; *p != ':' && p >= s; p--); + } + + if (p >= s && *p == ':') { if (!ret->port) { p++; if (e-p > 5) { /* port cannot be longer then 5 characters */ @@ -213,6 +224,11 @@ PHPAPI php_url *php_url_parse(char *str) } else { p = e; } + + if (*s == '[' && *(p-1) == ']') { + s++; + p--; + } /* check if we have a valid host, if we don't reject the string as url */ if ((p-s) < 1) { -- 2.40.0