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 <viktor@openssl.org>
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 @@
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 @@
*/
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;