Fix proxy reply parsing broken by the previous commit.
[tinc] / src / proxy.c
index 165d3f3..22d4947 100644 (file)
@@ -203,7 +203,7 @@ int receive_proxy_meta(connection_t *c, int start, int lenin) {
        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;
                }
@@ -256,7 +256,12 @@ int receive_proxy_meta(connection_t *c, int start, int lenin) {
                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;