summaryrefslogtreecommitdiffstats
path: root/netwerk/base/nsStandardURL.cpp
diff options
context:
space:
mode:
authorNew Tobin Paradigm <email@mattatobin.com>2018-04-16 08:25:45 -0400
committerGitHub <noreply@github.com>2018-04-16 08:25:45 -0400
commitba80720469e27d3d7ae6f1095b3c187207adc051 (patch)
treef864e580c5cd7d99127aac64e9c3ae0ee6e9aa4b /netwerk/base/nsStandardURL.cpp
parenta66e6546c361d238b0179af18e26bf18aa4a7eb9 (diff)
parentae14556114dcae29f679db7c15f0bc9b707bb89a (diff)
downloadUXP-ba80720469e27d3d7ae6f1095b3c187207adc051.tar
UXP-ba80720469e27d3d7ae6f1095b3c187207adc051.tar.gz
UXP-ba80720469e27d3d7ae6f1095b3c187207adc051.tar.lz
UXP-ba80720469e27d3d7ae6f1095b3c187207adc051.tar.xz
UXP-ba80720469e27d3d7ae6f1095b3c187207adc051.zip
Merge pull request #174 from janekptacijarabaci/url_parser_1
moebius#130: URL parser - fix: don't allow empty host name
Diffstat (limited to 'netwerk/base/nsStandardURL.cpp')
-rw-r--r--netwerk/base/nsStandardURL.cpp31
1 files changed, 21 insertions, 10 deletions
diff --git a/netwerk/base/nsStandardURL.cpp b/netwerk/base/nsStandardURL.cpp
index bc1350f28..983e938ca 100644
--- a/netwerk/base/nsStandardURL.cpp
+++ b/netwerk/base/nsStandardURL.cpp
@@ -1483,6 +1483,11 @@ nsStandardURL::SetSpec(const nsACString &input)
rv = BuildNormalizedSpec(spec);
}
+ // Make sure that a URLTYPE_AUTHORITY has a non-empty hostname.
+ if (mURLType == URLTYPE_AUTHORITY && mHost.mLen == -1) {
+ rv = NS_ERROR_MALFORMED_URI;
+ }
+
if (NS_FAILED(rv)) {
Clear();
// If parsing the spec has failed, restore the old URL
@@ -3092,20 +3097,26 @@ nsStandardURL::SetFile(nsIFile *file)
rv = net_GetURLSpecFromFile(file, url);
if (NS_FAILED(rv)) return rv;
- SetSpec(url);
+ uint32_t oldURLType = mURLType;
+ uint32_t oldDefaultPort = mDefaultPort;
+ rv = Init(nsIStandardURL::URLTYPE_NO_AUTHORITY, -1, url, nullptr, nullptr);
- rv = Init(mURLType, mDefaultPort, url, nullptr, nullptr);
+ if (NS_FAILED(rv)) {
+ // Restore the old url type and default port if the call to Init fails.
+ mURLType = oldURLType;
+ mDefaultPort = oldDefaultPort;
+ return rv;
+ }
// must clone |file| since its value is not guaranteed to remain constant
- if (NS_SUCCEEDED(rv)) {
- InvalidateCache();
- if (NS_FAILED(file->Clone(getter_AddRefs(mFile)))) {
- NS_WARNING("nsIFile::Clone failed");
- // failure to clone is not fatal (GetFile will generate mFile)
- mFile = nullptr;
- }
+ InvalidateCache();
+ if (NS_FAILED(file->Clone(getter_AddRefs(mFile)))) {
+ NS_WARNING("nsIFile::Clone failed");
+ // failure to clone is not fatal (GetFile will generate mFile)
+ mFile = nullptr;
}
- return rv;
+
+ return NS_OK;
}
//----------------------------------------------------------------------------