Log only the first line of a proxy request rejection message.
[tinc] / src / proxy.c
index 165d3f3..227be4a 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;
 
@@ -272,6 +277,8 @@ int receive_proxy_meta(connection_t *c, int start, int lenin) {
                                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;
                        }