summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortb <tb@openbsd.org>2020-09-26 07:36:51 +0000
committertb <tb@openbsd.org>2020-09-26 07:36:51 +0000
commit9215d666781ca72883347948ff65d7c0e2eb06fc (patch)
treecd38be67bb95da537a0ef7e211f2801e2a072a94
parentjumping into the x509 fray with a bunch of whitespace repair (diff)
downloadwireguard-openbsd-9215d666781ca72883347948ff65d7c0e2eb06fc.tar.xz
wireguard-openbsd-9215d666781ca72883347948ff65d7c0e2eb06fc.zip
Refactor dtls1_clear_queues()
An upcoming cleanup diff by jsing needs dtls1_clear_queues() to be able to handle NULL pqueues. While one can easily add a NULL check to pqueue_pop(), this does not really fit in with the rest of the code. There are two kinds of while loops in dtls1_clear_queues that drain pqueues, so add two helper functions with a NULL check each. ok jsing
-rw-r--r--lib/libssl/d1_lib.c51
1 files changed, 26 insertions, 25 deletions
diff --git a/lib/libssl/d1_lib.c b/lib/libssl/d1_lib.c
index 758f5195e64..a728944047b 100644
--- a/lib/libssl/d1_lib.c
+++ b/lib/libssl/d1_lib.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: d1_lib.c,v 1.47 2020/09/24 17:59:54 jsing Exp $ */
+/* $OpenBSD: d1_lib.c,v 1.48 2020/09/26 07:36:51 tb Exp $ */
/*
* DTLS implementation written by Nagendra Modadugu
* (nagendra@cs.stanford.edu) for the OpenSSL project 2005.
@@ -124,46 +124,47 @@ dtls1_new(SSL *s)
}
static void
-dtls1_clear_queues(SSL *s)
+dtls1_drain_records(pqueue queue)
{
- pitem *item = NULL;
- hm_fragment *frag = NULL;
+ pitem *item;
DTLS1_RECORD_DATA_INTERNAL *rdata;
- while ((item = pqueue_pop(D1I(s)->unprocessed_rcds.q)) != NULL) {
- rdata = (DTLS1_RECORD_DATA_INTERNAL *) item->data;
- ssl3_release_buffer(&rdata->rbuf);
- free(item->data);
- pitem_free(item);
- }
+ if (queue == NULL)
+ return;
- while ((item = pqueue_pop(D1I(s)->processed_rcds.q)) != NULL) {
- rdata = (DTLS1_RECORD_DATA_INTERNAL *) item->data;
+ while ((item = pqueue_pop(queue)) != NULL) {
+ rdata = (DTLS1_RECORD_DATA_INTERNAL *)item->data;
ssl3_release_buffer(&rdata->rbuf);
free(item->data);
pitem_free(item);
}
+}
- while ((item = pqueue_pop(D1I(s)->buffered_messages)) != NULL) {
- frag = (hm_fragment *)item->data;
- free(frag->fragment);
- free(frag);
- pitem_free(item);
- }
+static void
+dtls1_drain_fragments(pqueue queue)
+{
+ pitem *item;
+ hm_fragment *frag;
+
+ if (queue == NULL)
+ return;
- while ((item = pqueue_pop(s->d1->sent_messages)) != NULL) {
+ while ((item = pqueue_pop(queue)) != NULL) {
frag = (hm_fragment *)item->data;
free(frag->fragment);
free(frag);
pitem_free(item);
}
+}
- while ((item = pqueue_pop(D1I(s)->buffered_app_data.q)) != NULL) {
- rdata = (DTLS1_RECORD_DATA_INTERNAL *) item->data;
- ssl3_release_buffer(&rdata->rbuf);
- free(item->data);
- pitem_free(item);
- }
+static void
+dtls1_clear_queues(SSL *s)
+{
+ dtls1_drain_records(D1I(s)->unprocessed_rcds.q);
+ dtls1_drain_records(D1I(s)->processed_rcds.q);
+ dtls1_drain_fragments(D1I(s)->buffered_messages);
+ dtls1_drain_fragments(s->d1->sent_messages);
+ dtls1_drain_records(D1I(s)->buffered_app_data.q);
}
void