Skip to content

Commit 84f03b3

Browse files
committed
streams: openssl: fix use of uninitialized variable
When verifying the server certificate, we do try to make sure that the hostname actually matches the certificate alternative names. In cases where the host is either an IPv4 or IPv6 address, we have to compare the binary representations of the hostname with the declared IP address of the certificate. We only do that comparison in case we were successfully able to parse the hostname as an IP, which would always result in the memory region being initialized. Still, GCC 6.4.0 was complaining about usage of non-initialized memory. Fix the issue by simply asserting that `addr` needs to be initialized. This shuts up the GCC warning.
1 parent b8cb753 commit 84f03b3

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/streams/openssl.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ static int verify_server_cert(SSL *ssl, const char *host)
344344
GENERAL_NAMES *alts;
345345
struct in6_addr addr6;
346346
struct in_addr addr4;
347-
void *addr;
347+
void *addr = NULL;
348348
int i = -1, j, error = 0;
349349

350350
if (SSL_get_verify_result(ssl) != X509_V_OK) {
@@ -357,7 +357,7 @@ static int verify_server_cert(SSL *ssl, const char *host)
357357
type = GEN_IPADD;
358358
addr = &addr4;
359359
} else {
360-
if(p_inet_pton(AF_INET6, host, &addr6)) {
360+
if (p_inet_pton(AF_INET6, host, &addr6)) {
361361
type = GEN_IPADD;
362362
addr = &addr6;
363363
}
@@ -397,7 +397,7 @@ static int verify_server_cert(SSL *ssl, const char *host)
397397
matched = 1;
398398
} else if (type == GEN_IPADD) {
399399
/* Here name isn't so much a name but a binary representation of the IP */
400-
matched = !!memcmp(name, addr, namelen);
400+
matched = addr && !!memcmp(name, addr, namelen);
401401
}
402402
}
403403
}

0 commit comments

Comments
 (0)