From d07f7fde139d15ba9e55fcf7ecb45bbfc82d6564 Mon Sep 17 00:00:00 2001 From: jsing <> Date: Mon, 26 Jul 2021 03:17:38 +0000 Subject: Dedup dtls1_dispatch_alert()/ssl3_dispatch_alert(). The code for dtls1_dispatch_alert() and ssl3_dispatch_alert() is largely identical - with a bit of reshuffling we can use ssl3_dispatch_alert() for both protocols and remove the ssl_dispatch_alert function pointer. ok inoguchi@ tb@ --- src/lib/libssl/ssl_pkt.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'src/lib/libssl/ssl_pkt.c') diff --git a/src/lib/libssl/ssl_pkt.c b/src/lib/libssl/ssl_pkt.c index 7f655adfe6..c3fd4a7365 100644 --- a/src/lib/libssl/ssl_pkt.c +++ b/src/lib/libssl/ssl_pkt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ssl_pkt.c,v 1.45 2021/06/29 18:43:49 jsing Exp $ */ +/* $OpenBSD: ssl_pkt.c,v 1.46 2021/07/26 03:17:38 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -116,6 +116,7 @@ #include #include "bytestring.h" +#include "dtls_locl.h" #include "ssl_locl.h" static int do_ssl3_write(SSL *s, int type, const unsigned char *buf, @@ -552,7 +553,7 @@ do_ssl3_write(SSL *s, int type, const unsigned char *buf, unsigned int len) /* If we have an alert to send, let's send it. */ if (S3I(s)->alert_dispatch) { - if ((ret = s->method->ssl_dispatch_alert(s)) <= 0) + if ((ret = ssl3_dispatch_alert(s)) <= 0) return (ret); /* If it went, fall through and send more stuff. */ @@ -1188,6 +1189,17 @@ ssl3_do_change_cipher_spec(SSL *s) return (1); } +static int +ssl3_write_alert(SSL *s) +{ + if (SSL_is_dtls(s)) + return do_dtls1_write(s, SSL3_RT_ALERT, S3I(s)->send_alert, + sizeof(S3I(s)->send_alert)); + + return do_ssl3_write(s, SSL3_RT_ALERT, S3I(s)->send_alert, + sizeof(S3I(s)->send_alert)); +} + int ssl3_send_alert(SSL *s, int level, int desc) { @@ -1199,7 +1211,7 @@ ssl3_send_alert(SSL *s, int level, int desc) S3I(s)->send_alert[0] = level; S3I(s)->send_alert[1] = desc; if (S3I(s)->wbuf.left == 0) /* data still being written out? */ - return s->method->ssl_dispatch_alert(s); + return ssl3_dispatch_alert(s); /* else data is still being written out, we will get written * some time in the future */ @@ -1213,7 +1225,7 @@ ssl3_dispatch_alert(SSL *s) void (*cb)(const SSL *ssl, int type, int val) = NULL; S3I(s)->alert_dispatch = 0; - i = do_ssl3_write(s, SSL3_RT_ALERT, &S3I(s)->send_alert[0], 2); + i = ssl3_write_alert(s); if (i <= 0) { S3I(s)->alert_dispatch = 1; } else { -- cgit v1.2.3-55-g6feb