Allocate extra byte for NUL termination after HTTP 1.0 read loop, not in it.
authorAdam Piątyszek <ediap@users.sourceforge.net>
Fri, 12 Feb 2010 21:48:08 +0000 (22:48 +0100)
committerDavid Woodhouse <David.Woodhouse@intel.com>
Mon, 22 Feb 2010 14:08:27 +0000 (14:08 +0000)
Signed-off-by: Adam Piątyszek <ediap@users.sourceforge.net>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
http.c

diff --git a/http.c b/http.c
index 5a98a6d..2072001 100644 (file)
--- a/http.c
+++ b/http.c
@@ -268,10 +268,12 @@ static int process_http_response(struct openconnect_info *vpninfo, int *result,
 
                /* HTTP 1.0 response. Just eat all we can in 16KiB chunks */
                while (1) {
-                       body = realloc(body, done + 16385);
+                       body = realloc(body, done + 16384);
                        i = SSL_read(vpninfo->https_ssl, body + done, 16384);
-                       if (i <= 0)
+                       if (i <= 0) {
+                               body = realloc(body, done + 1);
                                break;
+                        }
                        done += i;
                }
        }