summaryrefslogtreecommitdiff
path: root/src/lib/libssl/d1_both.c
diff options
context:
space:
mode:
authorjsing <>2020-09-26 08:58:00 +0000
committerjsing <>2020-09-26 08:58:00 +0000
commit54565543a39e4f139757aeba9b823d6d2cd8a78a (patch)
treef04921c071b54b0b4937527030b55242f2f13d65 /src/lib/libssl/d1_both.c
parent3345108d2a65403103b8b6331fac7b04a642dddd (diff)
downloadopenbsd-54565543a39e4f139757aeba9b823d6d2cd8a78a.tar.gz
openbsd-54565543a39e4f139757aeba9b823d6d2cd8a78a.tar.bz2
openbsd-54565543a39e4f139757aeba9b823d6d2cd8a78a.zip
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 'src/lib/libssl/d1_both.c')
-rw-r--r--src/lib/libssl/d1_both.c43
1 files changed, 17 insertions, 26 deletions
diff --git a/src/lib/libssl/d1_both.c b/src/lib/libssl/d1_both.c
index 4a2e41b21b..6541a395a7 100644
--- a/src/lib/libssl/d1_both.c
+++ b/src/lib/libssl/d1_both.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: d1_both.c,v 1.58 2020/08/11 19:13:35 jsing Exp $ */ 1/* $OpenBSD: d1_both.c,v 1.59 2020/09/26 08:58:00 jsing 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.
@@ -166,42 +166,33 @@ static int dtls1_write_message_header(const struct hm_header_st *msg_hdr,
166static long dtls1_get_message_fragment(SSL *s, int st1, int stn, long max, 166static long dtls1_get_message_fragment(SSL *s, int st1, int stn, long max,
167 int *ok); 167 int *ok);
168 168
169static void dtls1_hm_fragment_free(hm_fragment *frag);
170
169static hm_fragment * 171static hm_fragment *
170dtls1_hm_fragment_new(unsigned long frag_len, int reassembly) 172dtls1_hm_fragment_new(unsigned long frag_len, int reassembly)
171{ 173{
172 hm_fragment *frag = NULL; 174 hm_fragment *frag;
173 unsigned char *buf = NULL;
174 unsigned char *bitmask = NULL;
175 175
176 frag = malloc(sizeof(hm_fragment)); 176 if ((frag = calloc(1, sizeof(*frag))) == NULL)
177 if (frag == NULL) 177 goto err;
178 return NULL;
179 178
180 if (frag_len) { 179 if (frag_len > 0) {
181 buf = malloc(frag_len); 180 if ((frag->fragment = calloc(1, frag_len)) == NULL)
182 if (buf == NULL) { 181 goto err;
183 free(frag);
184 return NULL;
185 }
186 } 182 }
187 183
188 /* zero length fragment gets zero frag->fragment */ 184 /* Initialize reassembly bitmask if necessary. */
189 frag->fragment = buf;
190
191 /* Initialize reassembly bitmask if necessary */
192 if (reassembly) { 185 if (reassembly) {
193 bitmask = malloc(RSMBLY_BITMASK_SIZE(frag_len)); 186 if ((frag->reassembly = calloc(1,
194 if (bitmask == NULL) { 187 RSMBLY_BITMASK_SIZE(frag_len))) == NULL)
195 free(buf); 188 goto err;
196 free(frag);
197 return NULL;
198 }
199 memset(bitmask, 0, RSMBLY_BITMASK_SIZE(frag_len));
200 } 189 }
201 190
202 frag->reassembly = bitmask;
203
204 return frag; 191 return frag;
192
193 err:
194 dtls1_hm_fragment_free(frag);
195 return NULL;
205} 196}
206 197
207static void 198static void