summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2021-04-19 08:34:52 +0200
committerDaniel Stenberg <daniel@haxx.se>2021-04-19 08:34:55 +0200
commit56a037cc0ad1b2a770d0c08d3d09dee1ce600f0f (patch)
tree53b945b03c4261e5be88c9fb68921963365302b7 /tests
parent2426fa49ea30323d01db3ecff42c6d2c929943e4 (diff)
downloadcurl-56a037cc0ad1b2a770d0c08d3d09dee1ce600f0f.tar.gz
urlapi: "normalize" numerical IPv4 host names
When the host name in a URL is given as an IPv4 numerical address, the address can be specified with dotted numericals in four different ways: a32, a.b24, a.b.c16 or a.b.c.d and each part can be specified in decimal, octal (0-prefixed) or hexadecimal (0x-prefixed). Instead of passing on the name as-is and leaving the handling to the underlying name functions, which made them not work with c-ares but work with getaddrinfo, this change now makes the curl URL API itself detect and "normalize" host names specified as IPv4 numericals. The WHATWG URL Spec says this is an okay way to specify a host name in a URL. RFC 3896 does not allow them, but curl didn't prevent them before and it seems other RFC 3896-using tools have not either. Host names used like this are widely supported by other tools as well due to the handling being done by getaddrinfo and friends. I decided to add the functionality into the URL API itself so that all users of these functions get the benefits, when for example wanting to compare two URLs. Also, it makes curl built to use c-ares now support them as well and make curl builds more consistent. The normalization makes HTTPS and virtual hosted HTTP work fine even when curl gets the address specified using one of the "obscure" formats. Test 1560 is extended to verify. Fixes #6863 Closes #6871
Diffstat (limited to 'tests')
-rw-r--r--tests/libtest/lib1560.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/tests/libtest/lib1560.c b/tests/libtest/lib1560.c
index c81400242..a469b7a0c 100644
--- a/tests/libtest/lib1560.c
+++ b/tests/libtest/lib1560.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -323,6 +323,19 @@ static struct testcase get_parts_list[] ={
};
static struct urltestcase get_url_list[] = {
+ /* IPv4 trickeries */
+ {"https://16843009", "https://1.1.1.1/", 0, 0, CURLUE_OK},
+ {"https://0x7f.1", "https://127.0.0.1/", 0, 0, CURLUE_OK},
+ {"https://0177.1", "https://127.0.0.1/", 0, 0, CURLUE_OK},
+ {"https://0111.02.0x3", "https://73.2.0.3/", 0, 0, CURLUE_OK},
+ {"https://0xff.0xff.0377.255", "https://255.255.255.255/", 0, 0, CURLUE_OK},
+ {"https://1.0xffffff", "https://1.255.255.255/", 0, 0, CURLUE_OK},
+ /* IPv4 numerical overflows or syntax errors will not normalize */
+ {"https://1.0x1000000", "https://1.0x1000000/", 0, 0, CURLUE_OK},
+ {"https://1.2.3.256", "https://1.2.3.256/", 0, 0, CURLUE_OK},
+ {"https://1.2.3.4.5", "https://1.2.3.4.5/", 0, 0, CURLUE_OK},
+ {"https://1.2.0x100.3", "https://1.2.0x100.3/", 0, 0, CURLUE_OK},
+ {"https://4294967296", "https://4294967296/", 0, 0, CURLUE_OK},
/* 40 bytes scheme is the max allowed */
{"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA://hostname/path",
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa://hostname/path",