From ce0865d8dcf4ed088a9e9ae3aa2310b7bd8c295e Mon Sep 17 00:00:00 2001 From: Matt Caswell Date: Thu, 21 Jan 2016 12:22:58 +0000 Subject: Add tests for DTLSv1_listen Adds a set of tests for the newly rewritten DTLSv1_listen function. The test pokes various packets at the function and then checks the return value and the data written out to ensure it is what we would have expected. Reviewed-by: Viktor Dukhovni --- ssl/d1_lib.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'ssl/d1_lib.c') diff --git a/ssl/d1_lib.c b/ssl/d1_lib.c index 4aea13c..b1f6ed2 100644 --- a/ssl/d1_lib.c +++ b/ssl/d1_lib.c @@ -811,15 +811,19 @@ int DTLSv1_listen(SSL *s, BIO_ADDR *client) s->msg_callback(1, 0, SSL3_RT_HEADER, buf, DTLS1_RT_HEADER_LENGTH, s, s->msg_callback_arg); + + if ((tmpclient = BIO_ADDR_new()) == NULL) { + SSLerr(SSL_F_DTLSV1_LISTEN, ERR_R_MALLOC_FAILURE); + goto end; + } + /* * This is unneccessary if rbio and wbio are one and the same - but - * maybe they're not. + * maybe they're not. We ignore errors here - some BIOs do not + * support this. */ - if ((tmpclient = BIO_ADDR_new()) == NULL - || BIO_dgram_get_peer(rbio, tmpclient) <= 0 - || BIO_dgram_set_peer(wbio, tmpclient) <= 0) { - SSLerr(SSL_F_DTLSV1_LISTEN, ERR_R_INTERNAL_ERROR); - goto end; + if(BIO_dgram_get_peer(rbio, tmpclient) > 0) { + (void)BIO_dgram_set_peer(wbio, tmpclient); } BIO_ADDR_free(tmpclient); tmpclient = NULL; @@ -868,10 +872,9 @@ int DTLSv1_listen(SSL *s, BIO_ADDR *client) */ ossl_statem_set_hello_verify_done(s); - if(BIO_dgram_get_peer(rbio, client) <= 0) { - SSLerr(SSL_F_DTLSV1_LISTEN, ERR_R_INTERNAL_ERROR); - return -1; - } + /* Some BIOs may not support this. If we fail we clear the client address */ + if (BIO_dgram_get_peer(rbio, client) <= 0) + BIO_ADDR_clear(client); ret = 1; clearpkt = 0; -- cgit v1.1