From 46773fdde0cc4a3a519067c1d4ad134eb21d0086 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Wed, 23 Jul 2014 10:50:06 -0700 Subject: Fix potential memory violation in CJS_PublicMethods::StrRTrim() BUG=395266 R=jun_fang@foxitsoftware.com Review URL: https://codereview.chromium.org/411713003 --- fpdfsdk/src/javascript/PublicMethods.cpp | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/fpdfsdk/src/javascript/PublicMethods.cpp b/fpdfsdk/src/javascript/PublicMethods.cpp index 08d5cb707c..c030d6cad2 100644 --- a/fpdfsdk/src/javascript/PublicMethods.cpp +++ b/fpdfsdk/src/javascript/PublicMethods.cpp @@ -222,16 +222,10 @@ CFX_WideString CJS_PublicMethods::StrLTrim(FX_LPCWSTR pStr) CFX_WideString CJS_PublicMethods::StrRTrim(FX_LPCWSTR pStr) { FX_LPCWSTR p = pStr; - while (*p) p++; - p--; - if (p >= pStr) - { - while (*p && *p == L' ') p--; - p++; - return CFX_WideString(pStr,p-pStr); - } - return L""; + while (p > pStr && *(p - 1) == L' ') p--; + + return CFX_WideString(pStr, p - pStr); } CFX_WideString CJS_PublicMethods::StrTrim(FX_LPCWSTR pStr) @@ -243,22 +237,16 @@ CFX_ByteString CJS_PublicMethods::StrLTrim(FX_LPCSTR pStr) { while (*pStr && *pStr == ' ') pStr++; - return pStr; + return pStr; } CFX_ByteString CJS_PublicMethods::StrRTrim(FX_LPCSTR pStr) { FX_LPCSTR p = pStr; - while (*p) p++; - p--; - if (p >= pStr) - { - while (*p && *p == ' ') p--; - p++; - return CFX_ByteString(pStr,p-pStr); - } - return ""; + while (p > pStr && *(p - 1) == L' ') p--; + + return CFX_ByteString(pStr,p-pStr); } CFX_ByteString CJS_PublicMethods::StrTrim(FX_LPCSTR pStr) -- cgit v1.2.3