From ddb9b7cdd19b63a81c4a094239e85f84acefaa17 Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Fri, 11 Aug 2017 16:20:32 -0400 Subject: Add checks of index operations on string classes Specifically the index parameter passed in to GetAt(), SetAt() and operator[] are now being tested to be in bounds. BUG=chromium:752480, pdfium:828 Change-Id: I9e94d58c98a8eaaaae53cd0e3ffe2123ea17d8c4 Reviewed-on: https://pdfium-review.googlesource.com/10651 Commit-Queue: Ryan Harrison Reviewed-by: Tom Sepez --- core/fxcrt/cfx_string_c_template.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'core/fxcrt/cfx_string_c_template.h') diff --git a/core/fxcrt/cfx_string_c_template.h b/core/fxcrt/cfx_string_c_template.h index 6a95a05d45..bc0fe1e0a0 100644 --- a/core/fxcrt/cfx_string_c_template.h +++ b/core/fxcrt/cfx_string_c_template.h @@ -119,8 +119,13 @@ class CFX_StringCTemplate { FX_STRSIZE GetLength() const { return m_Length; } bool IsEmpty() const { return m_Length == 0; } - UnsignedType GetAt(FX_STRSIZE index) const { return m_Ptr.Get()[index]; } + UnsignedType GetAt(FX_STRSIZE index) const { + ASSERT(index >= 0 && index < GetLength()); + return m_Ptr.Get()[index]; + } + CharType CharAt(FX_STRSIZE index) const { + ASSERT(index >= 0 && index < GetLength()); return static_cast(m_Ptr.Get()[index]); } @@ -159,9 +164,7 @@ class CFX_StringCTemplate { return CFX_StringCTemplate(m_Ptr.Get() + m_Length - count, count); } - const UnsignedType& operator[](size_t index) const { - return m_Ptr.Get()[index]; - } + UnsignedType operator[](FX_STRSIZE index) const { return GetAt(index); } bool operator<(const CFX_StringCTemplate& that) const { int result = FXSYS_cmp(reinterpret_cast(m_Ptr.Get()), -- cgit v1.2.3