Closed Bug 1313028 Opened 5 years ago Closed 5 years ago

GCC 6 null pointer check removal causes segfaulting in ActionResultHolder::GetValueAndDelete()


(Testing :: General, defect)

Not set


(firefox52 fixed)

Tracking Status
firefox52 --- fixed


(Reporter: jseward, Unassigned)




(1 file)

An optimised build with GCC 6.2 on x86_64-Linux, Fedora 23,
results in ./mach gtest eventually segfaulting, due to calling
ActionResultHolder::GetValueAndDelete() with this=0x0.

I suspect it is a result of:

  Result InvokeWith(const ArgumentTuple& args) {
    return static_cast<const ResultHolder*>(

GCC 6 can rightly (per the spec) assume that this->UntypedInvokeWith(&args)
doesn't return a NULL value, since we are subsequently calling
GetValueAndDelete(), implying that we somehow know that the value we
are calling on is non-NULL.  But that isn't always true.  The result
is a null dereference like this:

Invalid read of size 8
   at 0x155C597D: GetValueAndDelete (gmock-spec-builders.h:1357)
   by 0x155C597D: InvokeWith (gmock-spec-builders.h:1490)
   by 0x155C597D: Invoke (gmock-generated-function-mockers.h:76)
   by 0x155C597D: (anonymous namespace)::TestMock::MockedCall() (SanityTest.cpp:20)
   by 0x155C5C2E: MozillaGMockSanity_Runs_Test::TestBody() (SanityTest.cpp:28)
   by 0x155BF91B: testing::Test::Run() (
   by 0x155BFA2B: testing::TestInfo::Run() (
   by 0x155BFAC9: testing::TestCase::Run() (
   by 0x155C05C9: testing::internal::UnitTestImpl::RunAllTests() (
   by 0x155C06C3: HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool> (
   by 0x155C06C3: testing::UnitTest::Run() (
   by 0x155C4D8E: mozilla::RunGTestFunc() (GTestRunner.cpp:118)
   by 0x14F00222: XREMain::XRE_mainStartup(bool*) (nsAppRunner.cpp:3742)
   by 0x14F03AEE: XREMain::XRE_main(int, char**, nsXREAppData const*) (nsAppRunner.cpp:4568)
   by 0x14F03E08: XRE_main (nsAppRunner.cpp:4674)
   by 0x404CA1: do_main(int, char**, char**, nsIFile*) (nsBrowserApp.cpp:282)
 Address 0x0 is not stack'd, malloc'd or (recently) free'd
Per this is a known
problem that has been fixed already in the GTest/GMock trunk, but 
we have an older and unfixed release.  A simple fix for our version,
that appears to work, is shown here:
Proposed fix, as per comment 1.
Attachment #8804806 - Flags: feedback?(cmanchester)
Comment on attachment 8804806 [details] [diff] [review]

I'm not sure what our policy is for maintaining local patches to gmock, BenWa, is there any precedent for this?
Flags: needinfo?(b56girard)
Attachment #8804806 - Flags: feedback?(cmanchester) → feedback+
I'm not aware of us having applied any patches for gtest/gmock.
Flags: needinfo?(b56girard)
Well, would it be OK to land this?  We need to take this fix or
something equivalent, in order to have |mach gtest| work when 
building with gcc 6.
If it's fixed upstream then it seems fine to patch locally until we update our vendored copy to pick up the upstream fix.
Ted; thanks.  Chris, can you pls upgrade your f+ to an r+ so I can land this?
Flags: needinfo?(cmanchester)
Flags: needinfo?(cmanchester)
Attachment #8804806 - Flags: review+
Pushed by
GCC 6 null pointer check removal causes segfaulting in ActionResultHolder::GetValueAndDelete().  r=chmanchester.
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla52
You need to log in before you can comment on or make changes to this bug.