Avoid integer overflow/wraparound in wxString::Mid().
Don't compare nLength with "nFirst + nCount" as this could wrap around. Compare nCount with maximal allowed count, after ensuring that nFirst itself is valid first, instead. Closes #16572. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@77749 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
4d561bf02c
commit
51791822a1
@ -1242,17 +1242,17 @@ wxString wxString::Mid(size_t nFirst, size_t nCount) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
// out-of-bounds requests return sensible things
|
// out-of-bounds requests return sensible things
|
||||||
if ( nFirst + nCount > nLen )
|
|
||||||
{
|
|
||||||
nCount = nLen - nFirst;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( nFirst > nLen )
|
if ( nFirst > nLen )
|
||||||
{
|
{
|
||||||
// AllocCopy() will return empty string
|
// AllocCopy() will return empty string
|
||||||
return wxEmptyString;
|
return wxEmptyString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( nCount > nLen - nFirst )
|
||||||
|
{
|
||||||
|
nCount = nLen - nFirst;
|
||||||
|
}
|
||||||
|
|
||||||
wxString dest(*this, nFirst, nCount);
|
wxString dest(*this, nFirst, nCount);
|
||||||
if ( dest.length() != nCount )
|
if ( dest.length() != nCount )
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user