Breakpad processor: Fix function and public symbol lookup.

In r480, I botched the change to make the comparisons that decide
whether an address falls within a function's range safe from overflow.
The original code said:

  address >= function_base && address < function_base + function_size

which is fine unless the function abuts the end of the address space,
in which case the addition overflows and you get a false negative.

My change subtracted function_size from both sides of the latter
comparison, which is meaning-preserving in true math, and gets you:

  address >= function_base && address - function_size < function_base

This not only reads strangely, but also still overflows if
function_size is greater than address. That's rare, but I've added a
case to the unit tests that checks it.

My intent had been to replace the addition which could overflow with a
subtraction that was known not to overflow, namely:

  address >= function_base && address - function_base < function_size

This is equivalent to the original in true math, and because of the
first comparison, we know the subtraction won't underflow in MemAddr
math.

The patch includes similar fixes to the public symbol lookup code, and
to FindWindowsFrameInfo, which was the only other function affected by
r480.

a=jimblandy, r=mmentovai


git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@503 4c0a9323-5329-0410-9bdc-e9ce6186880e
This commit is contained in:
jimblandy 2010-01-28 05:17:23 +00:00
parent 384b1c7d7d
commit 03ebc1d245
3 changed files with 17 additions and 4 deletions

View file

@ -63,7 +63,7 @@ class TestCodeModule : public CodeModule {
virtual ~TestCodeModule() {}
virtual u_int64_t base_address() const { return 0; }
virtual u_int64_t size() const { return 0x4000; }
virtual u_int64_t size() const { return 0xb000; }
virtual string code_file() const { return code_file_; }
virtual string code_identifier() const { return ""; }
virtual string debug_file() const { return ""; }
@ -162,6 +162,16 @@ static bool RunTests() {
frame_info.reset(resolver.FindWindowsFrameInfo(&frame));
ASSERT_FALSE(frame_info.get());
frame.instruction = 0x2900;
frame.module = &module1;
resolver.FillSourceLineInfo(&frame);
ASSERT_EQ(frame.function_name, string("PublicSymbol"));
frame.instruction = 0x4000;
frame.module = &module1;
resolver.FillSourceLineInfo(&frame);
ASSERT_EQ(frame.function_name, string("LargeFunction"));
TestCodeModule module2("module2");
frame.instruction = 0x2181;