summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authortb <>2023-07-02 20:16:47 +0000
committertb <>2023-07-02 20:16:47 +0000
commitba60cf4d7f8d8cf5ed3ede464afcbf50ef4f05bd (patch)
tree5c2cc3883257cab30c7165ad2bd98e37bbe78666 /src/lib
parent1235f87e2cef60842de72797e55c7587df5ed283 (diff)
downloadopenbsd-ba60cf4d7f8d8cf5ed3ede464afcbf50ef4f05bd.tar.gz
openbsd-ba60cf4d7f8d8cf5ed3ede464afcbf50ef4f05bd.tar.bz2
openbsd-ba60cf4d7f8d8cf5ed3ede464afcbf50ef4f05bd.zip
Simplify allocation checks
Instead of attempting to allocate a few times and only then check all the returned pointers for NULL, allocate and check one after the othre. This is easier on the eyes and what we usually do. Prompted by a report by Ilya Shipitsin ok beck
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libssl/d1_pkt.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/lib/libssl/d1_pkt.c b/src/lib/libssl/d1_pkt.c
index 5409d3923b..df9581a3ce 100644
--- a/src/lib/libssl/d1_pkt.c
+++ b/src/lib/libssl/d1_pkt.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: d1_pkt.c,v 1.127 2022/11/26 16:08:55 tb Exp $ */ 1/* $OpenBSD: d1_pkt.c,v 1.128 2023/07/02 20:16:47 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.
@@ -206,16 +206,16 @@ dtls1_copy_record(SSL *s, DTLS1_RECORD_DATA_INTERNAL *rdata)
206static int 206static int
207dtls1_buffer_record(SSL *s, record_pqueue *queue, unsigned char *priority) 207dtls1_buffer_record(SSL *s, record_pqueue *queue, unsigned char *priority)
208{ 208{
209 DTLS1_RECORD_DATA_INTERNAL *rdata; 209 DTLS1_RECORD_DATA_INTERNAL *rdata = NULL;
210 pitem *item; 210 pitem *item = NULL;
211 211
212 /* Limit the size of the queue to prevent DOS attacks */ 212 /* Limit the size of the queue to prevent DOS attacks */
213 if (pqueue_size(queue->q) >= 100) 213 if (pqueue_size(queue->q) >= 100)
214 return 0; 214 return 0;
215 215
216 rdata = malloc(sizeof(DTLS1_RECORD_DATA_INTERNAL)); 216 if ((rdata = malloc(sizeof(*rdata))) == NULL)
217 item = pitem_new(priority, rdata); 217 goto init_err;
218 if (rdata == NULL || item == NULL) 218 if ((item = pitem_new(priority, rdata)) == NULL)
219 goto init_err; 219 goto init_err;
220 220
221 rdata->packet = s->packet; 221 rdata->packet = s->packet;
@@ -252,16 +252,16 @@ dtls1_buffer_record(SSL *s, record_pqueue *queue, unsigned char *priority)
252static int 252static int
253dtls1_buffer_rcontent(SSL *s, rcontent_pqueue *queue, unsigned char *priority) 253dtls1_buffer_rcontent(SSL *s, rcontent_pqueue *queue, unsigned char *priority)
254{ 254{
255 DTLS1_RCONTENT_DATA_INTERNAL *rdata; 255 DTLS1_RCONTENT_DATA_INTERNAL *rdata = NULL;
256 pitem *item; 256 pitem *item = NULL;
257 257
258 /* Limit the size of the queue to prevent DOS attacks */ 258 /* Limit the size of the queue to prevent DOS attacks */
259 if (pqueue_size(queue->q) >= 100) 259 if (pqueue_size(queue->q) >= 100)
260 return 0; 260 return 0;
261 261
262 rdata = malloc(sizeof(DTLS1_RCONTENT_DATA_INTERNAL)); 262 if ((rdata = malloc(sizeof(*rdata))) == NULL)
263 item = pitem_new(priority, rdata); 263 goto init_err;
264 if (rdata == NULL || item == NULL) 264 if ((item = pitem_new(priority, rdata)) == NULL)
265 goto init_err; 265 goto init_err;
266 266
267 rdata->rcontent = s->s3->rcontent; 267 rdata->rcontent = s->s3->rcontent;