diff options
| author | jsing <> | 2020-09-26 08:58:00 +0000 |
|---|---|---|
| committer | jsing <> | 2020-09-26 08:58:00 +0000 |
| commit | f4c0739084aedd02b6fe70b1b3fd77fb833e59c1 (patch) | |
| tree | f04921c071b54b0b4937527030b55242f2f13d65 | |
| parent | 4284d3c95b72551c4d0f88087d7ef3e863d48e86 (diff) | |
| download | openbsd-f4c0739084aedd02b6fe70b1b3fd77fb833e59c1.tar.gz openbsd-f4c0739084aedd02b6fe70b1b3fd77fb833e59c1.tar.bz2 openbsd-f4c0739084aedd02b6fe70b1b3fd77fb833e59c1.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 '')
| -rw-r--r-- | src/lib/libssl/d1_both.c | 43 |
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, | |||
| 166 | static long dtls1_get_message_fragment(SSL *s, int st1, int stn, long max, | 166 | static long dtls1_get_message_fragment(SSL *s, int st1, int stn, long max, |
| 167 | int *ok); | 167 | int *ok); |
| 168 | 168 | ||
| 169 | static void dtls1_hm_fragment_free(hm_fragment *frag); | ||
| 170 | |||
| 169 | static hm_fragment * | 171 | static hm_fragment * |
| 170 | dtls1_hm_fragment_new(unsigned long frag_len, int reassembly) | 172 | dtls1_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 | ||
| 207 | static void | 198 | static void |
