summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvictorw@chromium.org <victorw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-11 22:25:06 +0000
committervictorw@chromium.org <victorw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-11 22:25:06 +0000
commitd4d1b878fde9f01c21a8e247288d56df1e5382c6 (patch)
tree370e50600417adf231ce21a239c57428da1ae034
parent97a28e721396d6337d31e7b532fd4066326cfc0d (diff)
downloadchromium_src-d4d1b878fde9f01c21a8e247288d56df1e5382c6.zip
chromium_src-d4d1b878fde9f01c21a8e247288d56df1e5382c6.tar.gz
chromium_src-d4d1b878fde9f01c21a8e247288d56df1e5382c6.tar.bz2
Do not use CRT strcmp function in PEImage.
This is for chromium dev build with MSVCRT dll. On render process dll initialization, sandbox interception agent patches the dlls, calls PEImage::GetProcOrdinal and GetProcOrdinal calls CRT strcmp function. This may happen before MSVCRT dll loads and crash render process. Using a local string compare function in PEImgage fixes the issue. The patch does not add new functionality and GetProcOrdinal is already covered by existing unittests. R=nsylvain,rvargas BUG=46311 TEST=none Review URL: http://codereview.chromium.org/2756008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49598 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/pe_image.cc23
1 files changed, 22 insertions, 1 deletions
diff --git a/base/pe_image.cc b/base/pe_image.cc
index f2fb140..36eb0e4 100644
--- a/base/pe_image.cc
+++ b/base/pe_image.cc
@@ -21,6 +21,25 @@ struct EnumAllImportsStorage {
PVOID cookie;
};
+namespace {
+
+ // Compare two strings byte by byte on an unsigned basis.
+ // if s1 == s2, return 0
+ // if s1 < s2, return negative
+ // if s1 > s2, return positive
+ // Exception if inputs are invalid.
+ int StrCmpByByte(LPCSTR s1, LPCSTR s2) {
+ while (*s1 != '\0' && *s1 == *s2) {
+ ++s1;
+ ++s2;
+ }
+
+ return (*reinterpret_cast<const unsigned char*>(s1) -
+ *reinterpret_cast<const unsigned char*>(s2));
+ }
+
+} // namespace
+
// Callback used to enumerate imports. See EnumImportChunksFunction.
bool ProcessImportChunk(const PEImage &image, LPCSTR module,
PIMAGE_THUNK_DATA name_table,
@@ -186,7 +205,9 @@ bool PEImage::GetProcOrdinal(LPCSTR function_name, WORD *ordinal) const {
PDWORD middle = lower + (upper - lower) / 2;
LPCSTR name = reinterpret_cast<LPCSTR>(RVAToAddr(*middle));
- cmp = strcmp(function_name, name);
+ // This may be called by sandbox before MSVCRT dll loads, so can't use
+ // CRT function here.
+ cmp = StrCmpByByte(function_name, name);
if (cmp == 0) {
lower = middle;