-/* $OpenBSD: tls.c,v 1.3 2014/12/07 15:48:02 bcook Exp $ */
+/* $OpenBSD: tls.c,v 1.4 2014/12/17 17:51:33 doug Exp $ */
/*
* Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
*
#include <sys/socket.h>
#include <errno.h>
+#include <limits.h>
#include <stdlib.h>
#include <unistd.h>
BIO *bio = NULL;
if (ctx->config->cert_mem != NULL) {
+ if (ctx->config->cert_len > INT_MAX) {
+ tls_set_error(ctx, "certificate too long");
+ goto err;
+ }
+
if (SSL_CTX_use_certificate_chain(ctx->ssl_ctx,
ctx->config->cert_mem, ctx->config->cert_len) != 1) {
tls_set_error(ctx, "failed to load certificate");
cert = NULL;
}
if (ctx->config->key_mem != NULL) {
+ if (ctx->config->key_len > INT_MAX) {
+ tls_set_error(ctx, "key too long");
+ goto err;
+ }
+
if ((bio = BIO_new_mem_buf(ctx->config->key_mem,
ctx->config->key_len)) == NULL) {
tls_set_error(ctx, "failed to create buffer");
{
int ret, ssl_err;
+ if (buflen > INT_MAX) {
+ tls_set_error(ctx, "buflen too long");
+ return (-1);
+ }
+
ret = SSL_read(ctx->ssl_conn, buf, buflen);
if (ret > 0) {
*outlen = (size_t)ret;
{
int ret, ssl_err;
+ if (buflen > INT_MAX) {
+ tls_set_error(ctx, "buflen too long");
+ return (-1);
+ }
+
ret = SSL_write(ctx->ssl_conn, buf, buflen);
if (ret > 0) {
*outlen = (size_t)ret;
-/* $OpenBSD: tls_internal.h,v 1.4 2014/12/07 16:56:17 bcook Exp $ */
+/* $OpenBSD: tls_internal.h,v 1.5 2014/12/17 17:51:33 doug Exp $ */
/*
* Copyright (c) 2014 Jeremie Courreges-Anglas <jca@openbsd.org>
* Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
int tls_configure_server(struct tls *ctx);
int tls_configure_ssl(struct tls *ctx);
int tls_host_port(const char *hostport, char **host, char **port);
-int tls_set_error(struct tls *ctx, char *fmt, ...);
+int tls_set_error(struct tls *ctx, char *fmt, ...)
+ __attribute__((__format__ (printf, 2, 3)))
+ __attribute__((__nonnull__ (2)));
#endif /* HEADER_TLS_INTERNAL_H */
-/* $OpenBSD: tls_verify.c,v 1.5 2014/12/07 16:56:17 bcook Exp $ */
+/* $OpenBSD: tls_verify.c,v 1.6 2014/12/17 17:51:33 doug Exp $ */
/*
* Copyright (c) 2014 Jeremie Courreges-Anglas <jca@openbsd.org>
*
if (type == GEN_DNS) {
unsigned char *data;
- int format;
+ int format, len;
format = ASN1_STRING_type(altname->d.dNSName);
if (format == V_ASN1_IA5STRING) {
data = ASN1_STRING_data(altname->d.dNSName);
+ len = ASN1_STRING_length(altname->d.dNSName);
- if (ASN1_STRING_length(altname->d.dNSName) !=
- (int)strlen(data)) {
+ if (len < 0 || len != strlen(data)) {
tls_set_error(ctx,
"error verifying host '%s': "
"NUL byte in subjectAltName, "
datalen = ASN1_STRING_length(altname->d.iPAddress);
data = ASN1_STRING_data(altname->d.iPAddress);
+ if (datalen < 0) {
+ tls_set_error(ctx,
+ "Unexpected negative length for an "
+ "IP address: %d", datalen);
+ rv = -2;
+ break;
+ }
+
if (datalen == addrlen &&
memcmp(data, &addrbuf, addrlen) == 0) {
rv = 0;
common_name_len + 1);
/* NUL bytes in CN? */
- if (common_name_len != (int)strlen(common_name)) {
+ if (common_name_len != strlen(common_name)) {
tls_set_error(ctx, "error verifying host '%s': "
"NUL byte in Common Name field, "
"probably a malicious certificate.", host);