NormalizeIDN can (and should, I think) normalize to an empty string in some cases, so don't use AppendSegmentToBuf, which will do the wrong thing with an empty string and potentially overrun buffer. b=307259 r=darin sr=dveditz

This commit is contained in:
dbaron%dbaron.org 2005-09-09 19:06:58 +00:00
Родитель e28922eb61
Коммит 916742999d
1 изменённых файлов: 9 добавлений и 2 удалений

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

@ -467,6 +467,7 @@ nsStandardURL::BuildNormalizedSpec(const char *spec)
nsCAutoString encUsername;
nsCAutoString encPassword;
nsCAutoString encHost;
PRBool useEncHost;
nsCAutoString encDirectory;
nsCAutoString encBasename;
nsCAutoString encExtension;
@ -506,7 +507,7 @@ nsStandardURL::BuildNormalizedSpec(const char *spec)
if (mHost.mLen > 0) {
const nsCSubstring& tempHost =
Substring(spec + mHost.mPos, spec + mHost.mPos + mHost.mLen);
if (NormalizeIDN(tempHost, encHost))
if ((useEncHost = NormalizeIDN(tempHost, encHost)))
approxLen += encHost.Length();
else
approxLen += mHost.mLen;
@ -539,7 +540,13 @@ nsStandardURL::BuildNormalizedSpec(const char *spec)
buf[i++] = '@';
}
if (mHost.mLen > 0) {
i = AppendSegmentToBuf(buf, i, spec, mHost, &encHost);
if (useEncHost) {
mHost.mPos = i;
mHost.mLen = encHost.Length();
i = AppendToBuf(buf, i, encHost.get(), mHost.mLen);
}
else
i = AppendSegmentToBuf(buf, i, spec, mHost);
net_ToLowerCase(buf + mHost.mPos, mHost.mLen);
if (mPort != -1 && mPort != mDefaultPort) {
nsCAutoString portbuf;