summaryrefslogtreecommitdiff
path: root/lib/libssl/d1_both.c
diff options
context:
space:
mode:
authorJoel Sing <jsing@cvs.openbsd.org>2020-09-26 08:58:01 +0000
committerJoel Sing <jsing@cvs.openbsd.org>2020-09-26 08:58:01 +0000
commita92f8cf1317435bd200adcbcc7590474d15895b3 (patch)
treeb3f2af59646145b5815d72653cc6b854bd8caa6d /lib/libssl/d1_both.c
parent9d7e9d3d3fd97a27388f5e3597143788fe41b63c (diff)
Have dtls1_hm_fragment_new() call dtls1_hm_fragment_free() on failure.
Rather than using local variables and having to remember which things need to be freed upon a failure at a certain point, simply allocate into the hm_fragment struct and call dtls1_hm_fragment_free() on failure. Also use calloc() to ensure memory is appropriately zeroed/initialised. ok tb@
Diffstat (limited to 'lib/libssl/d1_both.c')
-rw-r--r--lib/libssl/d1_both.c43
1 files changed, 17 insertions, 26 deletions
diff --git a/lib/libssl/d1_both.c b/lib/libssl/d1_both.c
index 4a2e41b21b1..6541a395a7b 100644
--- a/lib/libssl/d1_both.c
+++ b/lib/libssl/d1_both.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: d1_both.c,v 1.58 2020/08/11 19:13:35 jsing Exp $ */
+/* $OpenBSD: d1_both.c,v 1.59 2020/09/26 08:58:00 jsing Exp $ */
/*
* DTLS implementation written by Nagendra Modadugu
* (nagendra@cs.stanford.edu) for the OpenSSL project 2005.
@@ -166,42 +166,33 @@ static int dtls1_write_message_header(const struct hm_header_st *msg_hdr,
static long dtls1_get_message_fragment(SSL *s, int st1, int stn, long max,
int *ok);
+static void dtls1_hm_fragment_free(hm_fragment *frag);
+
static hm_fragment *
dtls1_hm_fragment_new(unsigned long frag_len, int reassembly)
{
- hm_fragment *frag = NULL;
- unsigned char *buf = NULL;
- unsigned char *bitmask = NULL;
+ hm_fragment *frag;
- frag = malloc(sizeof(hm_fragment));
- if (frag == NULL)
- return NULL;
+ if ((frag = calloc(1, sizeof(*frag))) == NULL)
+ goto err;
- if (frag_len) {
- buf = malloc(frag_len);
- if (buf == NULL) {
- free(frag);
- return NULL;
- }
+ if (frag_len > 0) {
+ if ((frag->fragment = calloc(1, frag_len)) == NULL)
+ goto err;
}
- /* zero length fragment gets zero frag->fragment */
- frag->fragment = buf;
-
- /* Initialize reassembly bitmask if necessary */
+ /* Initialize reassembly bitmask if necessary. */
if (reassembly) {
- bitmask = malloc(RSMBLY_BITMASK_SIZE(frag_len));
- if (bitmask == NULL) {
- free(buf);
- free(frag);
- return NULL;
- }
- memset(bitmask, 0, RSMBLY_BITMASK_SIZE(frag_len));
+ if ((frag->reassembly = calloc(1,
+ RSMBLY_BITMASK_SIZE(frag_len))) == NULL)
+ goto err;
}
- frag->reassembly = bitmask;
-
return frag;
+
+ err:
+ dtls1_hm_fragment_free(frag);
+ return NULL;
}
static void