summaryrefslogtreecommitdiff
path: root/src/lib/libssl/d1_pkt.c
diff options
context:
space:
mode:
authorjsing <>2017-01-25 06:13:02 +0000
committerjsing <>2017-01-25 06:13:02 +0000
commit994be17488e885953ca1fef89bbc4d5fb24eba71 (patch)
treefa8c6cb9fb6d55c7422e8539eed63d9c115a282d /src/lib/libssl/d1_pkt.c
parent0bc052b366fc7f6e3f38271d4294ce4217f86f4d (diff)
downloadopenbsd-994be17488e885953ca1fef89bbc4d5fb24eba71.tar.gz
openbsd-994be17488e885953ca1fef89bbc4d5fb24eba71.tar.bz2
openbsd-994be17488e885953ca1fef89bbc4d5fb24eba71.zip
Provide ssl3_packet_read() and ssl3_packet_extend() functions that improve
the awkward API provided by ssl3_read_n(). Call these when we need to read or extend a packet. ok beck@
Diffstat (limited to 'src/lib/libssl/d1_pkt.c')
-rw-r--r--src/lib/libssl/d1_pkt.c31
1 files changed, 12 insertions, 19 deletions
diff --git a/src/lib/libssl/d1_pkt.c b/src/lib/libssl/d1_pkt.c
index f15b64364e..19853d2375 100644
--- a/src/lib/libssl/d1_pkt.c
+++ b/src/lib/libssl/d1_pkt.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: d1_pkt.c,v 1.58 2017/01/23 14:35:42 jsing Exp $ */ 1/* $OpenBSD: d1_pkt.c,v 1.59 2017/01/25 06:13:02 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.
@@ -469,11 +469,11 @@ err:
469int 469int
470dtls1_get_record(SSL *s) 470dtls1_get_record(SSL *s)
471{ 471{
472 int i, n;
473 SSL3_RECORD *rr; 472 SSL3_RECORD *rr;
474 unsigned char *p = NULL; 473 unsigned char *p = NULL;
475 DTLS1_BITMAP *bitmap; 474 DTLS1_BITMAP *bitmap;
476 unsigned int is_next_epoch; 475 unsigned int is_next_epoch;
476 int n;
477 477
478 rr = &(S3I(s)->rrec); 478 rr = &(S3I(s)->rrec);
479 479
@@ -501,13 +501,12 @@ again:
501 uint16_t epoch, len, ssl_version; 501 uint16_t epoch, len, ssl_version;
502 uint8_t type; 502 uint8_t type;
503 503
504 n = ssl3_read_n(s, DTLS1_RT_HEADER_LENGTH, s->s3->rbuf.len, 0); 504 n = ssl3_packet_read(s, DTLS1_RT_HEADER_LENGTH);
505 /* read timeout is handled by dtls1_read_bytes */
506 if (n <= 0) 505 if (n <= 0)
507 return(n); /* error or non-blocking */ 506 return (n);
508 507
509 /* this packet contained a partial record, dump it */ 508 /* If this packet contained a partial record, dump it. */
510 if (s->internal->packet_length != DTLS1_RT_HEADER_LENGTH) 509 if (n != DTLS1_RT_HEADER_LENGTH)
511 goto again; 510 goto again;
512 511
513 s->internal->rstate = SSL_ST_READ_BODY; 512 s->internal->rstate = SSL_ST_READ_BODY;
@@ -553,20 +552,14 @@ again:
553 552
554 /* s->internal->rstate == SSL_ST_READ_BODY, get and decode the data */ 553 /* s->internal->rstate == SSL_ST_READ_BODY, get and decode the data */
555 554
556 if (rr->length > s->internal->packet_length - DTLS1_RT_HEADER_LENGTH) { 555 n = ssl3_packet_extend(s, DTLS1_RT_HEADER_LENGTH + rr->length);
557 /* now s->internal->packet_length == DTLS1_RT_HEADER_LENGTH */ 556 if (n <= 0)
558 i = rr->length; 557 return (n);
559 n = ssl3_read_n(s, i, i, 1);
560 if (n <= 0)
561 return(n); /* error or non-blocking io */
562 558
563 /* this packet contained a partial record, dump it */ 559 /* If this packet contained a partial record, dump it. */
564 if (n != i) 560 if (n != DTLS1_RT_HEADER_LENGTH + rr->length)
565 goto again; 561 goto again;
566 562
567 /* now n == rr->length,
568 * and s->internal->packet_length == DTLS1_RT_HEADER_LENGTH + rr->length */
569 }
570 s->internal->rstate = SSL_ST_READ_HEADER; /* set state for later operations */ 563 s->internal->rstate = SSL_ST_READ_HEADER; /* set state for later operations */
571 564
572 /* match epochs. NULL means the packet is dropped on the floor */ 565 /* match epochs. NULL means the packet is dropped on the floor */