From 0b7cd6c0d6af071951a86810d2600d155fa53b05 Mon Sep 17 00:00:00 2001 From: David 'Digit' Turner Date: Fri, 10 Jul 2009 00:54:05 +0200 Subject: Fix bad zero-termination bug in the socket string formatter. This created, among other things, malformed CONNECT proxy requests, depending on the state of the stack --- sockets.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'sockets.c') diff --git a/sockets.c b/sockets.c index 2e61d9a..338b176 100644 --- a/sockets.c +++ b/sockets.c @@ -255,11 +255,14 @@ void sock_address_done( SockAddress* a ) static char* format_char( char* buf, char* end, int c ) { - if (buf >= end) - return buf; - if (buf+1 == end) - c = 0; - *buf++ = (char) c; + if (buf < end) { + if (buf+1 == end) { + *buf++ = 0; + } else { + *buf++ = (char) c; + *buf = 0; + } + } return buf; } @@ -350,7 +353,7 @@ const char* sock_address_to_string( const SockAddress* a ) { static char buf0[MAX_PATH]; - char *buf = buf0, *end = buf + sizeof(buf0); + char *buf = buf0, *end = buf + sizeof(buf0); switch (a->family) { case SOCKET_INET: -- cgit v1.1