From fb769bc010501a17f3a4283a6f4c8709fe1bcdba Mon Sep 17 00:00:00 2001 From: tb Date: Sun, 2 Jul 2023 20:16:47 +0000 Subject: [PATCH] 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(-) 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; -- 2.20.1