summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorschwarze <>2022-12-22 20:13:45 +0000
committerschwarze <>2022-12-22 20:13:45 +0000
commitaf463c86562dec5b0e142e1e010ee7d7ef2cb32f (patch)
treec8da3fdcd2f48a556056086277288e8a19cf9017 /src/lib
parent3608d51563efc264f9fb8d2a5a5d21073be1e163 (diff)
downloadopenbsd-af463c86562dec5b0e142e1e010ee7d7ef2cb32f.tar.gz
openbsd-af463c86562dec5b0e142e1e010ee7d7ef2cb32f.tar.bz2
openbsd-af463c86562dec5b0e142e1e010ee7d7ef2cb32f.zip
in case of failure, always report the error with BIOerror();
OK tb@
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/bio/b_sock.c18
1 files 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 @@
1/* $OpenBSD: b_sock.c,v 1.69 2018/02/07 00:52:05 bluhm Exp $ */ 1/* $OpenBSD: b_sock.c,v 1.70 2022/12/22 20:13:45 schwarze Exp $ */
2/* 2/*
3 * Copyright (c) 2017 Bob Beck <beck@openbsd.org> 3 * Copyright (c) 2017 Bob Beck <beck@openbsd.org>
4 * 4 *
@@ -47,6 +47,7 @@ BIO_get_host_ip(const char *str, unsigned char *ip)
47 int error; 47 int error;
48 48
49 if (str == NULL) { 49 if (str == NULL) {
50 BIOerror(BIO_R_BAD_HOSTNAME_LOOKUP);
50 ERR_asprintf_error_data("NULL host provided"); 51 ERR_asprintf_error_data("NULL host provided");
51 return (0); 52 return (0);
52 } 53 }
@@ -79,6 +80,7 @@ BIO_get_port(const char *str, unsigned short *port_ptr)
79 } 80 }
80 81
81 if ((error = getaddrinfo(NULL, str, &hints, &res)) != 0) { 82 if ((error = getaddrinfo(NULL, str, &hints, &res)) != 0) {
83 BIOerror(BIO_R_INVALID_ARGUMENT);
82 ERR_asprintf_error_data("getaddrinfo: service='%s' : %s'", str, 84 ERR_asprintf_error_data("getaddrinfo: service='%s' : %s'", str,
83 gai_strerror(error)); 85 gai_strerror(error));
84 return (0); 86 return (0);
@@ -129,8 +131,14 @@ BIO_get_accept_socket(char *host, int bind_mode)
129 char *h, *p, *str = NULL; 131 char *h, *p, *str = NULL;
130 int error, ret = 0, s = -1; 132 int error, ret = 0, s = -1;
131 133
132 if (host == NULL || (str = strdup(host)) == NULL) 134 if (host == NULL) {
135 BIOerror(BIO_R_NO_PORT_SPECIFIED);
136 return (-1);
137 }
138 if ((str = strdup(host)) == NULL) {
139 BIOerror(ERR_R_MALLOC_FAILURE);
133 return (-1); 140 return (-1);
141 }
134 p = NULL; 142 p = NULL;
135 h = str; 143 h = str;
136 if ((p = strrchr(str, ':')) == NULL) { 144 if ((p = strrchr(str, ':')) == NULL) {
@@ -148,6 +156,7 @@ BIO_get_accept_socket(char *host, int bind_mode)
148 } 156 }
149 157
150 if ((error = getaddrinfo(h, p, &hints, &res)) != 0) { 158 if ((error = getaddrinfo(h, p, &hints, &res)) != 0) {
159 BIOerror(BIO_R_BAD_HOSTNAME_LOOKUP);
151 ERR_asprintf_error_data("getaddrinfo: '%s:%s': %s'", h, p, 160 ERR_asprintf_error_data("getaddrinfo: '%s:%s': %s'", h, p,
152 gai_strerror(error)); 161 gai_strerror(error));
153 goto err; 162 goto err;
@@ -203,9 +212,10 @@ BIO_accept(int sock, char **addr)
203 socklen_t sin_len = sizeof(sin); 212 socklen_t sin_len = sizeof(sin);
204 int ret = -1; 213 int ret = -1;
205 214
206 if (addr == NULL) 215 if (addr == NULL) {
216 BIOerror(BIO_R_NULL_PARAMETER);
207 goto end; 217 goto end;
208 218 }
209 ret = accept(sock, (struct sockaddr *)&sin, &sin_len); 219 ret = accept(sock, (struct sockaddr *)&sin, &sin_len);
210 if (ret == -1) { 220 if (ret == -1) {
211 if (BIO_sock_should_retry(ret)) 221 if (BIO_sock_should_retry(ret))