From: Fabian Keil <fk@fabiankeil.de>
Date: Wed, 29 Feb 2012 19:35:11 +0000 (+0000)
Subject: In socks5_connect(), do not try to print a negative number ...
X-Git-Tag: v_3_0_20~414
X-Git-Url: http://www.privoxy.org/gitweb/user-manual/static/faq/static/gitweb.js?a=commitdiff_plain;h=534dba7e665aeec58782c2d823eb23367b0446cf;p=privoxy.git

In socks5_connect(), do not try to print a negative number ...

... of socks response bytes if the read() for the socks5
negotiation failed completely.

It's an API violation and can trigger an assert() in
debug builds with "debug 2" enabled. Except for the
assert(), log_error() already handled negative %N values
gracefully so this commit only makes a difference for
debug builds.
---

diff --git a/gateway.c b/gateway.c
index aedbc89e..2e43cb83 100644
--- a/gateway.c
+++ b/gateway.c
@@ -1,4 +1,4 @@
-const char gateway_rcs[] = "$Id: gateway.c,v 1.82 2011/10/23 11:21:28 fabiankeil Exp $";
+const char gateway_rcs[] = "$Id: gateway.c,v 1.83 2011/12/24 15:28:45 fabiankeil Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/gateway.c,v $
@@ -1116,6 +1116,15 @@ static jb_socket socks5_connect(const struct forward_spec *fwd,
 
    assert(errstr != NULL);
    csp->error_message = strdup(errstr);
+   if (server_size == -1)
+   {
+      /*
+       * We didn't read() anything from the server at all.
+       * Don't try to log a negative number of characters
+       * which could trigger an assert().
+       */
+      server_size = 0;
+   }
    log_error(LOG_LEVEL_CONNECT, "socks5_connect: %s: %N", errstr, server_size, sbuf);
    close_socket(sfd);
    errno = EINVAL;