diff options
| author | jsing <> | 2026-04-30 15:38:52 +0000 |
|---|---|---|
| committer | jsing <> | 2026-04-30 15:38:52 +0000 |
| commit | 8d8e1a7b2e6c542a0e603f8f585ea82b49d2910e (patch) | |
| tree | 0c153ce595ba417a41ca96e40909ac828dac6400 /src/lib | |
| parent | da79a6865de1c92d2576eff815dc5db434d73075 (diff) | |
| download | openbsd-8d8e1a7b2e6c542a0e603f8f585ea82b49d2910e.tar.gz openbsd-8d8e1a7b2e6c542a0e603f8f585ea82b49d2910e.tar.bz2 openbsd-8d8e1a7b2e6c542a0e603f8f585ea82b49d2910e.zip | |
Refactor dtls1_do_write_handshake_message().
If the call to dtls1_write_bytes() fails, handle the potential MTU update
and return/continue, which allows for the remainder to be moved out of an
else statement.
ok kenjiro@ tb@
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/libssl/d1_both.c | 87 |
1 files changed, 44 insertions, 43 deletions
diff --git a/src/lib/libssl/d1_both.c b/src/lib/libssl/d1_both.c index 2632d100e1..32bbf41966 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.91 2026/04/29 15:13:27 jsing Exp $ */ | 1 | /* $OpenBSD: d1_both.c,v 1.92 2026/04/30 15:38:52 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. |
| @@ -292,60 +292,61 @@ dtls1_do_write_handshake_message(SSL *s) | |||
| 292 | * handle the retransmit | 292 | * handle the retransmit |
| 293 | */ | 293 | */ |
| 294 | if (BIO_ctrl(SSL_get_wbio(s), | 294 | if (BIO_ctrl(SSL_get_wbio(s), |
| 295 | BIO_CTRL_DGRAM_MTU_EXCEEDED, 0, NULL) > 0) | 295 | BIO_CTRL_DGRAM_MTU_EXCEEDED, 0, NULL) <= 0) |
| 296 | s->d1->mtu = BIO_ctrl(SSL_get_wbio(s), | ||
| 297 | BIO_CTRL_DGRAM_QUERY_MTU, 0, NULL); | ||
| 298 | else | ||
| 299 | return (-1); | 296 | return (-1); |
| 300 | } else { | ||
| 301 | 297 | ||
| 298 | s->d1->mtu = BIO_ctrl(SSL_get_wbio(s), | ||
| 299 | BIO_CTRL_DGRAM_QUERY_MTU, 0, NULL); | ||
| 300 | |||
| 301 | continue; | ||
| 302 | } | ||
| 303 | |||
| 304 | /* | ||
| 305 | * Bad if this assert fails, only part of the | ||
| 306 | * handshake message got sent. but why would | ||
| 307 | * this happen? | ||
| 308 | */ | ||
| 309 | OPENSSL_assert(len == (unsigned int)ret); | ||
| 310 | |||
| 311 | if (!s->d1->retransmitting) { | ||
| 302 | /* | 312 | /* |
| 303 | * Bad if this assert fails, only part of the | 313 | * Should not be done for 'Hello Request's, |
| 304 | * handshake message got sent. but why would | 314 | * but in that case we'll ignore the result |
| 305 | * this happen? | 315 | * anyway |
| 306 | */ | 316 | */ |
| 307 | OPENSSL_assert(len == (unsigned int)ret); | 317 | unsigned char *p = (unsigned char *)&s->init_buf->data[s->init_off]; |
| 318 | const struct hm_header_st *msg_hdr = &s->d1->w_msg_hdr; | ||
| 319 | int xlen; | ||
| 308 | 320 | ||
| 309 | if (!s->d1->retransmitting) { | 321 | if (frag_off == 0) { |
| 310 | /* | 322 | /* |
| 311 | * Should not be done for 'Hello Request's, | 323 | * Reconstruct message header is if it |
| 312 | * but in that case we'll ignore the result | 324 | * is being sent in single fragment |
| 313 | * anyway | ||
| 314 | */ | 325 | */ |
| 315 | unsigned char *p = (unsigned char *)&s->init_buf->data[s->init_off]; | 326 | if (!dtls1_write_message_header(msg_hdr, |
| 316 | const struct hm_header_st *msg_hdr = &s->d1->w_msg_hdr; | 327 | 0, msg_hdr->msg_len, p)) |
| 317 | int xlen; | 328 | return (-1); |
| 318 | 329 | xlen = ret; | |
| 319 | if (frag_off == 0) { | 330 | } else { |
| 320 | /* | 331 | p += DTLS1_HM_HEADER_LENGTH; |
| 321 | * Reconstruct message header is if it | 332 | xlen = ret - DTLS1_HM_HEADER_LENGTH; |
| 322 | * is being sent in single fragment | ||
| 323 | */ | ||
| 324 | if (!dtls1_write_message_header(msg_hdr, | ||
| 325 | 0, msg_hdr->msg_len, p)) | ||
| 326 | return (-1); | ||
| 327 | xlen = ret; | ||
| 328 | } else { | ||
| 329 | p += DTLS1_HM_HEADER_LENGTH; | ||
| 330 | xlen = ret - DTLS1_HM_HEADER_LENGTH; | ||
| 331 | } | ||
| 332 | |||
| 333 | tls1_transcript_record(s, p, xlen); | ||
| 334 | } | 333 | } |
| 335 | 334 | ||
| 336 | if (ret == s->init_num) { | 335 | tls1_transcript_record(s, p, xlen); |
| 337 | ssl_msg_callback(s, 1, SSL3_RT_HANDSHAKE, | 336 | } |
| 338 | s->init_buf->data, s->init_off + s->init_num); | ||
| 339 | 337 | ||
| 340 | s->init_off = 0; | 338 | if (ret == s->init_num) { |
| 341 | s->init_num = 0; | 339 | ssl_msg_callback(s, 1, SSL3_RT_HANDSHAKE, |
| 340 | s->init_buf->data, s->init_off + s->init_num); | ||
| 342 | 341 | ||
| 343 | return 1; | 342 | s->init_off = 0; |
| 344 | } | 343 | s->init_num = 0; |
| 345 | s->init_off += ret; | 344 | |
| 346 | s->init_num -= ret; | 345 | return (1); |
| 347 | frag_off += (ret -= DTLS1_HM_HEADER_LENGTH); | ||
| 348 | } | 346 | } |
| 347 | s->init_off += ret; | ||
| 348 | s->init_num -= ret; | ||
| 349 | frag_off += (ret -= DTLS1_HM_HEADER_LENGTH); | ||
| 349 | } | 350 | } |
| 350 | return (0); | 351 | return (0); |
| 351 | } | 352 | } |
