From e9d425bbe4989fcae33ff7295ab4b97a57d39723 Mon Sep 17 00:00:00 2001 From: Theo Buehler Date: Sun, 2 Jul 2023 20:16:48 +0000 Subject: 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 --- lib/libssl/d1_pkt.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'lib/libssl/d1_pkt.c') diff --git a/lib/libssl/d1_pkt.c b/lib/libssl/d1_pkt.c index 5409d3923bb..df9581a3cef 100644 --- a/lib/libssl/d1_pkt.c +++ b/lib/libssl/d1_pkt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: d1_pkt.c,v 1.127 2022/11/26 16:08:55 tb Exp $ */ +/* $OpenBSD: d1_pkt.c,v 1.128 2023/07/02 20:16:47 tb Exp $ */ /* * DTLS implementation written by Nagendra Modadugu * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. @@ -206,16 +206,16 @@ dtls1_copy_record(SSL *s, DTLS1_RECORD_DATA_INTERNAL *rdata) static int dtls1_buffer_record(SSL *s, record_pqueue *queue, unsigned char *priority) { - DTLS1_RECORD_DATA_INTERNAL *rdata; - pitem *item; + DTLS1_RECORD_DATA_INTERNAL *rdata = NULL; + pitem *item = NULL; /* Limit the size of the queue to prevent DOS attacks */ if (pqueue_size(queue->q) >= 100) return 0; - rdata = malloc(sizeof(DTLS1_RECORD_DATA_INTERNAL)); - item = pitem_new(priority, rdata); - if (rdata == NULL || item == NULL) + if ((rdata = malloc(sizeof(*rdata))) == NULL) + goto init_err; + if ((item = pitem_new(priority, rdata)) == NULL) goto init_err; rdata->packet = s->packet; @@ -252,16 +252,16 @@ dtls1_buffer_record(SSL *s, record_pqueue *queue, unsigned char *priority) static int dtls1_buffer_rcontent(SSL *s, rcontent_pqueue *queue, unsigned char *priority) { - DTLS1_RCONTENT_DATA_INTERNAL *rdata; - pitem *item; + DTLS1_RCONTENT_DATA_INTERNAL *rdata = NULL; + pitem *item = NULL; /* Limit the size of the queue to prevent DOS attacks */ if (pqueue_size(queue->q) >= 100) return 0; - rdata = malloc(sizeof(DTLS1_RCONTENT_DATA_INTERNAL)); - item = pitem_new(priority, rdata); - if (rdata == NULL || item == NULL) + if ((rdata = malloc(sizeof(*rdata))) == NULL) + goto init_err; + if ((item = pitem_new(priority, rdata)) == NULL) goto init_err; rdata->rcontent = s->s3->rcontent; -- cgit v1.2.3