aboutsummaryrefslogtreecommitdiffstats
path: root/sockets.c
diff options
context:
space:
mode:
authorDavid 'Digit' Turner <digit@google.com>2009-07-10 00:54:05 +0200
committerDavid 'Digit' Turner <digit@google.com>2009-07-10 00:54:05 +0200
commit0b7cd6c0d6af071951a86810d2600d155fa53b05 (patch)
treeb8de0eba2c27ee62fa45e7b8bad079d8a66b25fe /sockets.c
parentc5b127050f2dbed015d6b01703a33062d6910d4a (diff)
downloadexternal_qemu-0b7cd6c0d6af071951a86810d2600d155fa53b05.zip
external_qemu-0b7cd6c0d6af071951a86810d2600d155fa53b05.tar.gz
external_qemu-0b7cd6c0d6af071951a86810d2600d155fa53b05.tar.bz2
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
Diffstat (limited to 'sockets.c')
-rw-r--r--sockets.c15
1 files changed, 9 insertions, 6 deletions
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: