From f3e4cfe21e3dffbf416ecb21d7ddd353b026542b Mon Sep 17 00:00:00 2001 From: "dominique.leuenberger@gmail.com" Date: Tue, 27 Aug 2013 18:05:32 +0000 Subject: Fix test #10 Fix the way we detect if get_pac correctly aborted on our server trying to send a > 102400 byte long stream (which we do to avoid malicious pac files/wpad server to buffer overflow us). Replace assert calls with proper error handling, which avoids the server from hanging (the write command to send the quit was wrapped in assert()). When not building for a Debug release with CMAKE, the -DNDEBUG is being specified, which in turn disables the assert macro. Fixes bug 189. git-svn-id: http://libproxy.googlecode.com/svn/trunk@878 c587cffe-e639-0410-9787-d7902ae8ed56 --- NEWS | 1 + libproxy/test/get-pac-test.cpp | 30 +++++++++++++++++++----------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/NEWS b/NEWS index 6d19d3c..ec416da 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,7 @@ New in version * Fix linking of perl bindings to pthread (Bug #182) * Correctly detect spidermonky (mozjs185) (Bug #188) * Stop pxgsettings from segfaulting on exit (Bug #192) +* Fix test #10 (Bug 189) New in version 0.4.11 ============================== diff --git a/libproxy/test/get-pac-test.cpp b/libproxy/test/get-pac-test.cpp index a61fc4b..eaaceb0 100644 --- a/libproxy/test/get-pac-test.cpp +++ b/libproxy/test/get-pac-test.cpp @@ -3,6 +3,8 @@ #include #include +#include // for abort() +#include // for EINTR #include #include #include @@ -58,7 +60,12 @@ class TestServer { void stop() { - assert (write(m_pipe[1], (void*)"q", 1) == 1); + int ret; + do + { + ret = write(m_pipe[1], (void*)"q", 1); + } while (errno == EINTR); + if (ret < 0) abort(); // We could not write to the pipe anymore pthread_join (m_thread, NULL); close(m_pipe[1]); m_pipe[1] = -1; @@ -188,7 +195,8 @@ done: ret = send(csock, (void*)basic, strlen(basic), 0); assert(ret == strlen(basic)); ret = send(csock, (void*)buf, size, 0); - assert(ret != size); + if (!(errno == EBADF)) + abort(); // Test failed... the socket did not close on us delete[] buf; shutdown(csock, SHUT_RDWR); close(ret); @@ -235,21 +243,21 @@ int main() server.start(); pac = basic.get_pac(); - assert(pac != NULL); - assert(strlen(pac) == 10); - assert(!strcmp("0123456789", pac)); - delete[] pac; + if (!(pac != NULL && strlen(pac) == 10 && !strcmp("0123456789", pac))) + return 1; // test failed, exit with error code + delete[] pac; // test succesful, cleanup pac = truncated.get_pac(); - assert(pac == NULL); + if (pac != NULL) + return 2; // Test failed, exit with error code pac = overflow.get_pac(); - assert(pac == NULL); + if (pac != NULL) + return 3; // Test failed, exit with error code pac = chunked.get_pac(); - assert(pac != NULL); - assert(strlen(pac) == 10); - assert(!strcmp("0123456789", pac)); + if (!(pac != NULL && strlen(pac) == 10 && !strcmp("0123456789", pac))) + return 4; // Test failed, exit with error code delete[] pac; server.stop(); -- cgit v1.2.1