Bug 1484984 - Avoid writing past the logical length of a string in networking code. r=valentin

MozReview-Commit-ID: IIffoxnF6KS

Differential Revision: https://phabricator.services.mozilla.com/D3884

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Henri Sivonen 2018-08-21 14:20:48 +00:00
parent 9cbf625f78
commit 57d5f3ee13
5 changed files with 7 additions and 7 deletions

View File

@ -886,7 +886,7 @@ HttpConnInfo::SetHTTP2ProtocolVersion(SpdyVersion pv)
NS_IMETHODIMP
Dashboard::GetLogPath(nsACString &aLogPath)
{
aLogPath.SetCapacity(2048);
aLogPath.SetLength(2048);
uint32_t len = LogModule::GetLogFile(aLogPath.BeginWriting(), 2048);
aLogPath.SetLength(len);
return NS_OK;

View File

@ -45,12 +45,12 @@ NS_IMETHODIMP nsNetAddr::GetAddress(nsACString & aAddress)
switch(mAddr.raw.family) {
/* PR_NetAddrToString can handle INET and INET6, but not LOCAL. */
case AF_INET:
aAddress.SetCapacity(kIPv4CStrBufSize);
aAddress.SetLength(kIPv4CStrBufSize);
NetAddrToString(&mAddr, aAddress.BeginWriting(), kIPv4CStrBufSize);
aAddress.SetLength(strlen(aAddress.BeginReading()));
break;
case AF_INET6:
aAddress.SetCapacity(kIPv6CStrBufSize);
aAddress.SetLength(kIPv6CStrBufSize);
NetAddrToString(&mAddr, aAddress.BeginWriting(), kIPv6CStrBufSize);
aAddress.SetLength(strlen(aAddress.BeginReading()));
break;

View File

@ -1344,7 +1344,7 @@ nsSocketTransport::InitiateSocket()
IsIPAddrLocal(&mNetAddr)) {
if (SOCKET_LOG_ENABLED()) {
nsAutoCString netAddrCString;
netAddrCString.SetCapacity(kIPv6CStrBufSize);
netAddrCString.SetLength(kIPv6CStrBufSize);
if (!NetAddrToString(&mNetAddr,
netAddrCString.BeginWriting(),
kIPv6CStrBufSize))

View File

@ -1092,8 +1092,8 @@ Http2Compressor::EncodeHeaderBlock(const nsCString &nvInput,
{
mSetInitialMaxBufferSizeAllowed = false;
mOutput = &output;
output.SetCapacity(1024);
output.Truncate();
output.SetCapacity(1024);
mParsedContentLength = -1;
// first thing's first - context size updates (if necessary)

View File

@ -2591,7 +2591,7 @@ HttpBaseChannel::GetLocalAddress(nsACString& addr)
if (mSelfAddr.raw.family == PR_AF_UNSPEC)
return NS_ERROR_NOT_AVAILABLE;
addr.SetCapacity(kIPv6CStrBufSize);
addr.SetLength(kIPv6CStrBufSize);
NetAddrToString(&mSelfAddr, addr.BeginWriting(), kIPv6CStrBufSize);
addr.SetLength(strlen(addr.BeginReading()));
@ -2700,7 +2700,7 @@ HttpBaseChannel::GetRemoteAddress(nsACString& addr)
if (mPeerAddr.raw.family == PR_AF_UNSPEC)
return NS_ERROR_NOT_AVAILABLE;
addr.SetCapacity(kIPv6CStrBufSize);
addr.SetLength(kIPv6CStrBufSize);
NetAddrToString(&mPeerAddr, addr.BeginWriting(), kIPv6CStrBufSize);
addr.SetLength(strlen(addr.BeginReading()));