summaryrefslogtreecommitdiffstats
path: root/crypto/bio
diff options
context:
space:
mode:
authorRich Salz <rsalz@akamai.com>2019-06-11 15:42:42 -0400
committerTomas Mraz <tmraz@fedoraproject.org>2019-07-22 16:24:56 +0200
commit56c3a135b239f4c8ccfdbbb1668880d4c39d5b87 (patch)
tree22bf3958a3b0046ae690e57dd5eaad90c6fcf25a /crypto/bio
parent1372560f64c9a7cfad1979fa8c41bee335a04373 (diff)
Add ERR_put_func_error, and use it.
Change SYSerr to have the function name; remove SYS_F_xxx defines Add a test and documentation. Use get_last_socket_err, which removes some ifdef's in OpenSSL code. Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org> Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/9072)
Diffstat (limited to 'crypto/bio')
-rw-r--r--crypto/bio/b_addr.c16
-rw-r--r--crypto/bio/b_sock.c15
-rw-r--r--crypto/bio/b_sock2.c24
-rw-r--r--crypto/bio/bss_acpt.c2
-rw-r--r--crypto/bio/bss_conn.c6
-rw-r--r--crypto/bio/bss_file.c8
6 files changed, 32 insertions, 39 deletions
diff --git a/crypto/bio/b_addr.c b/crypto/bio/b_addr.c
index d7fcf2fcb5..66f16fb13c 100644
--- a/crypto/bio/b_addr.c
+++ b/crypto/bio/b_addr.c
@@ -207,7 +207,7 @@ static int addr_strings(const BIO_ADDR *ap, int numeric,
flags)) != 0) {
# ifdef EAI_SYSTEM
if (ret == EAI_SYSTEM) {
- SYSerr(SYS_F_GETNAMEINFO, get_last_socket_error());
+ SYSerr("getnameinfo", get_last_socket_error());
BIOerr(BIO_F_ADDR_STRINGS, ERR_R_SYS_LIB);
} else
# endif
@@ -700,7 +700,7 @@ int BIO_lookup_ex(const char *host, const char *service, int lookup_type,
switch ((gai_ret = getaddrinfo(host, service, &hints, res))) {
# ifdef EAI_SYSTEM
case EAI_SYSTEM:
- SYSerr(SYS_F_GETADDRINFO, get_last_socket_error());
+ SYSerr("getaddrinfo", get_last_socket_error());
BIOerr(BIO_F_BIO_LOOKUP_EX, ERR_R_SYS_LIB);
break;
# endif
@@ -804,12 +804,12 @@ int BIO_lookup_ex(const char *host, const char *service, int lookup_type,
*/
# if defined(OPENSSL_SYS_VXWORKS)
/* h_errno doesn't exist on VxWorks */
- SYSerr(SYS_F_GETHOSTBYNAME, 1000 );
+ SYSerr("gethostbyname", 1000 );
# else
- SYSerr(SYS_F_GETHOSTBYNAME, 1000 + h_errno);
+ SYSerr("gethostbyname", 1000 + h_errno);
# endif
#else
- SYSerr(SYS_F_GETHOSTBYNAME, WSAGetLastError());
+ SYSerr("gethostbyname", get_last_socket_error());
#endif
ret = 0;
goto err;
@@ -855,11 +855,7 @@ int BIO_lookup_ex(const char *host, const char *service, int lookup_type,
se = getservbyname(service, proto);
if (se == NULL) {
-#ifndef OPENSSL_SYS_WINDOWS
- SYSerr(SYS_F_GETSERVBYNAME, errno);
-#else
- SYSerr(SYS_F_GETSERVBYNAME, WSAGetLastError());
-#endif
+ SYSerr("getservbyname", get_last_socket_error());
goto err;
}
} else {
diff --git a/crypto/bio/b_sock.c b/crypto/bio/b_sock.c
index 9877b3d78d..f6ad9f03a9 100644
--- a/crypto/bio/b_sock.c
+++ b/crypto/bio/b_sock.c
@@ -120,8 +120,6 @@ int BIO_sock_init(void)
static struct WSAData wsa_state;
if (!wsa_init_done) {
- int err;
-
wsa_init_done = 1;
memset(&wsa_state, 0, sizeof(wsa_state));
/*
@@ -131,8 +129,7 @@ int BIO_sock_init(void)
* probed at run-time with DSO_global_lookup.
*/
if (WSAStartup(0x0202, &wsa_state) != 0) {
- err = WSAGetLastError();
- SYSerr(SYS_F_WSASTARTUP, err);
+ SYSerr("wsastartup", get_last_socket_error());
BIOerr(BIO_F_BIO_SOCK_INIT, BIO_R_WSASTARTUP);
return -1;
}
@@ -192,7 +189,7 @@ int BIO_socket_ioctl(int fd, long type, void *arg)
i = ioctlsocket(fd, type, ARG);
# endif /* __DJGPP__ */
if (i < 0)
- SYSerr(SYS_F_IOCTLSOCKET, get_last_socket_error());
+ SYSerr("ioctlsocket", get_last_socket_error());
return i;
}
@@ -243,7 +240,7 @@ int BIO_accept(int sock, char **ip_port)
ret = -2;
goto end;
}
- SYSerr(SYS_F_ACCEPT, get_last_socket_error());
+ SYSerr("accept", get_last_socket_error());
BIOerr(BIO_F_BIO_ACCEPT, BIO_R_ACCEPT_ERROR);
goto end;
}
@@ -308,7 +305,7 @@ int BIO_socket_nbio(int s, int mode)
l = fcntl(s, F_GETFL, 0);
if (l == -1) {
- SYSerr(SYS_F_FCNTL, get_last_sys_error());
+ SYSerr("fcntl", get_last_sys_error());
ret = -1;
} else {
# if defined(O_NONBLOCK)
@@ -326,7 +323,7 @@ int BIO_socket_nbio(int s, int mode)
ret = fcntl(s, F_SETFL, l);
if (ret < 0) {
- SYSerr(SYS_F_FCNTL, get_last_sys_error());
+ SYSerr("fcntl", get_last_sys_error());
}
}
# else
@@ -349,7 +346,7 @@ int BIO_sock_info(int sock,
ret = getsockname(sock, BIO_ADDR_sockaddr_noconst(info->addr),
&addr_len);
if (ret == -1) {
- SYSerr(SYS_F_GETSOCKNAME, get_last_socket_error());
+ SYSerr("getsockname", get_last_socket_error());
BIOerr(BIO_F_BIO_SOCK_INFO, BIO_R_GETSOCKNAME_ERROR);
return 0;
}
diff --git a/crypto/bio/b_sock2.c b/crypto/bio/b_sock2.c
index 7e04d7889b..88c7b0f52e 100644
--- a/crypto/bio/b_sock2.c
+++ b/crypto/bio/b_sock2.c
@@ -46,7 +46,7 @@ int BIO_socket(int domain, int socktype, int protocol, int options)
sock = socket(domain, socktype, protocol);
if (sock == -1) {
- SYSerr(SYS_F_SOCKET, get_last_socket_error());
+ SYSerr("socket", get_last_socket_error());
BIOerr(BIO_F_BIO_SOCKET, BIO_R_UNABLE_TO_CREATE_SOCKET);
return INVALID_SOCKET;
}
@@ -89,7 +89,7 @@ int BIO_connect(int sock, const BIO_ADDR *addr, int options)
if (options & BIO_SOCK_KEEPALIVE) {
if (setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE,
(const void *)&on, sizeof(on)) != 0) {
- SYSerr(SYS_F_SETSOCKOPT, get_last_socket_error());
+ SYSerr("setsockopt", get_last_socket_error());
BIOerr(BIO_F_BIO_CONNECT, BIO_R_UNABLE_TO_KEEPALIVE);
return 0;
}
@@ -98,7 +98,7 @@ int BIO_connect(int sock, const BIO_ADDR *addr, int options)
if (options & BIO_SOCK_NODELAY) {
if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY,
(const void *)&on, sizeof(on)) != 0) {
- SYSerr(SYS_F_SETSOCKOPT, get_last_socket_error());
+ SYSerr("setsockopt", get_last_socket_error());
BIOerr(BIO_F_BIO_CONNECT, BIO_R_UNABLE_TO_NODELAY);
return 0;
}
@@ -107,7 +107,7 @@ int BIO_connect(int sock, const BIO_ADDR *addr, int options)
if (connect(sock, BIO_ADDR_sockaddr(addr),
BIO_ADDR_sockaddr_size(addr)) == -1) {
if (!BIO_sock_should_retry(-1)) {
- SYSerr(SYS_F_CONNECT, get_last_socket_error());
+ SYSerr("connect", get_last_socket_error());
BIOerr(BIO_F_BIO_CONNECT, BIO_R_CONNECT_ERROR);
}
return 0;
@@ -150,7 +150,7 @@ int BIO_bind(int sock, const BIO_ADDR *addr, int options)
if (options & BIO_SOCK_REUSEADDR) {
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
(const void *)&on, sizeof(on)) != 0) {
- SYSerr(SYS_F_SETSOCKOPT, get_last_socket_error());
+ SYSerr("setsockopt", get_last_socket_error());
BIOerr(BIO_F_BIO_BIND, BIO_R_UNABLE_TO_REUSEADDR);
return 0;
}
@@ -158,7 +158,7 @@ int BIO_bind(int sock, const BIO_ADDR *addr, int options)
# endif
if (bind(sock, BIO_ADDR_sockaddr(addr), BIO_ADDR_sockaddr_size(addr)) != 0) {
- SYSerr(SYS_F_BIND, get_last_socket_error());
+ SYSerr("bind", get_last_socket_error());
BIOerr(BIO_F_BIO_BIND, BIO_R_UNABLE_TO_BIND_SOCKET);
return 0;
}
@@ -217,7 +217,7 @@ int BIO_listen(int sock, const BIO_ADDR *addr, int options)
if (getsockopt(sock, SOL_SOCKET, SO_TYPE,
(void *)&socktype, &socktype_len) != 0
|| socktype_len != sizeof(socktype)) {
- SYSerr(SYS_F_GETSOCKOPT, get_last_socket_error());
+ SYSerr("getsockopt", get_last_socket_error());
BIOerr(BIO_F_BIO_LISTEN, BIO_R_GETTING_SOCKTYPE);
return 0;
}
@@ -228,7 +228,7 @@ int BIO_listen(int sock, const BIO_ADDR *addr, int options)
if (options & BIO_SOCK_KEEPALIVE) {
if (setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE,
(const void *)&on, sizeof(on)) != 0) {
- SYSerr(SYS_F_SETSOCKOPT, get_last_socket_error());
+ SYSerr("setsockopt", get_last_socket_error());
BIOerr(BIO_F_BIO_LISTEN, BIO_R_UNABLE_TO_KEEPALIVE);
return 0;
}
@@ -237,7 +237,7 @@ int BIO_listen(int sock, const BIO_ADDR *addr, int options)
if (options & BIO_SOCK_NODELAY) {
if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY,
(const void *)&on, sizeof(on)) != 0) {
- SYSerr(SYS_F_SETSOCKOPT, get_last_socket_error());
+ SYSerr("setsockopt", get_last_socket_error());
BIOerr(BIO_F_BIO_LISTEN, BIO_R_UNABLE_TO_NODELAY);
return 0;
}
@@ -252,7 +252,7 @@ int BIO_listen(int sock, const BIO_ADDR *addr, int options)
on = options & BIO_SOCK_V6_ONLY ? 1 : 0;
if (setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY,
(const void *)&on, sizeof(on)) != 0) {
- SYSerr(SYS_F_SETSOCKOPT, get_last_socket_error());
+ SYSerr("setsockopt", get_last_socket_error());
BIOerr(BIO_F_BIO_LISTEN, BIO_R_LISTEN_V6_ONLY);
return 0;
}
@@ -263,7 +263,7 @@ int BIO_listen(int sock, const BIO_ADDR *addr, int options)
return 0;
if (socktype != SOCK_DGRAM && listen(sock, MAX_LISTEN) == -1) {
- SYSerr(SYS_F_LISTEN, get_last_socket_error());
+ SYSerr("listen", get_last_socket_error());
BIOerr(BIO_F_BIO_LISTEN, BIO_R_UNABLE_TO_LISTEN_SOCKET);
return 0;
}
@@ -290,7 +290,7 @@ int BIO_accept_ex(int accept_sock, BIO_ADDR *addr_, int options)
BIO_ADDR_sockaddr_noconst(addr), &len);
if (accepted_sock == -1) {
if (!BIO_sock_should_retry(accepted_sock)) {
- SYSerr(SYS_F_ACCEPT, get_last_socket_error());
+ SYSerr("accept", get_last_socket_error());
BIOerr(BIO_F_BIO_ACCEPT_EX, BIO_R_ACCEPT_ERROR);
}
return INVALID_SOCKET;
diff --git a/crypto/bio/bss_acpt.c b/crypto/bio/bss_acpt.c
index 8955aa8a7f..739bd1ac5f 100644
--- a/crypto/bio/bss_acpt.c
+++ b/crypto/bio/bss_acpt.c
@@ -226,7 +226,7 @@ static int acpt_state(BIO *b, BIO_ACCEPT *c)
BIO_ADDRINFO_socktype(c->addr_iter),
BIO_ADDRINFO_protocol(c->addr_iter), 0);
if (ret == (int)INVALID_SOCKET) {
- SYSerr(SYS_F_SOCKET, get_last_socket_error());
+ SYSerr("socket", get_last_socket_error());
ERR_add_error_data(4,
"hostname=", c->param_addr,
" service=", c->param_serv);
diff --git a/crypto/bio/bss_conn.c b/crypto/bio/bss_conn.c
index 818b2ee94e..6909601f99 100644
--- a/crypto/bio/bss_conn.c
+++ b/crypto/bio/bss_conn.c
@@ -138,7 +138,7 @@ static int conn_state(BIO *b, BIO_CONNECT *c)
BIO_ADDRINFO_socktype(c->addr_iter),
BIO_ADDRINFO_protocol(c->addr_iter), 0);
if (ret == (int)INVALID_SOCKET) {
- SYSerr(SYS_F_SOCKET, get_last_socket_error());
+ SYSerr("socket", get_last_socket_error());
ERR_add_error_data(4,
"hostname=", c->param_hostname,
" service=", c->param_service);
@@ -170,7 +170,7 @@ static int conn_state(BIO *b, BIO_CONNECT *c)
ERR_clear_error();
break;
} else {
- SYSerr(SYS_F_CONNECT, get_last_socket_error());
+ SYSerr("connect", get_last_socket_error());
ERR_add_error_data(4,
"hostname=", c->param_hostname,
" service=", c->param_service);
@@ -186,7 +186,7 @@ static int conn_state(BIO *b, BIO_CONNECT *c)
i = BIO_sock_error(b->num);
if (i) {
BIO_clear_retry_flags(b);
- SYSerr(SYS_F_CONNECT, i);
+ SYSerr("connect", i);
ERR_add_error_data(4,
"hostname=", c->param_hostname,
" service=", c->param_service);
diff --git a/crypto/bio/bss_file.c b/crypto/bio/bss_file.c
index 0e07632f7e..d0afd10214 100644
--- a/crypto/bio/bss_file.c
+++ b/crypto/bio/bss_file.c
@@ -69,7 +69,7 @@ BIO *BIO_new_file(const char *filename, const char *mode)
fp_flags |= BIO_FP_TEXT;
if (file == NULL) {
- SYSerr(SYS_F_FOPEN, get_last_sys_error());
+ SYSerr("fopen", get_last_sys_error());
ERR_add_error_data(5, "fopen('", filename, "','", mode, "')");
if (errno == ENOENT
# ifdef ENXIO
@@ -149,7 +149,7 @@ static int file_read(BIO *b, char *out, int outl)
if (ret == 0
&& (b->flags & BIO_FLAGS_UPLINK_INTERNAL
? UP_ferror((FILE *)b->ptr) : ferror((FILE *)b->ptr))) {
- SYSerr(SYS_F_FREAD, get_last_sys_error());
+ SYSerr("fread", get_last_sys_error());
BIOerr(BIO_F_FILE_READ, ERR_R_SYS_LIB);
ret = -1;
}
@@ -288,7 +288,7 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr)
# endif
fp = openssl_fopen(ptr, p);
if (fp == NULL) {
- SYSerr(SYS_F_FOPEN, get_last_sys_error());
+ SYSerr("fopen", get_last_sys_error());
ERR_add_error_data(5, "fopen('", ptr, "','", p, "')");
BIOerr(BIO_F_FILE_CTRL, ERR_R_SYS_LIB);
ret = 0;
@@ -316,7 +316,7 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr)
st = b->flags & BIO_FLAGS_UPLINK_INTERNAL
? UP_fflush(b->ptr) : fflush((FILE *)b->ptr);
if (st == EOF) {
- SYSerr(SYS_F_FFLUSH, get_last_sys_error());
+ SYSerr("fflush", get_last_sys_error());
ERR_add_error_data(1, "fflush()");
BIOerr(BIO_F_FILE_CTRL, ERR_R_SYS_LIB);
ret = 0;