From af463c86562dec5b0e142e1e010ee7d7ef2cb32f Mon Sep 17 00:00:00 2001
From: schwarze <>
Date: Thu, 22 Dec 2022 20:13:45 +0000
Subject: in case of failure, always report the error with BIOerror(); OK tb@

---
 src/lib/libcrypto/bio/b_sock.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/src/lib/libcrypto/bio/b_sock.c b/src/lib/libcrypto/bio/b_sock.c
index 152b080902..301f73914a 100644
--- a/src/lib/libcrypto/bio/b_sock.c
+++ b/src/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 <beck@openbsd.org>
  *
@@ -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))
-- 
cgit v1.2.3-55-g6feb