summaryrefslogtreecommitdiff
path: root/lib/libssl/d1_pkt.c
diff options
context:
space:
mode:
authorDoug Hogan <doug@cvs.openbsd.org>2015-07-18 22:28:54 +0000
committerDoug Hogan <doug@cvs.openbsd.org>2015-07-18 22:28:54 +0000
commit3318d4f870f9445e1f4caffd39dbc6819d624259 (patch)
tree05d4b9eb449dd16d99c26d10904447694888933a /lib/libssl/d1_pkt.c
parent9c8e29f9933bffe853b57428ff21c9be4617b094 (diff)
Remove repeated code in dtls1_get_record.
The "if" is a bit ugly, but this does remove a lot of repetitive code. This will be converted to CBS later as well. ok miod@ jsing@ roughly ok with it after seeing the CBS version
Diffstat (limited to 'lib/libssl/d1_pkt.c')
-rw-r--r--lib/libssl/d1_pkt.c56
1 files changed, 16 insertions, 40 deletions
diff --git a/lib/libssl/d1_pkt.c b/lib/libssl/d1_pkt.c
index 60c1236f53a..68571c8fd06 100644
--- a/lib/libssl/d1_pkt.c
+++ b/lib/libssl/d1_pkt.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: d1_pkt.c,v 1.42 2015/06/17 07:29:33 doug Exp $ */
+/* $OpenBSD: d1_pkt.c,v 1.43 2015/07/18 22:28:53 doug Exp $ */
/*
* DTLS implementation written by Nagendra Modadugu
* (nagendra@cs.stanford.edu) for the OpenSSL project 2005.
@@ -484,7 +484,13 @@ dtls1_get_record(SSL *s)
return 1;
/* get something from the wire */
+ if (0) {
again:
+ /* dump this record on all retries */
+ rr->length = 0;
+ s->packet_length = 0;
+ }
+
/* check if we have the header */
if ((s->rstate != SSL_ST_READ_BODY) ||
(s->packet_length < DTLS1_RT_HEADER_LENGTH)) {
@@ -494,10 +500,8 @@ again:
return(n); /* error or non-blocking */
/* this packet contained a partial record, dump it */
- if (s->packet_length != DTLS1_RT_HEADER_LENGTH) {
- s->packet_length = 0;
+ if (s->packet_length != DTLS1_RT_HEADER_LENGTH)
goto again;
- }
s->rstate = SSL_ST_READ_BODY;
@@ -519,27 +523,18 @@ again:
/* Lets check version */
if (!s->first_packet) {
- if (version != s->version) {
+ if (version != s->version)
/* unexpected version, silently discard */
- rr->length = 0;
- s->packet_length = 0;
goto again;
- }
}
- if ((version & 0xff00) != (s->version & 0xff00)) {
+ if ((version & 0xff00) != (s->version & 0xff00))
/* wrong version, silently discard record */
- rr->length = 0;
- s->packet_length = 0;
goto again;
- }
- if (rr->length > SSL3_RT_MAX_ENCRYPTED_LENGTH) {
+ if (rr->length > SSL3_RT_MAX_ENCRYPTED_LENGTH)
/* record too long, silently discard it */
- rr->length = 0;
- s->packet_length = 0;
goto again;
- }
/* now s->rstate == SSL_ST_READ_BODY */
}
@@ -554,11 +549,8 @@ again:
return(n); /* error or non-blocking io */
/* this packet contained a partial record, dump it */
- if (n != i) {
- rr->length = 0;
- s->packet_length = 0;
+ if (n != i)
goto again;
- }
/* now n == rr->length,
* and s->packet_length == DTLS1_RT_HEADER_LENGTH + rr->length */
@@ -567,13 +559,8 @@ again:
/* match epochs. NULL means the packet is dropped on the floor */
bitmap = dtls1_get_bitmap(s, rr, &is_next_epoch);
- if (bitmap == NULL) {
- rr->length = 0;
- s->packet_length = 0;
- /* dump this record */
+ if (bitmap == NULL)
goto again;
- /* get another record */
- }
/*
* Check whether this is a repeat, or aged record.
@@ -584,12 +571,8 @@ again:
*/
if (!(s->d1->listen && rr->type == SSL3_RT_HANDSHAKE &&
p != NULL && *p == SSL3_MT_CLIENT_HELLO) &&
- !dtls1_record_replay_check(s, bitmap)) {
- rr->length = 0;
- s->packet_length=0; /* dump this record */
+ !dtls1_record_replay_check(s, bitmap))
goto again;
- /* get another record */
- }
/* just read a 0 length packet */
if (rr->length == 0)
@@ -608,23 +591,16 @@ again:
/* Mark receipt of record. */
dtls1_record_bitmap_update(s, bitmap);
}
- rr->length = 0;
- s->packet_length = 0;
goto again;
}
- if (!dtls1_process_record(s)) {
- rr->length = 0;
- s->packet_length = 0;
- /* dump this record */
+ if (!dtls1_process_record(s))
goto again;
- /* get another record */
- }
+
/* Mark receipt of record. */
dtls1_record_bitmap_update(s, bitmap);
return (1);
-
}
/* Return up to 'len' payload bytes received in 'type' records.