summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMorgan Deters <mdeters@gmail.com>2011-03-10 21:05:13 +0000
committerMorgan Deters <mdeters@gmail.com>2011-03-10 21:05:13 +0000
commit0f4764b2f0e64be5df31cd87a27363cf59045665 (patch)
tree5e48030ea6087b3dfe66e9c37d790b2394070132 /test
parent9be1d8fe09cdc0e5b5b3478f7dab16a218802ec1 (diff)
Fix bug 246 (occasional buffer overflow related to varargs in assertion-failure string construction) and addition of an assert_white unit test check for the issue
Diffstat (limited to 'test')
-rw-r--r--test/unit/util/assert_white.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/unit/util/assert_white.h b/test/unit/util/assert_white.h
index 389f2aa1b..75006ed12 100644
--- a/test/unit/util/assert_white.h
+++ b/test/unit/util/assert_white.h
@@ -71,6 +71,31 @@ public:
} catch(...) {
TS_FAIL("Threw the wrong kind of exception !");
}
+
+ // Now test an assert with a format that drives it over the 512
+ // byte initial buffer. This was a bug in r1441, see bug 246:
+ // http://goedel.cims.nyu.edu/bugzilla3/show_bug.cgi?id=246
+ string fmt = string(200, 'x') + " %s " + string(200, 'x');
+ string arg(200, 'y');
+ try {
+ AlwaysAssert(false, fmt.c_str(), arg.c_str());
+ TS_FAIL("Should have thrown an exception !");
+ } catch(AssertionException& e) {
+ // we don't want to match on the entire string, because it may
+ // have an absolute path to the unit test binary, line number
+ // info, etc.
+ const char* theString = e.toString().c_str();
+ const char* firstPart =
+ "Assertion failure\nvoid AssertWhite::testReallyLongAssert()\n";
+ string lastPartStr = "\n\n false\n" + string(200, 'x') + " " +
+ string(200, 'y') + " " + string(200, 'x');
+ const char* lastPart = lastPartStr.c_str();
+ TS_ASSERT(strncmp(theString, firstPart, strlen(firstPart)) == 0);
+ TS_ASSERT(strncmp(theString + strlen(theString) - strlen(lastPart),
+ lastPart, strlen(lastPart)) == 0);
+ } catch(...) {
+ TS_FAIL("Threw the wrong kind of exception !");
+ }
}
void testUnreachable() {
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback