summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul van Tilburg <paul.van.tilburg@leftclick.eu>2016-09-12 10:55:59 +0000
committerPaul van Tilburg <paul.van.tilburg@leftclick.eu>2016-09-19 15:10:17 +0200
commitf8d37660f8a29ecf2c1cfda6fbfebf3acdd9c08a (patch)
tree4a65539a7365be83fd6f4fec3be02195e5d2252b
parent5e0f3abde2def9885b8a0218f10324163a7a6da3 (diff)
downloadlibproxy-git-f8d37660f8a29ecf2c1cfda6fbfebf3acdd9c08a.tar.gz
Handle PAC files without specified HTTP content length
-rw-r--r--libproxy/url.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/libproxy/url.cpp b/libproxy/url.cpp
index 9c69917..6176482 100644
--- a/libproxy/url.cpp
+++ b/libproxy/url.cpp
@@ -53,6 +53,8 @@ using namespace std;
// This is the maximum pac size (to avoid memory attacks)
#define PAC_MAX_SIZE 102400
+// This is the default block size to use when receiving via HTTP
+#define PAC_HTTP_BLOCK_SIZE 512
static inline int get_default_port(string scheme) {
struct servent *serv;
@@ -448,6 +450,7 @@ char* url::get_pac() {
string line = recvline(sock);
if (sscanf(line.c_str(), "HTTP/1.%*d %lu", &status) == 1 && status == 200) {
/* Check for correct mime type and content length */
+ content_length = 0;
for (line = recvline(sock) ; line != "\r" && line != "" ; line = recvline(sock)) {
// Check for chunked encoding
if (line.find("Content-Transfer-Encoding: chunked") == 0 || line.find("Transfer-Encoding: chunked") == 0)
@@ -479,8 +482,10 @@ char* url::get_pac() {
if (content_length >= PAC_MAX_SIZE) break;
- while (recvd != content_length) {
- int r = recv(sock, buffer + recvd, content_length - recvd, 0);
+ while (content_length == 0 || recvd != content_length) {
+ int r = recv(sock, buffer + recvd,
+ content_length == 0 ? PAC_HTTP_BLOCK_SIZE
+ : content_length - recvd, 0);
if (r <= 0) {
chunked = false;
break;
@@ -489,7 +494,7 @@ char* url::get_pac() {
}
} while (chunked);
- if (string(buffer).size() != content_length) {
+ if (content_length != 0 && string(buffer).size() != content_length) {
delete[] buffer;
buffer = NULL;
}