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_bytestring.h | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'core/fxcrt/cfx_bytestring.h') diff --git a/core/fxcrt/cfx_bytestring.h b/core/fxcrt/cfx_bytestring.h index cf688b4c88..df31751273 100644 --- a/core/fxcrt/cfx_bytestring.h +++ b/core/fxcrt/cfx_bytestring.h @@ -107,15 +107,14 @@ class CFX_ByteString { const CFX_ByteString& operator+=(const CFX_ByteString& str); const CFX_ByteString& operator+=(const CFX_ByteStringC& bstrc); - uint8_t GetAt(FX_STRSIZE nIndex) const { - return m_pData ? m_pData->m_String[nIndex] : 0; + uint8_t GetAt(FX_STRSIZE index) const { + ASSERT(index >= 0 && index < GetLength()); + return m_pData->m_String[index]; } - uint8_t operator[](FX_STRSIZE nIndex) const { - return m_pData ? m_pData->m_String[nIndex] : 0; - } + uint8_t operator[](FX_STRSIZE index) const { return GetAt(index); } - void SetAt(FX_STRSIZE nIndex, char ch); + void SetAt(FX_STRSIZE index, char c); FX_STRSIZE Insert(FX_STRSIZE index, char ch); FX_STRSIZE InsertAtFront(char ch) { return Insert(0, ch); } FX_STRSIZE InsertAtBack(char ch) { return Insert(GetLength(), ch); } -- cgit v1.2.3