Null terminate the punycode encoded string,

bug 198437, r=shanjian, sr=darin.
This commit is contained in:
nhotta%netscape.com 2003-03-21 00:23:12 +00:00
parent ffa7725b75
commit cbc48d4f51

View File

@ -232,7 +232,7 @@ static nsresult punycode(const char* prefix, const nsAString& in, nsACString& ou
// (include null terminator)
const PRUint32 kEncodedBufSize = kMaxDNSNodeLen * 20 / 8 + 1 + 1;
char encodedBuf[kEncodedBufSize];
punycode_uint encodedLength;
punycode_uint encodedLength = kEncodedBufSize;
enum punycode_status status = punycode_encode(ucs4Len,
ucs4Buf,
@ -240,9 +240,11 @@ static nsresult punycode(const char* prefix, const nsAString& in, nsACString& ou
&encodedLength,
encodedBuf);
if (punycode_success != status)
if (punycode_success != status ||
encodedLength >= kEncodedBufSize)
return NS_ERROR_FAILURE;
encodedBuf[encodedLength] = '\0';
out.Assign(nsDependentCString(prefix) + nsDependentCString(encodedBuf));
return NS_OK;