mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-03 15:26:07 +00:00
bug 164695 prevent heap overrun if jar manifest file has size -1 (corrupt/malicious archive). Also fixes unrelated potential memory leak. r=mstoltz, sr=darin, a=roc
This commit is contained in:
parent
3d5579582f
commit
e37635e2c0
@ -424,13 +424,18 @@ nsJAR::LoadEntry(const char* aFilename, char** aBuf, PRUint32* aBufLen)
|
||||
PRUint32 len;
|
||||
rv = manifestStream->Available(&len);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (len == PRUint32(-1))
|
||||
return NS_ERROR_FILE_CORRUPTED; // bug 164695
|
||||
buf = (char*)PR_MALLOC(len+1);
|
||||
if (!buf) return NS_ERROR_OUT_OF_MEMORY;
|
||||
PRUint32 bytesRead;
|
||||
rv = manifestStream->Read(buf, len, &bytesRead);
|
||||
if (bytesRead != len)
|
||||
rv = NS_ERROR_FILE_CORRUPTED;
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (NS_FAILED(rv)) {
|
||||
PR_FREEIF(buf);
|
||||
return rv;
|
||||
}
|
||||
buf[len] = '\0'; //Null-terminate the buffer
|
||||
*aBuf = buf;
|
||||
if (aBufLen)
|
||||
|
Loading…
x
Reference in New Issue
Block a user