Bug 1637727 - convert network.standard-url.max-length to a StaticPref. r=KrisWright,necko-reviewers,valentin

Differential Revision: https://phabricator.services.mozilla.com/D77106
This commit is contained in:
Alexis Beingessner 2020-05-29 07:52:35 +00:00
Родитель a908129a6d
Коммит b4d76cf97a
6 изменённых файлов: 33 добавлений и 35 удалений

Просмотреть файл

@ -7791,6 +7791,12 @@
value: true
mirror: always
# The maximum allowed length for a URL - 1MB default.
- name: network.standard-url.max-length
type: RelaxedAtomicUint32
value: 1048576
mirror: always
# Single TRR request timeout, in milliseconds
- name: network.trr.request_timeout_ms
type: RelaxedAtomicUint32

Просмотреть файл

@ -1818,9 +1818,6 @@ pref("network.dns.resolver-thread-extra-idle-time-seconds", 60);
// Whether to disable TRR when parental control is enabled.
pref("network.dns.skipTRR-when-parental-control-enabled", true);
// The maximum allowed length for a URL - 1MB default
pref("network.standard-url.max-length", 1048576);
// Idle timeout for ftp control connections - 5 minute default
pref("network.ftp.idleConnectionTimeout", 300);

Просмотреть файл

@ -790,7 +790,7 @@ nsresult nsStandardURL::BuildNormalizedSpec(const char* spec,
// The encoded string could be longer than the original input, so we need
// to check the final URI isn't longer than the max length.
if (approxLen + 1 > (uint32_t)net_GetURLMaxLength()) {
if (approxLen + 1 > StaticPrefs::network_standard_url_max_length()) {
return NS_ERROR_MALFORMED_URI;
}
@ -949,7 +949,7 @@ nsresult nsStandardURL::BuildNormalizedSpec(const char* spec,
mSpec.Truncate(strlen(buf));
NS_ASSERTION(mSpec.Length() <= approxLen,
"We've overflowed the mSpec buffer!");
MOZ_ASSERT(mSpec.Length() <= (uint32_t)net_GetURLMaxLength(),
MOZ_ASSERT(mSpec.Length() <= StaticPrefs::network_standard_url_max_length(),
"The spec should never be this long, we missed a check.");
MOZ_ASSERT(mUsername.mLen != 0 && mPassword.mLen != 0);
@ -1025,7 +1025,7 @@ int32_t nsStandardURL::ReplaceSegment(uint32_t pos, uint32_t len,
nsresult nsStandardURL::ParseURL(const char* spec, int32_t specLen) {
nsresult rv;
if (specLen > net_GetURLMaxLength()) {
if (specLen > (int32_t)StaticPrefs::network_standard_url_max_length()) {
return NS_ERROR_MALFORMED_URI;
}
@ -1068,7 +1068,7 @@ nsresult nsStandardURL::ParsePath(const char* spec, uint32_t pathPos,
int32_t pathLen) {
LOG(("ParsePath: %s pathpos %d len %d\n", spec, pathPos, pathLen));
if (pathLen > net_GetURLMaxLength()) {
if (pathLen > (int32_t)StaticPrefs::network_standard_url_max_length()) {
return NS_ERROR_MALFORMED_URI;
}
@ -1202,7 +1202,7 @@ NS_INTERFACE_MAP_END
// result may contain unescaped UTF-8 characters
NS_IMETHODIMP
nsStandardURL::GetSpec(nsACString& result) {
MOZ_ASSERT(mSpec.Length() <= (uint32_t)net_GetURLMaxLength(),
MOZ_ASSERT(mSpec.Length() <= StaticPrefs::network_standard_url_max_length(),
"The spec should never be this long, we missed a check.");
nsresult rv = NS_OK;
if (StaticPrefs::network_standard_url_punycode_host()) {
@ -1459,7 +1459,7 @@ nsresult nsStandardURL::SetSpecWithEncoding(const nsACString& input,
const nsPromiseFlatCString& flat = PromiseFlatCString(input);
LOG(("nsStandardURL::SetSpec [spec=%s]\n", flat.get()));
if (input.Length() > (uint32_t)net_GetURLMaxLength()) {
if (input.Length() > StaticPrefs::network_standard_url_max_length()) {
return NS_ERROR_MALFORMED_URI;
}
@ -1556,7 +1556,7 @@ nsresult nsStandardURL::SetScheme(const nsACString& input) {
}
if (mSpec.Length() + input.Length() - Scheme().Length() >
(uint32_t)net_GetURLMaxLength()) {
StaticPrefs::network_standard_url_max_length()) {
return NS_ERROR_MALFORMED_URI;
}
@ -1593,7 +1593,7 @@ nsresult nsStandardURL::SetUserPass(const nsACString& input) {
}
if (mSpec.Length() + input.Length() - Userpass(true).Length() >
(uint32_t)net_GetURLMaxLength()) {
StaticPrefs::network_standard_url_max_length()) {
return NS_ERROR_MALFORMED_URI;
}
@ -1688,7 +1688,7 @@ nsresult nsStandardURL::SetUsername(const nsACString& input) {
}
if (mSpec.Length() + input.Length() - Username().Length() >
(uint32_t)net_GetURLMaxLength()) {
StaticPrefs::network_standard_url_max_length()) {
return NS_ERROR_MALFORMED_URI;
}
@ -1753,7 +1753,7 @@ nsresult nsStandardURL::SetPassword(const nsACString& input) {
}
if (mSpec.Length() + input.Length() - Password().Length() >
(uint32_t)net_GetURLMaxLength()) {
StaticPrefs::network_standard_url_max_length()) {
return NS_ERROR_MALFORMED_URI;
}
@ -1923,7 +1923,7 @@ nsresult nsStandardURL::SetHost(const nsACString& input) {
if (strchr(host, ' ')) return NS_ERROR_MALFORMED_URI;
if (mSpec.Length() + strlen(host) - Host().Length() >
(uint32_t)net_GetURLMaxLength()) {
StaticPrefs::network_standard_url_max_length()) {
return NS_ERROR_MALFORMED_URI;
}
@ -2737,7 +2737,7 @@ nsresult nsStandardURL::SetQueryWithEncoding(const nsACString& input,
if (mPath.mLen < 0) return SetPathQueryRef(flat);
if (mSpec.Length() + input.Length() - Query().Length() >
(uint32_t)net_GetURLMaxLength()) {
StaticPrefs::network_standard_url_max_length()) {
return NS_ERROR_MALFORMED_URI;
}
@ -2805,7 +2805,7 @@ nsresult nsStandardURL::SetRef(const nsACString& input) {
if (mPath.mLen < 0) return SetPathQueryRef(flat);
if (mSpec.Length() + input.Length() - Ref().Length() >
(uint32_t)net_GetURLMaxLength()) {
StaticPrefs::network_standard_url_max_length()) {
return NS_ERROR_MALFORMED_URI;
}
@ -2863,7 +2863,7 @@ nsresult nsStandardURL::SetFileNameInternal(const nsACString& input) {
if (mPath.mLen < 0) return SetPathQueryRef(flat);
if (mSpec.Length() + input.Length() - Filename().Length() >
(uint32_t)net_GetURLMaxLength()) {
StaticPrefs::network_standard_url_max_length()) {
return NS_ERROR_MALFORMED_URI;
}
@ -3054,7 +3054,7 @@ nsresult nsStandardURL::SetFile(nsIFile* file) {
nsresult nsStandardURL::Init(uint32_t urlType, int32_t defaultPort,
const nsACString& spec, const char* charset,
nsIURI* baseURI) {
if (spec.Length() > (uint32_t)net_GetURLMaxLength() ||
if (spec.Length() > StaticPrefs::network_standard_url_max_length() ||
defaultPort > std::numeric_limits<uint16_t>::max()) {
return NS_ERROR_MALFORMED_URI;
}
@ -3241,7 +3241,7 @@ nsresult nsStandardURL::ReadPrivate(nsIObjectInputStream* stream) {
NS_IMETHODIMP
nsStandardURL::Write(nsIObjectOutputStream* stream) {
MOZ_ASSERT(mSpec.Length() <= (uint32_t)net_GetURLMaxLength(),
MOZ_ASSERT(mSpec.Length() <= StaticPrefs::network_standard_url_max_length(),
"The spec should never be this long, we missed a check.");
nsresult rv;
@ -3351,7 +3351,7 @@ inline ipc::StandardURLSegment ToIPCSegment(
}
void nsStandardURL::Serialize(URIParams& aParams) {
MOZ_ASSERT(mSpec.Length() <= (uint32_t)net_GetURLMaxLength(),
MOZ_ASSERT(mSpec.Length() <= StaticPrefs::network_standard_url_max_length(),
"The spec should never be this long, we missed a check.");
StandardURLParams params;
@ -3408,7 +3408,8 @@ bool nsStandardURL::Deserialize(const URIParams& aParams) {
mPort = params.port();
mDefaultPort = params.defaultPort();
mSpec = params.spec();
NS_ENSURE_TRUE(mSpec.Length() <= (uint32_t)net_GetURLMaxLength(), false);
NS_ENSURE_TRUE(
mSpec.Length() <= StaticPrefs::network_standard_url_max_length(), false);
NS_ENSURE_TRUE(FromIPCSegment(mSpec, params.scheme(), mScheme), false);
NS_ENSURE_TRUE(FromIPCSegment(mSpec, params.authority(), mAuthority), false);
NS_ENSURE_TRUE(FromIPCSegment(mSpec, params.username(), mUsername), false);

Просмотреть файл

@ -19,6 +19,7 @@
#include "nsNetCID.h"
#include "mozilla/Preferences.h"
#include "prnetdb.h"
#include "mozilla/StaticPrefs_network.h"
#include "mozilla/Tokenizer.h"
#include "nsEscape.h"
#include "mozilla/net/rust_helper.h"
@ -33,7 +34,6 @@ static bool gInitialized = false;
static nsIURLParser* gNoAuthURLParser = nullptr;
static nsIURLParser* gAuthURLParser = nullptr;
static nsIURLParser* gStdURLParser = nullptr;
static int32_t gMaxLength = 1048576; // Default: 1MB
static void InitGlobals() {
nsCOMPtr<nsIURLParser> parser;
@ -60,8 +60,6 @@ static void InitGlobals() {
}
gInitialized = true;
Preferences::AddIntVarCache(&gMaxLength, "network.standard-url.max-length",
1048576);
}
void net_ShutdownURLHelper() {
@ -73,8 +71,6 @@ void net_ShutdownURLHelper() {
}
}
int32_t net_GetURLMaxLength() { return gMaxLength; }
//----------------------------------------------------------------------------
// nsIURLParser getters
//----------------------------------------------------------------------------
@ -139,7 +135,8 @@ nsresult net_ParseFileURL(const nsACString& inURL, nsACString& outDirectory,
nsACString& outFileExtension) {
nsresult rv;
if (inURL.Length() > (uint32_t)gMaxLength) {
if (inURL.Length() >
(uint32_t)StaticPrefs::network_standard_url_max_length()) {
return NS_ERROR_MALFORMED_URI;
}

Просмотреть файл

@ -221,10 +221,4 @@ bool net_IsValidIPv4Addr(const nsACString& aAddr);
*/
bool net_IsValidIPv6Addr(const nsACString& aAddr);
/**
* Returns the max length of a URL. The default is 1048576 (1 MB).
* Can be changed by pref "network.standard-url.max-length"
*/
int32_t net_GetURLMaxLength();
#endif // !nsURLHelper_h__

Просмотреть файл

@ -10,8 +10,11 @@
#include "nsEscape.h"
#include "nsIFile.h"
#include <windows.h>
#include "mozilla/StaticPrefs_network.h"
#include "mozilla/Utf8.h"
using namespace mozilla;
nsresult net_GetURLSpecFromActualFile(nsIFile* aFile, nsACString& result) {
nsresult rv;
nsAutoString path;
@ -49,7 +52,7 @@ nsresult net_GetURLSpecFromActualFile(nsIFile* aFile, nsACString& result) {
nsresult net_GetFileFromURLSpec(const nsACString& aURL, nsIFile** result) {
nsresult rv;
if (aURL.Length() > (uint32_t)net_GetURLMaxLength()) {
if (aURL.Length() > StaticPrefs::network_standard_url_max_length()) {
return NS_ERROR_MALFORMED_URI;
}
@ -92,7 +95,7 @@ nsresult net_GetFileFromURLSpec(const nsACString& aURL, nsIFile** result) {
// remove leading '\'
if (path.CharAt(0) == '\\') path.Cut(0, 1);
if (mozilla::IsUtf8(path))
if (IsUtf8(path))
rv = localFile->InitWithPath(NS_ConvertUTF8toUTF16(path));
// XXX In rare cases, a valid UTF-8 string can be valid as a native
// encoding (e.g. 0xC5 0x83 is valid both as UTF-8 and Windows-125x).