Skip to content

Commit 00ee9a7

Browse files
committed
Avoid truncation of SSL_get_verify_result(3) return value
1 parent 32a93b9 commit 00ee9a7

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/netlog/netlog-tls.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ int ssl_verify_certificate_validity(int s, X509_STORE_CTX *store) {
3535
_cleanup_free_ char *pretty = NULL;
3636
union sockaddr_union sa;
3737
int r;
38+
long rc;
3839

3940
assert(store);
4041

@@ -57,26 +58,26 @@ int ssl_verify_certificate_validity(int s, X509_STORE_CTX *store) {
5758
return 1;
5859
}
5960

60-
r = SSL_get_verify_result(ssl);
61-
if (r != X509_V_OK) {
62-
switch(r) {
61+
rc = SSL_get_verify_result(ssl);
62+
if (rc != X509_V_OK) {
63+
switch(rc) {
6364
case X509_V_ERR_CERT_HAS_EXPIRED: {
6465
switch (m->auth_mode) {
6566
case OPEN_SSL_CERTIFICATE_AUTH_MODE_DENY: {
6667
log_error_errno(SYNTHETIC_ERRNO(EINVAL),
67-
"TLS: Failed to verify certificate server=%s: %s", pretty, X509_verify_cert_error_string(r));
68+
"TLS: Failed to verify certificate server=%s: %s", pretty, X509_verify_cert_error_string(rc));
6869
return 0;
6970
}
7071
break;
7172
case OPEN_SSL_CERTIFICATE_AUTH_MODE_WARN: {
7273
log_warning_errno(SYNTHETIC_ERRNO(EINVAL),
73-
"TLS: Failed to verify certificate server=%s: %s", pretty, X509_verify_cert_error_string(r));
74+
"TLS: Failed to verify certificate server=%s: %s", pretty, X509_verify_cert_error_string(rc));
7475

7576
return 1;
7677
}
7778
break;
7879
case OPEN_SSL_CERTIFICATE_AUTH_MODE_ALLOW: {
79-
log_debug("TLS: Failed to verify certificate server=%s: %s", pretty, X509_verify_cert_error_string(r));
80+
log_debug("TLS: Failed to verify certificate server=%s: %s", pretty, X509_verify_cert_error_string(rc));
8081
return 1;
8182
}
8283

@@ -89,20 +90,20 @@ int ssl_verify_certificate_validity(int s, X509_STORE_CTX *store) {
8990
switch (m->auth_mode) {
9091
case OPEN_SSL_CERTIFICATE_AUTH_MODE_DENY: {
9192
log_error_errno(SYNTHETIC_ERRNO(EINVAL),
92-
"TLS: Failed to verify certificate server=%s: %s", pretty, X509_verify_cert_error_string(r));
93+
"TLS: Failed to verify certificate server=%s: %s", pretty, X509_verify_cert_error_string(rc));
9394
return 0;
9495
}
9596
break;
9697
case OPEN_SSL_CERTIFICATE_AUTH_MODE_WARN: {
9798
log_warning_errno(SYNTHETIC_ERRNO(EINVAL),
98-
"TLS: Failed to verify certificate server=%s: %s", pretty, X509_verify_cert_error_string(r));
99+
"TLS: Failed to verify certificate server=%s: %s", pretty, X509_verify_cert_error_string(rc));
99100

100101
return 1;
101102
}
102103
break;
103104
case OPEN_SSL_CERTIFICATE_AUTH_MODE_ALLOW: {
104105
log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
105-
"TLS: Failed to verify certificate server=%s: %s", pretty, X509_verify_cert_error_string(r));
106+
"TLS: Failed to verify certificate server=%s: %s", pretty, X509_verify_cert_error_string(rc));
106107
return 1;
107108
}
108109
break;
@@ -111,12 +112,12 @@ int ssl_verify_certificate_validity(int s, X509_STORE_CTX *store) {
111112
}}
112113
break;
113114
default:
114-
log_error("TLS: Failed to validate remote certificate server=%s: %s. Aborting connection ...", pretty, X509_verify_cert_error_string(r));
115+
log_error("TLS: Failed to validate remote certificate server=%s: %s. Aborting connection ...", pretty, X509_verify_cert_error_string(rc));
115116
return 0;
116117
}
117118
}
118119

119-
log_debug("TLS: SSL ceritificates verified server=%s: %s", pretty, X509_verify_cert_error_string(r));
120+
log_debug("TLS: SSL ceritificates verified server=%s: %s", pretty, X509_verify_cert_error_string(rc));
120121

121122
return 1;
122123
}

0 commit comments

Comments
 (0)