Re: [googletest] No failing status for std::vector::insert using invalidated iterator

42 views
Skip to first unread message

Billy O'Neal

unread,
May 20, 2013, 12:38:13 PM5/20/13
to Andrey Z., googletes...@googlegroups.com
You invoked undefined behavior. Undefined behavior does not "throw an exception" or anything like that. Some implementations will failfast the program if you try to do that in debug mode, which GTest cannot handle. Others may give silent corruption
 
Unless you are using death tests, GTest doesn't run each test in a separate process, so there's really no way for it to recover from this. Memory corruption corrupts Google Test too.
Billy O'Neal
--------------------------------------------------------------
Malware Response Instructor - BleepingComputer.com


On Mon, May 20, 2013 at 5:23 AM, Andrey Z. <zam...@gmail.com> wrote:
Hi,

if I try testing a code like this:

TEST(SampleTest, Test0)
{
  std::vector< int> a(0,1);
  std::vector< int>::iterator itE=a.end();
  a.insert(itE, 1);
  a.insert(itE, 2);
}
which basically tries to insert a new element to the invalid position, Google Test framework will report this:

Note: Google Test filter = SampleTest.Test0
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from SampleTest
[ RUN      ] SampleTest.Test0

It looks like it tries to handle SEH exception but fails to allocate new memory because of corruption and has to finish test silently. 
Is there a way to make gtest report test as failing?

Thanks
Andrey

--
 
---
You received this message because you are subscribed to the Google Groups "Google C++ Testing Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to googletestframe...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Josh Kelley

unread,
May 20, 2013, 10:10:32 PM5/20/13
to Andrey Z., Google C++ Testing Framework
On Mon, May 20, 2013 at 5:23 AM, Andrey Z. <zam...@gmail.com> wrote:
It looks like it tries to handle SEH exception but fails to allocate new memory because of corruption and has to finish test silently. 
Is there a way to make gtest report test as failing?
 
Although this is in the realm of undefined behavior (as Billy O'Neal explained), several Standard Library implementations have optional debugging that should help catch problems like this.  I'd recommend enabling it when building your test suites.

For example:
Visual C++ - http://msdn.microsoft.com/en-us/library/aa985982%28v=vs.110%29.aspx
GCC - http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt03ch17s03.html#debug_mode.using.mode

--
Josh Kelley

Andrey Z.

unread,
May 21, 2013, 2:57:01 AM5/21/13
to googletes...@googlegroups.com, Andrey Z.
On Tuesday, May 21, 2013 5:10:32 AM UTC+3, Josh Kelley wrote:
On Mon, May 20, 2013 at 5:23 AM, Andrey Z. <zam...@gmail.com> wrote:
It looks like it tries to handle SEH exception but fails to allocate new memory because of corruption and has to finish test silently. 
Is there a way to make gtest report test as failing?
 
Although this is in the realm of undefined behavior (as Billy O'Neal explained), several Standard Library implementations have optional debugging that should help catch problems like this.  I'd recommend enabling it when building your test suites.

Thanks for a suggestion. 
Static library being tested in my case is built with the fixed iterator setup (_SECURE_SCL=0) and I can't use different settings in test application, since it will lead to inconsistent binary format.

Andrey

Andrey Z.

unread,
May 21, 2013, 3:31:40 AM5/21/13
to googletes...@googlegroups.com
Thank you, I'd definitely try death tests.

Billy O'Neal

unread,
May 21, 2013, 1:00:37 PM5/21/13
to Andrey Z., googletes...@googlegroups.com
Death tests don't solve the problem. They just make it such that the test itself can't corrupt Google Test.

Billy O'Neal
--------------------------------------------------------------
Malware Response Instructor - BleepingComputer.com


Reply all
Reply to author
Forward
0 new messages