summaryrefslogtreecommitdiff
path: root/fpdfsdk/src/javascript
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2014-07-23 10:50:06 -0700
committerTom Sepez <tsepez@chromium.org>2014-07-23 10:50:06 -0700
commit46773fdde0cc4a3a519067c1d4ad134eb21d0086 (patch)
tree6422fc953cf787546ee7e2d9f320ecde487b7074 /fpdfsdk/src/javascript
parent8538642e103530670a69572905557be58e677e1a (diff)
downloadpdfium-46773fdde0cc4a3a519067c1d4ad134eb21d0086.tar.xz
Fix potential memory violation in CJS_PublicMethods::StrRTrim()
BUG=395266 R=jun_fang@foxitsoftware.com Review URL: https://codereview.chromium.org/411713003
Diffstat (limited to 'fpdfsdk/src/javascript')
-rw-r--r--fpdfsdk/src/javascript/PublicMethods.cpp26
1 files 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)