summaryrefslogtreecommitdiff
path: root/apps/s_socket.c
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2017-09-12 16:19:09 +0100
committerMatt Caswell <matt@openssl.org>2018-01-24 18:02:36 +0000
commit10ee72461254643bd152a7f3f6112edb6f517d4b (patch)
treeed4062bac466192046e01bf0179ce0966efa6914 /apps/s_socket.c
parent43054d3d734a8fa8a3d2da20c206a47d4060b7bd (diff)
downloadopenssl-new-10ee72461254643bd152a7f3f6112edb6f517d4b.tar.gz
Enable the cookie callbacks to work even in TLS in the apps
Reviewed-by: Ben Kaduk <kaduk@mit.edu> (Merged from https://github.com/openssl/openssl/pull/4435)
Diffstat (limited to 'apps/s_socket.c')
-rw-r--r--apps/s_socket.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/apps/s_socket.c b/apps/s_socket.c
index 74cf8d28e2..a9e46f9949 100644
--- a/apps/s_socket.c
+++ b/apps/s_socket.c
@@ -35,6 +35,9 @@ typedef unsigned int u_int;
# include <openssl/bio.h>
# include <openssl/err.h>
+/* Keep track of our peer's address for the cookie callback */
+BIO_ADDR *ourpeer = NULL;
+
/*
* init_client - helper routine to set up socket communication
* @sock: pointer to storage of resulting socket.
@@ -212,8 +215,15 @@ int do_server(int *accept_sock, const char *host, const char *port,
*accept_sock = asock;
for (;;) {
if (type == SOCK_STREAM) {
+ BIO_ADDR_free(ourpeer);
+ ourpeer = BIO_ADDR_new();
+ if (ourpeer == NULL) {
+ BIO_closesocket(asock);
+ ERR_print_errors(bio_err);
+ goto end;
+ }
do {
- sock = BIO_accept_ex(asock, NULL, 0);
+ sock = BIO_accept_ex(asock, ourpeer, 0);
} while (sock < 0 && BIO_sock_should_retry(sock));
if (sock < 0) {
ERR_print_errors(bio_err);
@@ -264,6 +274,8 @@ int do_server(int *accept_sock, const char *host, const char *port,
if (family == AF_UNIX)
unlink(host);
# endif
+ BIO_ADDR_free(ourpeer);
+ ourpeer = NULL;
return ret;
}