------------------------------------------------------------ revno: 12439 revision-id: squid3@treenet.co.nz-20130102040707-fw8k1teecddqu6s2 parent: squid3@treenet.co.nz-20130102040515-un4kc5pjeqark53i committer: Amos Jeffries branch nick: 3.3 timestamp: Tue 2013-01-01 21:07:07 -0700 message: Fix various issues in unit tests * Define MemObject stub constructor to initialize teh stub object properly apparently store unit tests needs one defined. Best to make it work and set base values than leave garbage in the object fields. * Buffer overrun on config parser if test is ever given a too-long string input. * Memory leak in HttpRequest testing. One instance of a short array. * Range: header testing may thor exceptions which were not caught by the test binary. Could lead to difficulty debugging exception errors. Detected by Coverity Scan. Issues 740523, 740482, 740440, 740498 ------------------------------------------------------------ # Bazaar merge directive format 2 (Bazaar 0.90) # revision_id: squid3@treenet.co.nz-20130102040707-fw8k1teecddqu6s2 # target_branch: http://bzr.squid-cache.org/bzr/squid3/3.3 # testament_sha1: 271f26e404dcb214a3cabebad05b4da091a61e11 # timestamp: 2013-01-02 04:08:51 +0000 # source_branch: http://bzr.squid-cache.org/bzr/squid3/3.3 # base_revision_id: squid3@treenet.co.nz-20130102040515-\ # un4kc5pjeqark53i # # Begin patch === modified file 'src/tests/stub_MemObject.cc' --- src/tests/stub_MemObject.cc 2012-06-18 23:08:56 +0000 +++ src/tests/stub_MemObject.cc 2013-01-02 04:07:07 +0000 @@ -21,7 +21,25 @@ void MemObject::trimSwappable() STUB void MemObject::trimUnSwappable() STUB int64_t MemObject::policyLowestOffsetToKeep(bool swap) const STUB_RETVAL(-1) -MemObject::MemObject(char const *, char const *) {} // NOP due to Store +MemObject::MemObject(char const *, char const *) : + url(NULL), + inmem_lo(0), + nclients(0), + request(NULL), + ping_reply_callback(NULL), + ircb_data(NULL), + log_url(NULL), + id(0), + object_sz(-1), + swap_hdr_sz(0), + vary_headers(NULL), + _reply(NULL) +{ + memset(&clients, 0, sizeof(clients)); + memset(&start_ping, 0, sizeof(start_ping)); + memset(&abort, 0, sizeof(abort)); +} // NOP instead of elided due to Store + HttpReply const * MemObject::getReply() const { // XXX: required by testStore === modified file 'src/tests/testConfigParser.cc' --- src/tests/testConfigParser.cc 2012-08-24 09:57:00 +0000 +++ src/tests/testConfigParser.cc 2013-01-02 04:07:07 +0000 @@ -30,8 +30,10 @@ fprintf(stderr, "Invalid config line: %s\n", s); return false; } + // Keep the initial value on cfgparam. The ConfigParser methods will write on cfgline - strcpy(cfgparam, tmp+1); + strncpy(cfgparam, tmp+1, sizeof(cfgparam)-1); + cfgparam[sizeof(cfgparam)-1] = '\0'; // Initialize parser to point to the start of quoted string strtok(cfgline, w_space); === modified file 'src/tests/testHttpRequest.cc' --- src/tests/testHttpRequest.cc 2012-08-31 16:57:39 +0000 +++ src/tests/testHttpRequest.cc 2013-01-02 04:07:07 +0000 @@ -57,6 +57,7 @@ CPPUNIT_ASSERT_EQUAL(String("/bar"), aRequest->urlpath); CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_HTTP, aRequest->protocol); CPPUNIT_ASSERT_EQUAL(String("http://foo/bar"), String(url)); + xfree(url); /* a connect url with non-CONNECT data */ url = xstrdup(":foo/bar"); === modified file 'src/tests/test_http_range.cc' --- src/tests/test_http_range.cc 2012-10-03 17:32:57 +0000 +++ src/tests/test_http_range.cc 2013-01-02 04:07:07 +0000 @@ -187,17 +187,25 @@ } int -main (int argc, char **argv) +main(int argc, char **argv) { - Mem::Init(); - /* enable for debugging to console */ - // _db_init (NULL, NULL); - // Debug::Levels[64] = 9; - testRangeParser ("bytes=0-3"); - testRangeParser ("bytes=-3"); - testRangeParser ("bytes=1-"); - testRangeParser ("bytes=0-3, 1-, -2"); - testRangeIter (); - testRangeCanonization(); + try{ + Mem::Init(); + /* enable for debugging to console */ + // _db_init (NULL, NULL); + // Debug::Levels[64] = 9; + testRangeParser("bytes=0-3"); + testRangeParser("bytes=-3"); + testRangeParser("bytes=1-"); + testRangeParser("bytes=0-3, 1-, -2"); + testRangeIter(); + testRangeCanonization(); + } catch (const std::exception &e) { + printf("Error: dying from an unhandled exception: %s\n", e.what()); + return 1; + } catch (...) { + printf("Error: dying from an unhandled exception.\n"); + return 1; + } return 0; }