Bug 473587 - nsTString::ToInteger can overflow. Detect and prevent this condition, r+sr=dbaron
git-svn-id: svn://10.0.0.236/trunk@255922 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -193,6 +193,8 @@ nsTString_CharT::ToInteger( PRInt32* aErrorCode, PRUint32 aRadix ) const
|
||||
PRBool haveValue = PR_FALSE;
|
||||
|
||||
while(cp<endcp){
|
||||
PRInt32 oldresult = result;
|
||||
|
||||
theChar=*cp++;
|
||||
if(('0'<=theChar) && (theChar<='9')){
|
||||
result = (theRadix * result) + (theChar-'0');
|
||||
@@ -246,6 +248,13 @@ nsTString_CharT::ToInteger( PRInt32* aErrorCode, PRUint32 aRadix ) const
|
||||
//we've encountered a char that's not a legal number or sign
|
||||
break;
|
||||
}
|
||||
|
||||
if (result < oldresult) {
|
||||
// overflow!
|
||||
*aErrorCode = NS_ERROR_ILLEGAL_VALUE;
|
||||
result = 0;
|
||||
break;
|
||||
}
|
||||
} //while
|
||||
if(negate)
|
||||
result=-result;
|
||||
|
||||
Reference in New Issue
Block a user