summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <>2020-09-26 07:36:51 +0000
committertb <>2020-09-26 07:36:51 +0000
commit3345108d2a65403103b8b6331fac7b04a642dddd (patch)
tree48486280532a41742d81deaf5c02364e8258b21e
parentaf7c6ade0d2208202ee8003159d10cf52d688e00 (diff)
downloadopenbsd-3345108d2a65403103b8b6331fac7b04a642dddd.tar.gz
openbsd-3345108d2a65403103b8b6331fac7b04a642dddd.tar.bz2
openbsd-3345108d2a65403103b8b6331fac7b04a642dddd.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--src/lib/libssl/d1_lib.c51
1 files changed, 26 insertions, 25 deletions
diff --git a/src/lib/libssl/d1_lib.c b/src/lib/libssl/d1_lib.c
index 758f5195e6..a728944047 100644
--- a/src/lib/libssl/d1_lib.c
+++ b/src/lib/libssl/d1_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: d1_lib.c,v 1.47 2020/09/24 17:59:54 jsing Exp $ */ 1/* $OpenBSD: d1_lib.c,v 1.48 2020/09/26 07:36:51 tb Exp $ */
2/* 2/*
3 * DTLS implementation written by Nagendra Modadugu 3 * DTLS implementation written by Nagendra Modadugu
4 * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. 4 * (nagendra@cs.stanford.edu) for the OpenSSL project 2005.
@@ -124,46 +124,47 @@ dtls1_new(SSL *s)
124} 124}
125 125
126static void 126static void
127dtls1_clear_queues(SSL *s) 127dtls1_drain_records(pqueue queue)
128{ 128{
129 pitem *item = NULL; 129 pitem *item;
130 hm_fragment *frag = NULL;
131 DTLS1_RECORD_DATA_INTERNAL *rdata; 130 DTLS1_RECORD_DATA_INTERNAL *rdata;
132 131
133 while ((item = pqueue_pop(D1I(s)->unprocessed_rcds.q)) != NULL) { 132 if (queue == NULL)
134 rdata = (DTLS1_RECORD_DATA_INTERNAL *) item->data; 133 return;
135 ssl3_release_buffer(&rdata->rbuf);
136 free(item->data);
137 pitem_free(item);
138 }
139 134
140 while ((item = pqueue_pop(D1I(s)->processed_rcds.q)) != NULL) { 135 while ((item = pqueue_pop(queue)) != NULL) {
141 rdata = (DTLS1_RECORD_DATA_INTERNAL *) item->data; 136 rdata = (DTLS1_RECORD_DATA_INTERNAL *)item->data;
142 ssl3_release_buffer(&rdata->rbuf); 137 ssl3_release_buffer(&rdata->rbuf);
143 free(item->data); 138 free(item->data);
144 pitem_free(item); 139 pitem_free(item);
145 } 140 }
141}
146 142
147 while ((item = pqueue_pop(D1I(s)->buffered_messages)) != NULL) { 143static void
148 frag = (hm_fragment *)item->data; 144dtls1_drain_fragments(pqueue queue)
149 free(frag->fragment); 145{
150 free(frag); 146 pitem *item;
151 pitem_free(item); 147 hm_fragment *frag;
152 } 148
149 if (queue == NULL)
150 return;
153 151
154 while ((item = pqueue_pop(s->d1->sent_messages)) != NULL) { 152 while ((item = pqueue_pop(queue)) != NULL) {
155 frag = (hm_fragment *)item->data; 153 frag = (hm_fragment *)item->data;
156 free(frag->fragment); 154 free(frag->fragment);
157 free(frag); 155 free(frag);
158 pitem_free(item); 156 pitem_free(item);
159 } 157 }
158}
160 159
161 while ((item = pqueue_pop(D1I(s)->buffered_app_data.q)) != NULL) { 160static void
162 rdata = (DTLS1_RECORD_DATA_INTERNAL *) item->data; 161dtls1_clear_queues(SSL *s)
163 ssl3_release_buffer(&rdata->rbuf); 162{
164 free(item->data); 163 dtls1_drain_records(D1I(s)->unprocessed_rcds.q);
165 pitem_free(item); 164 dtls1_drain_records(D1I(s)->processed_rcds.q);
166 } 165 dtls1_drain_fragments(D1I(s)->buffered_messages);
166 dtls1_drain_fragments(s->d1->sent_messages);
167 dtls1_drain_records(D1I(s)->buffered_app_data.q);
167} 168}
168 169
169void 170void