case PROXY_SOCKS5:
if(c->buflen < 2)
return 0;
- if(c->buffer[0] != 0x05 || c->buffer[1] == 0xff) {
+ if(c->buffer[0] != 0x05 || c->buffer[1] == (char)0xff) {
logger(LOG_ERR, "Proxy authentication method rejected");
return -1;
}
char *p = memchr(c->buffer, '\n', c->buflen);
if(!p || p - c->buffer >= c->buflen)
return 0;
- p = memchr(p + 1, '\n', c->buflen - (p + 1 - c->buffer));
+
+ while((p = memchr(p + 1, '\n', c->buflen - (p + 1 - c->buffer)))) {
+ if(p > c->buffer + 3 && !memcmp(p - 3, "\r\n\r\n", 4))
+ break;
+ }
+
if(!p)
return 0;
c->allow_request = ID;
return replen;
} else {
+ p = memchr(c->buffer, '\n', c->buflen);
+ p[-1] = 0;
logger(LOG_ERR, "Proxy request rejected: %s", c->buffer + 9);
return false;
}