diff options
| author | jsing <> | 2020-09-26 09:01:05 +0000 |
|---|---|---|
| committer | jsing <> | 2020-09-26 09:01:05 +0000 |
| commit | 9b13245446b00e24d00467fda708aec05a3ac606 (patch) | |
| tree | 0ec964f98801cff0df7bbd4eada3822a70414a62 /src | |
| parent | 54565543a39e4f139757aeba9b823d6d2cd8a78a (diff) | |
| download | openbsd-9b13245446b00e24d00467fda708aec05a3ac606.tar.gz openbsd-9b13245446b00e24d00467fda708aec05a3ac606.tar.bz2 openbsd-9b13245446b00e24d00467fda708aec05a3ac606.zip | |
Have dtls1_new() call dtls1_free() on failure.
Allocate into the appropriate structures and call dtls1_free() on failure,
rather than allocating into local variables and then remembering to free
various things on failure.
ok tb@
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/libssl/d1_lib.c | 58 |
1 files changed, 22 insertions, 36 deletions
diff --git a/src/lib/libssl/d1_lib.c b/src/lib/libssl/d1_lib.c index a728944047..b2f05452c8 100644 --- a/src/lib/libssl/d1_lib.c +++ b/src/lib/libssl/d1_lib.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: d1_lib.c,v 1.48 2020/09/26 07:36:51 tb Exp $ */ | 1 | /* $OpenBSD: d1_lib.c,v 1.49 2020/09/26 09:01:05 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. |
| @@ -79,48 +79,34 @@ SSL3_ENC_METHOD DTLSv1_enc_data = { | |||
| 79 | int | 79 | int |
| 80 | dtls1_new(SSL *s) | 80 | dtls1_new(SSL *s) |
| 81 | { | 81 | { |
| 82 | DTLS1_STATE *d1; | ||
| 83 | |||
| 84 | if (!ssl3_new(s)) | 82 | if (!ssl3_new(s)) |
| 85 | return (0); | 83 | goto err; |
| 86 | if ((d1 = calloc(1, sizeof(*d1))) == NULL) { | ||
| 87 | ssl3_free(s); | ||
| 88 | return (0); | ||
| 89 | } | ||
| 90 | if ((d1->internal = calloc(1, sizeof(*d1->internal))) == NULL) { | ||
| 91 | free(d1); | ||
| 92 | ssl3_free(s); | ||
| 93 | return (0); | ||
| 94 | } | ||
| 95 | |||
| 96 | /* d1->handshake_epoch=0; */ | ||
| 97 | 84 | ||
| 98 | d1->internal->unprocessed_rcds.q = pqueue_new(); | 85 | if ((s->d1 = calloc(1, sizeof(*s->d1))) == NULL) |
| 99 | d1->internal->processed_rcds.q = pqueue_new(); | 86 | goto err; |
| 100 | d1->internal->buffered_messages = pqueue_new(); | 87 | if ((s->d1->internal = calloc(1, sizeof(*s->d1->internal))) == NULL) |
| 101 | d1->sent_messages = pqueue_new(); | 88 | goto err; |
| 102 | d1->internal->buffered_app_data.q = pqueue_new(); | ||
| 103 | 89 | ||
| 104 | if (s->server) { | 90 | if ((s->d1->internal->unprocessed_rcds.q = pqueue_new()) == NULL) |
| 105 | d1->internal->cookie_len = sizeof(D1I(s)->cookie); | 91 | goto err; |
| 106 | } | 92 | if ((s->d1->internal->processed_rcds.q = pqueue_new()) == NULL) |
| 93 | goto err; | ||
| 94 | if ((s->d1->internal->buffered_messages = pqueue_new()) == NULL) | ||
| 95 | goto err; | ||
| 96 | if ((s->d1->sent_messages = pqueue_new()) == NULL) | ||
| 97 | goto err; | ||
| 98 | if ((s->d1->internal->buffered_app_data.q = pqueue_new()) == NULL) | ||
| 99 | goto err; | ||
| 107 | 100 | ||
| 108 | if (!d1->internal->unprocessed_rcds.q || !d1->internal->processed_rcds.q || | 101 | if (s->server) |
| 109 | !d1->internal->buffered_messages || !d1->sent_messages || | 102 | s->d1->internal->cookie_len = sizeof(D1I(s)->cookie); |
| 110 | !d1->internal->buffered_app_data.q) { | ||
| 111 | pqueue_free(d1->internal->unprocessed_rcds.q); | ||
| 112 | pqueue_free(d1->internal->processed_rcds.q); | ||
| 113 | pqueue_free(d1->internal->buffered_messages); | ||
| 114 | pqueue_free(d1->sent_messages); | ||
| 115 | pqueue_free(d1->internal->buffered_app_data.q); | ||
| 116 | free(d1); | ||
| 117 | ssl3_free(s); | ||
| 118 | return (0); | ||
| 119 | } | ||
| 120 | 103 | ||
| 121 | s->d1 = d1; | ||
| 122 | s->method->internal->ssl_clear(s); | 104 | s->method->internal->ssl_clear(s); |
| 123 | return (1); | 105 | return (1); |
| 106 | |||
| 107 | err: | ||
| 108 | dtls1_free(s); | ||
| 109 | return (0); | ||
| 124 | } | 110 | } |
| 125 | 111 | ||
| 126 | static void | 112 | static void |
