Ensure a string is properly terminated in http_client.c
authorMatt Caswell <matt@openssl.org>
Thu, 25 Jun 2020 11:21:07 +0000 (12:21 +0100)
committerMatt Caswell <matt@openssl.org>
Fri, 3 Jul 2020 16:18:41 +0000 (17:18 +0100)
In HTTP_new_bio(), if the host has a trailing '/' we took a copy of the
hostname but failed to terminate it properly.

Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com>
Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/12275)

crypto/http/http_client.c

index a8dda0050ac6586a36247b8e56587f1d155dddd1..3e1be1f569d670d86e994badd21c0281ab0a09f1 100644 (file)
@@ -712,10 +712,15 @@ static BIO *HTTP_new_bio(const char *server /* optionally includes ":port" */,
     }
 
     host_end = strchr(host, '/');
-    if (host_end != NULL && (size_t)(host_end - host) < sizeof(host_name)) {
-        /* chop trailing string starting with '/' */
-        strncpy(host_name, host, host_end - host + 1);
-        host = host_name;
+    if (host_end != NULL) {
+        size_t host_len = host_end - host;
+
+        if (host_len < sizeof(host_name)) {
+            /* chop trailing string starting with '/' */
+            strncpy(host_name, host, host_len);
+            host_name[host_len] = '\0';
+            host = host_name;
+        }
     }
 
     cbio = BIO_new_connect(host /* optionally includes ":port" */);