diff options
author | jsing <> | 2021-09-04 14:24:28 +0000 |
---|---|---|
committer | jsing <> | 2021-09-04 14:24:28 +0000 |
commit | dee1e6cf24ed6de39feac8e8be7b300789269839 (patch) | |
tree | 30ff1d6ccf31f3c51cfc256334e43e5e1cf91810 /src/lib/libssl/d1_both.c | |
parent | a9d8853125301b55e45f0243ec734a0fb4f3a8f3 (diff) | |
download | openbsd-dee1e6cf24ed6de39feac8e8be7b300789269839.tar.gz openbsd-dee1e6cf24ed6de39feac8e8be7b300789269839.tar.bz2 openbsd-dee1e6cf24ed6de39feac8e8be7b300789269839.zip |
Change dtls1_get_message_header() to take a CBS.
The callers know the actual length and can initialise a CBS correctly.
ok inoguchi@ tb@
Diffstat (limited to 'src/lib/libssl/d1_both.c')
-rw-r--r-- | src/lib/libssl/d1_both.c | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/src/lib/libssl/d1_both.c b/src/lib/libssl/d1_both.c index 61dc47b4b7..4c014be6a9 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.77 2021/07/19 08:42:24 jsing Exp $ */ | 1 | /* $OpenBSD: d1_both.c,v 1.78 2021/09/04 14:24:28 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. |
@@ -744,8 +744,9 @@ dtls1_get_message_fragment(SSL *s, int st1, int stn, long max, int *ok) | |||
744 | { | 744 | { |
745 | unsigned char wire[DTLS1_HM_HEADER_LENGTH]; | 745 | unsigned char wire[DTLS1_HM_HEADER_LENGTH]; |
746 | unsigned long len, frag_off, frag_len; | 746 | unsigned long len, frag_off, frag_len; |
747 | int i, al; | ||
748 | struct hm_header_st msg_hdr; | 747 | struct hm_header_st msg_hdr; |
748 | int i, al; | ||
749 | CBS cbs; | ||
749 | 750 | ||
750 | again: | 751 | again: |
751 | /* see if we have the required fragment already */ | 752 | /* see if we have the required fragment already */ |
@@ -758,16 +759,16 @@ dtls1_get_message_fragment(SSL *s, int st1, int stn, long max, int *ok) | |||
758 | /* read handshake message header */ | 759 | /* read handshake message header */ |
759 | i = s->method->ssl_read_bytes(s, SSL3_RT_HANDSHAKE, wire, | 760 | i = s->method->ssl_read_bytes(s, SSL3_RT_HANDSHAKE, wire, |
760 | DTLS1_HM_HEADER_LENGTH, 0); | 761 | DTLS1_HM_HEADER_LENGTH, 0); |
761 | if (i <= 0) /* nbio, or an error */ | 762 | if (i <= 0) { |
762 | { | 763 | /* nbio, or an error */ |
763 | s->internal->rwstate = SSL_READING; | 764 | s->internal->rwstate = SSL_READING; |
764 | *ok = 0; | 765 | *ok = 0; |
765 | return i; | 766 | return i; |
766 | } | 767 | } |
767 | /* Handshake fails if message header is incomplete */ | 768 | |
768 | if (i != DTLS1_HM_HEADER_LENGTH || | 769 | CBS_init(&cbs, wire, i); |
769 | /* parse the message fragment header */ | 770 | if (!dtls1_get_message_header(&cbs, &msg_hdr)) { |
770 | dtls1_get_message_header(wire, &msg_hdr) == 0) { | 771 | /* Handshake fails if message header is incomplete. */ |
771 | al = SSL_AD_UNEXPECTED_MESSAGE; | 772 | al = SSL_AD_UNEXPECTED_MESSAGE; |
772 | SSLerror(s, SSL_R_UNEXPECTED_MESSAGE); | 773 | SSLerror(s, SSL_R_UNEXPECTED_MESSAGE); |
773 | goto fatal_err; | 774 | goto fatal_err; |
@@ -1172,26 +1173,23 @@ dtls1_guess_mtu(unsigned int curr_mtu) | |||
1172 | } | 1173 | } |
1173 | 1174 | ||
1174 | int | 1175 | int |
1175 | dtls1_get_message_header(unsigned char *data, struct hm_header_st *msg_hdr) | 1176 | dtls1_get_message_header(CBS *header, struct hm_header_st *msg_hdr) |
1176 | { | 1177 | { |
1177 | CBS header; | ||
1178 | uint32_t msg_len, frag_off, frag_len; | 1178 | uint32_t msg_len, frag_off, frag_len; |
1179 | uint16_t seq; | 1179 | uint16_t seq; |
1180 | uint8_t type; | 1180 | uint8_t type; |
1181 | 1181 | ||
1182 | CBS_init(&header, data, sizeof(*msg_hdr)); | ||
1183 | |||
1184 | memset(msg_hdr, 0, sizeof(*msg_hdr)); | 1182 | memset(msg_hdr, 0, sizeof(*msg_hdr)); |
1185 | 1183 | ||
1186 | if (!CBS_get_u8(&header, &type)) | 1184 | if (!CBS_get_u8(header, &type)) |
1187 | return 0; | 1185 | return 0; |
1188 | if (!CBS_get_u24(&header, &msg_len)) | 1186 | if (!CBS_get_u24(header, &msg_len)) |
1189 | return 0; | 1187 | return 0; |
1190 | if (!CBS_get_u16(&header, &seq)) | 1188 | if (!CBS_get_u16(header, &seq)) |
1191 | return 0; | 1189 | return 0; |
1192 | if (!CBS_get_u24(&header, &frag_off)) | 1190 | if (!CBS_get_u24(header, &frag_off)) |
1193 | return 0; | 1191 | return 0; |
1194 | if (!CBS_get_u24(&header, &frag_len)) | 1192 | if (!CBS_get_u24(header, &frag_len)) |
1195 | return 0; | 1193 | return 0; |
1196 | 1194 | ||
1197 | msg_hdr->type = type; | 1195 | msg_hdr->type = type; |