From 4941afce3697f2dde251174d9dec54584a780d95 Mon Sep 17 00:00:00 2001 From: schwarze Date: Thu, 22 Dec 2022 20:13:45 +0000 Subject: [PATCH] in case of failure, always report the error with BIOerror(); OK tb@ --- lib/libcrypto/bio/b_sock.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/libcrypto/bio/b_sock.c b/lib/libcrypto/bio/b_sock.c index 152b0809022..301f73914a7 100644 --- a/lib/libcrypto/bio/b_sock.c +++ b/lib/libcrypto/bio/b_sock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: b_sock.c,v 1.69 2018/02/07 00:52:05 bluhm Exp $ */ +/* $OpenBSD: b_sock.c,v 1.70 2022/12/22 20:13:45 schwarze Exp $ */ /* * Copyright (c) 2017 Bob Beck * @@ -47,6 +47,7 @@ BIO_get_host_ip(const char *str, unsigned char *ip) int error; if (str == NULL) { + BIOerror(BIO_R_BAD_HOSTNAME_LOOKUP); ERR_asprintf_error_data("NULL host provided"); return (0); } @@ -79,6 +80,7 @@ BIO_get_port(const char *str, unsigned short *port_ptr) } if ((error = getaddrinfo(NULL, str, &hints, &res)) != 0) { + BIOerror(BIO_R_INVALID_ARGUMENT); ERR_asprintf_error_data("getaddrinfo: service='%s' : %s'", str, gai_strerror(error)); return (0); @@ -129,8 +131,14 @@ BIO_get_accept_socket(char *host, int bind_mode) char *h, *p, *str = NULL; int error, ret = 0, s = -1; - if (host == NULL || (str = strdup(host)) == NULL) + if (host == NULL) { + BIOerror(BIO_R_NO_PORT_SPECIFIED); + return (-1); + } + if ((str = strdup(host)) == NULL) { + BIOerror(ERR_R_MALLOC_FAILURE); return (-1); + } p = NULL; h = str; if ((p = strrchr(str, ':')) == NULL) { @@ -148,6 +156,7 @@ BIO_get_accept_socket(char *host, int bind_mode) } if ((error = getaddrinfo(h, p, &hints, &res)) != 0) { + BIOerror(BIO_R_BAD_HOSTNAME_LOOKUP); ERR_asprintf_error_data("getaddrinfo: '%s:%s': %s'", h, p, gai_strerror(error)); goto err; @@ -203,9 +212,10 @@ BIO_accept(int sock, char **addr) socklen_t sin_len = sizeof(sin); int ret = -1; - if (addr == NULL) + if (addr == NULL) { + BIOerror(BIO_R_NULL_PARAMETER); goto end; - + } ret = accept(sock, (struct sockaddr *)&sin, &sin_len); if (ret == -1) { if (BIO_sock_should_retry(ret)) -- 2.20.1