From e7dbd7a1e2ad3e12dafa2919bc8603d60416ea4d Mon Sep 17 00:00:00 2001 From: beck <> Date: Sat, 26 Apr 2014 18:56:38 +0000 Subject: Replace all use of ERR_add_error_data with ERR_asprintf_error_data. This avoids a lot of ugly gymnastics to do snprintfs before sending the bag of strings to ERR, and eliminates at least one place in dso_dlfctn.c where it was being called with the incorrect number of arguments and using random things off the stack as addresses of strings. ok krw@, jsing@ --- src/lib/libcrypto/bio/b_sock.c | 10 +++++----- src/lib/libcrypto/bio/bss_conn.c | 25 ++++++++++++------------- src/lib/libcrypto/bio/bss_file.c | 4 ++-- 3 files changed, 19 insertions(+), 20 deletions(-) (limited to 'src/lib/libcrypto/bio') diff --git a/src/lib/libcrypto/bio/b_sock.c b/src/lib/libcrypto/bio/b_sock.c index 05eb362cc6..ecfaf93b99 100644 --- a/src/lib/libcrypto/bio/b_sock.c +++ b/src/lib/libcrypto/bio/b_sock.c @@ -129,7 +129,7 @@ err: if (locked) CRYPTO_w_unlock(CRYPTO_LOCK_GETHOSTBYNAME); if (err) { - ERR_add_error_data(2, "host=", str); + ERR_asprintf_error_data("host=%s", str); return 0; } else return 1; @@ -171,7 +171,7 @@ BIO_get_port(const char *str, unsigned short *port_ptr) *port_ptr = 70; else { SYSerr(SYS_F_GETSERVBYNAME, errno); - ERR_add_error_data(3, "service='", str, "'"); + ERR_asprintf_error_data("service='%s'", str); return (0); } } @@ -378,7 +378,7 @@ again: s = socket(server.sa.sa_family, SOCK_STREAM, SOCKET_PROTOCOL); if (s == -1) { SYSerr(SYS_F_SOCKET, errno); - ERR_add_error_data(3, "port='", host, "'"); + ERR_asprintf_error_data("port='%s'", host); BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET, BIO_R_UNABLE_TO_CREATE_SOCKET); goto err; } @@ -422,13 +422,13 @@ again: } #endif SYSerr(SYS_F_BIND, err_num); - ERR_add_error_data(3, "port='", host, "'"); + ERR_asprintf_error_data("port='%s'", host); BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET, BIO_R_UNABLE_TO_BIND_SOCKET); goto err; } if (listen(s, MAX_LISTEN) == -1) { SYSerr(SYS_F_BIND, errno); - ERR_add_error_data(3, "port='", host, "'"); + ERR_asprintf_error_data("port='%s'", host); BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET, BIO_R_UNABLE_TO_LISTEN_SOCKET); goto err; } diff --git a/src/lib/libcrypto/bio/bss_conn.c b/src/lib/libcrypto/bio/bss_conn.c index b64d7d7761..d7a8619b38 100644 --- a/src/lib/libcrypto/bio/bss_conn.c +++ b/src/lib/libcrypto/bio/bss_conn.c @@ -156,7 +156,8 @@ conn_state(BIO *b, BIO_CONNECT *c) if (c->param_port == NULL) { BIOerr(BIO_F_CONN_STATE, BIO_R_NO_PORT_SPECIFIED); - ERR_add_error_data(2, "host=", c->param_hostname); + ERR_asprintf_error_data("host=%s", + c->param_hostname); goto exit_loop; } c->state = BIO_CONN_S_GET_IP; @@ -193,8 +194,8 @@ conn_state(BIO *b, BIO_CONNECT *c) ret = socket(AF_INET, SOCK_STREAM, SOCKET_PROTOCOL); if (ret == -1) { SYSerr(SYS_F_SOCKET, errno); - ERR_add_error_data(4, "host=", - c->param_hostname, ":", c->param_port); + ERR_asprintf_error_data("host=%s:%s", + c->param_hostname, c->param_port); BIOerr(BIO_F_CONN_STATE, BIO_R_UNABLE_TO_CREATE_SOCKET); goto exit_loop; @@ -208,9 +209,8 @@ conn_state(BIO *b, BIO_CONNECT *c) if (!BIO_socket_nbio(b->num, 1)) { BIOerr(BIO_F_CONN_STATE, BIO_R_ERROR_SETTING_NBIO); - ERR_add_error_data(4, "host=", - c->param_hostname, ":", - c->param_port); + ERR_asprintf_error_data("host=%s:%s", + c->param_hostname, c->param_port); goto exit_loop; } } @@ -221,8 +221,8 @@ conn_state(BIO *b, BIO_CONNECT *c) i = setsockopt(b->num, SOL_SOCKET, SO_KEEPALIVE,(char *)&i, sizeof(i)); if (i < 0) { SYSerr(SYS_F_SOCKET, errno); - ERR_add_error_data(4, "host=", - c->param_hostname, ":", c->param_port); + ERR_asprintf_error_data("host=%s:%s", + c->param_hostname, c->param_port); BIOerr(BIO_F_CONN_STATE, BIO_R_KEEPALIVE); goto exit_loop; } @@ -242,9 +242,8 @@ conn_state(BIO *b, BIO_CONNECT *c) b->retry_reason = BIO_RR_CONNECT; } else { SYSerr(SYS_F_CONNECT, errno); - ERR_add_error_data(4, "host=", - c->param_hostname, ":", - c->param_port); + ERR_asprintf_error_data("host=%s:%s", + c->param_hostname, c->param_port); BIOerr(BIO_F_CONN_STATE, BIO_R_CONNECT_ERROR); } @@ -258,8 +257,8 @@ conn_state(BIO *b, BIO_CONNECT *c) if (i) { BIO_clear_retry_flags(b); SYSerr(SYS_F_CONNECT, i); - ERR_add_error_data(4, "host=", - c->param_hostname, ":", c->param_port); + ERR_asprintf_error_data("host=%s:%s", + c->param_hostname, c->param_port); BIOerr(BIO_F_CONN_STATE, BIO_R_NBIO_CONNECT_ERROR); ret = 0; diff --git a/src/lib/libcrypto/bio/bss_file.c b/src/lib/libcrypto/bio/bss_file.c index acc746260e..6d5444f666 100644 --- a/src/lib/libcrypto/bio/bss_file.c +++ b/src/lib/libcrypto/bio/bss_file.c @@ -122,7 +122,7 @@ BIO_new_file(const char *filename, const char *mode) if (file == NULL) { SYSerr(SYS_F_FOPEN, errno); - ERR_add_error_data(5, "fopen('", filename, "', '", mode, "')"); + ERR_asprintf_error_data("fopen('%s', '%s')", filename, mode); if (errno == ENOENT) BIOerr(BIO_F_BIO_NEW_FILE, BIO_R_NO_SUCH_FILE); else @@ -262,7 +262,7 @@ file_ctrl(BIO *b, int cmd, long num, void *ptr) fp = fopen(ptr, p); if (fp == NULL) { SYSerr(SYS_F_FOPEN, errno); - ERR_add_error_data(5, "fopen('", ptr, "', '", p, "')"); + ERR_asprintf_error_data("fopen('%s', '%s')", ptr, p); BIOerr(BIO_F_FILE_CTRL, ERR_R_SYS_LIB); ret = 0; break; -- cgit v1.2.3-55-g6feb