summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordominique.leuenberger@gmail.com <dominique.leuenberger@gmail.com@c587cffe-e639-0410-9787-d7902ae8ed56>2013-08-27 18:05:32 +0000
committerdominique.leuenberger@gmail.com <dominique.leuenberger@gmail.com@c587cffe-e639-0410-9787-d7902ae8ed56>2013-08-27 18:05:32 +0000
commitf3e4cfe21e3dffbf416ecb21d7ddd353b026542b (patch)
treecbc05c4213162b9043d6de40cf838645cb218d5d
parenta59476b9d5bc67d22f9390ec0209dc93c5f8095d (diff)
downloadlibproxy-f3e4cfe21e3dffbf416ecb21d7ddd353b026542b.tar.gz
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
-rw-r--r--NEWS1
-rw-r--r--libproxy/test/get-pac-test.cpp30
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 <NEXT>
* 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 <sstream>
#include <string>
+#include <stdlib.h> // for abort()
+#include <errno.h> // for EINTR
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
@@ -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();