From ed2352bfe7e95f95bf52e2b5e1db56d0ffba787b Mon Sep 17 00:00:00 2001 From: "benjamin%smedbergs.us" Date: Mon, 26 Jan 2009 17:07:45 +0000 Subject: [PATCH] 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 --- .../xpcom/string/src/nsTStringObsolete.cpp | 9 +++++++ mozilla/xpcom/tests/TestStrings.cpp | 27 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/mozilla/xpcom/string/src/nsTStringObsolete.cpp b/mozilla/xpcom/string/src/nsTStringObsolete.cpp index c1425a6ba07..6ee42d31140 100644 --- a/mozilla/xpcom/string/src/nsTStringObsolete.cpp +++ b/mozilla/xpcom/string/src/nsTStringObsolete.cpp @@ -193,6 +193,8 @@ nsTString_CharT::ToInteger( PRInt32* aErrorCode, PRUint32 aRadix ) const PRBool haveValue = PR_FALSE; while(cpstr; ++t) { + PRInt32 result = nsCAutoString(t->str).ToInteger(&rv, t->radix); + if (rv != t->rv || result != t->result) + return PR_FALSE; + } + return PR_TRUE; +} + //---- typedef PRBool (*TestFunc)(); @@ -936,6 +962,7 @@ tests[] = { "test_stringbuffer", test_stringbuffer }, { "test_voided", test_voided }, { "test_voided_autostr", test_voided_autostr }, + { "test_string_tointeger", test_string_tointeger }, { nsnull, nsnull } };