From d4d1b878fde9f01c21a8e247288d56df1e5382c6 Mon Sep 17 00:00:00 2001 From: "victorw@chromium.org" Date: Fri, 11 Jun 2010 22:25:06 +0000 Subject: 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 --- base/pe_image.cc | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'base/pe_image.cc') 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(s1) - + *reinterpret_cast(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(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; -- cgit v1.1