mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-27 14:52:16 +00:00
Bug 1815914 - Allow IPv4 number parser to parse 0x as 0. r=necko-reviewers,kershaw,valentin.
Differential Revision: https://phabricator.services.mozilla.com/D182934
This commit is contained in:
parent
3614741dfe
commit
cbee8deaf8
@ -423,8 +423,10 @@ inline int32_t ValidateIPv4Number(const nsACString& host, int32_t bases[4],
|
||||
for (int32_t i = 0; i < length; i++) {
|
||||
char current = host[i];
|
||||
if (current == '.') {
|
||||
if (!lastWasNumber) { // A dot should not follow an X or a dot, or be
|
||||
// first
|
||||
// A dot should not follow a dot, or be first - it can follow an x though.
|
||||
if (!(lastWasNumber ||
|
||||
(i >= 2 && (host[i - 1] == 'X' || host[i - 1] == 'x') &&
|
||||
host[i - 2] == '0'))) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -3905,3 +3907,16 @@ size_t nsStandardURL::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const {
|
||||
nsresult Test_NormalizeIPv4(const nsACString& host, nsCString& result) {
|
||||
return mozilla::net::nsStandardURL::NormalizeIPv4(host, result);
|
||||
}
|
||||
|
||||
// For unit tests. Including nsStandardURL.h seems to cause problems
|
||||
nsresult Test_ParseIPv4Number(const nsACString& input, int32_t base,
|
||||
uint32_t& number, uint32_t maxNumber) {
|
||||
return mozilla::net::ParseIPv4Number(input, base, number, maxNumber);
|
||||
}
|
||||
|
||||
int32_t Test_ValidateIPv4Number(const nsACString& host, int32_t bases[4],
|
||||
int32_t dotIndex[3], bool& onlyBase10,
|
||||
int32_t& length) {
|
||||
return mozilla::net::ValidateIPv4Number(host, bases, dotIndex, onlyBase10,
|
||||
length);
|
||||
}
|
||||
|
@ -19,7 +19,11 @@ using namespace mozilla;
|
||||
|
||||
// In nsStandardURL.cpp
|
||||
extern nsresult Test_NormalizeIPv4(const nsACString& host, nsCString& result);
|
||||
|
||||
extern nsresult Test_ParseIPv4Number(const nsACString& input, int32_t base,
|
||||
uint32_t& number, uint32_t maxNumber);
|
||||
extern int32_t Test_ValidateIPv4Number(const nsACString& host, int32_t bases[4],
|
||||
int32_t dotIndex[3], bool& onlyBase10,
|
||||
int32_t& length);
|
||||
TEST(TestStandardURL, Simple)
|
||||
{
|
||||
nsCOMPtr<nsIURI> url;
|
||||
@ -185,14 +189,13 @@ TEST(TestStandardURL, NormalizeBad)
|
||||
{
|
||||
nsAutoCString result;
|
||||
const char* manual[] = {
|
||||
"x22.232.12.32", "122..12.32", "122.12.32.12.32", "122.12.32..",
|
||||
"122.12.xx.22", "122.12.0xx.22", "0xx.12.01.22", "0x.12.01.22",
|
||||
"12.12.02x.22", "1q.12.2.22", "122.01f.02.22", "12a.01.02.22",
|
||||
"12.01.02.20x1", "10x2.01.02.20", "0xx.01.02.20", "10.x.02.20",
|
||||
"10.00x2.02.20", "10.13.02x2.20", "10.x13.02.20", "10.0x134def.02.20",
|
||||
"\0.2.2.2", "256.2.2.2", "2.256.2.2", "2.2.256.2",
|
||||
"2.2.2.256", "2.2.-2.3", "+2.2.2.3", "13.0x2x2.2.3",
|
||||
"0x2x2.13.2.3"};
|
||||
"x22.232.12.32", "122..12.32", "122.12.32.12.32", "122.12.32..",
|
||||
"122.12.xx.22", "122.12.0xx.22", "0xx.12.01.22", "12.12.02x.22",
|
||||
"1q.12.2.22", "122.01f.02.22", "12a.01.02.22", "12.01.02.20x1",
|
||||
"10x2.01.02.20", "0xx.01.02.20", "10.x.02.20", "10.00x2.02.20",
|
||||
"10.13.02x2.20", "10.x13.02.20", "10.0x134def.02.20", "\0.2.2.2",
|
||||
"256.2.2.2", "2.256.2.2", "2.2.256.2", "2.2.2.256",
|
||||
"2.2.-2.3", "+2.2.2.3", "13.0x2x2.2.3", "0x2x2.13.2.3"};
|
||||
|
||||
for (auto& i : manual) {
|
||||
nsCString encHost(i);
|
||||
@ -416,3 +419,23 @@ TEST(TestStandardURL, CorruptSerialization)
|
||||
NS_ERROR_MALFORMED_URI,
|
||||
NS_DeserializeObject(serialization, getter_AddRefs(deserializedObject)));
|
||||
}
|
||||
|
||||
TEST(TestStandardURL, ParseIPv4Num)
|
||||
{
|
||||
auto host = "0x.0x.0"_ns;
|
||||
|
||||
int32_t bases[4] = {10, 10, 10, 10};
|
||||
bool onlyBase10 = true; // Track this as a special case
|
||||
int32_t dotIndex[3]; // The positions of the dots in the string
|
||||
int32_t length = static_cast<int32_t>(host.Length());
|
||||
|
||||
ASSERT_EQ(2,
|
||||
Test_ValidateIPv4Number(host, bases, dotIndex, onlyBase10, length));
|
||||
|
||||
nsCString result;
|
||||
ASSERT_EQ(NS_OK, Test_NormalizeIPv4("0x.0x.0"_ns, result));
|
||||
|
||||
uint32_t number;
|
||||
Test_ParseIPv4Number("0x10"_ns, 16, number, 255);
|
||||
ASSERT_EQ(number, (uint32_t)16);
|
||||
}
|
||||
|
@ -1,7 +1,4 @@
|
||||
[a-element-origin-xhtml.xhtml]
|
||||
[Parsing origin: <https://0x.0x.0> against <about:blank>]
|
||||
expected: FAIL
|
||||
|
||||
[Parsing origin: <ssh://example.com/foo/bar.git> against <http://example.org/>]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -1,7 +1,4 @@
|
||||
[a-element-origin.html]
|
||||
[Parsing origin: <https://0x.0x.0> against <about:blank>]
|
||||
expected: FAIL
|
||||
|
||||
[Parsing origin: <ssh://example.com/foo/bar.git> against <http://example.org/>]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -1145,9 +1145,6 @@
|
||||
[Parsing: <http://256.256.256.256> against <http://other.com/>]
|
||||
expected: FAIL
|
||||
|
||||
[Parsing: <https://0x.0x.0> against <about:blank>]
|
||||
expected: FAIL
|
||||
|
||||
[Parsing: <https://0x100000000/test> against <about:blank>]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -1174,9 +1174,6 @@
|
||||
[Parsing: <http://256.256.256.256> against <http://other.com/>]
|
||||
expected: FAIL
|
||||
|
||||
[Parsing: <https://0x.0x.0> against <about:blank>]
|
||||
expected: FAIL
|
||||
|
||||
[Parsing: <https://0x100000000/test> against <about:blank>]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -1434,9 +1434,6 @@
|
||||
[Parsing: <sc://\x01\x02\x03\x04\x05\x06\x07\x08\x0b\x0c\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f!"$%&'()*+,-.;=_`{}~/> without base]
|
||||
expected: FAIL
|
||||
|
||||
[Parsing: <https://0x.0x.0> without base]
|
||||
expected: FAIL
|
||||
|
||||
[Parsing: <https://0x100000000/test> without base]
|
||||
expected: FAIL
|
||||
|
||||
@ -2268,9 +2265,6 @@
|
||||
[Parsing: <sc://\x01\x02\x03\x04\x05\x06\x07\x08\x0b\x0c\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f!"$%&'()*+,-.;=_`{}~/> without base]
|
||||
expected: FAIL
|
||||
|
||||
[Parsing: <https://0x.0x.0> without base]
|
||||
expected: FAIL
|
||||
|
||||
[Parsing: <https://0x100000000/test> without base]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -8,9 +8,6 @@
|
||||
[Origin parsing: <http://!"$&'()*+,-.;=_`{}~/> without base]
|
||||
expected: FAIL
|
||||
|
||||
[Origin parsing: <https://0x.0x.0> without base]
|
||||
expected: FAIL
|
||||
|
||||
[Origin parsing: <wss://!"$&'()*+,-.;=_`{}~/> without base]
|
||||
expected: FAIL
|
||||
|
||||
@ -37,9 +34,6 @@
|
||||
[Origin parsing: <http://!"$&'()*+,-.;=_`{}~/> without base]
|
||||
expected: FAIL
|
||||
|
||||
[Origin parsing: <https://0x.0x.0> without base]
|
||||
expected: FAIL
|
||||
|
||||
[Origin parsing: <wss://!"$&'()*+,-.;=_`{}~/> without base]
|
||||
expected: FAIL
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user