diff options
author | jsing <> | 2021-10-23 08:34:36 +0000 |
---|---|---|
committer | jsing <> | 2021-10-23 08:34:36 +0000 |
commit | 3781592d1cd8ce107960abb543e4eccf20288a82 (patch) | |
tree | 84ea9950c0cb3d3c14ebfccb65a931db3ba71bfd /src/lib/libssl/d1_both.c | |
parent | 5ee33af93b944cb8cf535f155eb2a489305b5ccc (diff) | |
download | openbsd-3781592d1cd8ce107960abb543e4eccf20288a82.tar.gz openbsd-3781592d1cd8ce107960abb543e4eccf20288a82.tar.bz2 openbsd-3781592d1cd8ce107960abb543e4eccf20288a82.zip |
Untangle ssl3_get_message() return values.
This function currently has a long return type that may be <= 0 on
error/retry (which is then cast to an int in order to return it up the
stack), or it returns the length of the handshake message (on success).
This obviously means that 0 can be returned for both success and failure,
which is the reason why a separate 'ok' argument has to exist.
Untangle this mess by changing the return value to an int that indicates
success (1) or error/retry (<= 0). The length never needs to actually be
returned as it is already stored in s->internal->init_num (which is where
the return value is read from anyway).
ok tb@
Diffstat (limited to 'src/lib/libssl/d1_both.c')
-rw-r--r-- | src/lib/libssl/d1_both.c | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/src/lib/libssl/d1_both.c b/src/lib/libssl/d1_both.c index 4c014be6a9..7365968db6 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.78 2021/09/04 14:24:28 jsing Exp $ */ | 1 | /* $OpenBSD: d1_both.c,v 1.79 2021/10/23 08:34:36 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. |
@@ -368,13 +368,13 @@ dtls1_do_write(SSL *s, int type) | |||
368 | * Read an entire handshake message. Handshake messages arrive in | 368 | * Read an entire handshake message. Handshake messages arrive in |
369 | * fragments. | 369 | * fragments. |
370 | */ | 370 | */ |
371 | long | 371 | int |
372 | dtls1_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok) | 372 | dtls1_get_message(SSL *s, int st1, int stn, int mt, long max) |
373 | { | 373 | { |
374 | int i, al; | ||
375 | struct hm_header_st *msg_hdr; | 374 | struct hm_header_st *msg_hdr; |
376 | unsigned char *p; | 375 | unsigned char *p; |
377 | unsigned long msg_len; | 376 | unsigned long msg_len; |
377 | int i, al, ok; | ||
378 | 378 | ||
379 | /* | 379 | /* |
380 | * s3->internal->tmp is used to store messages that are unexpected, caused | 380 | * s3->internal->tmp is used to store messages that are unexpected, caused |
@@ -387,21 +387,20 @@ dtls1_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok) | |||
387 | SSLerror(s, SSL_R_UNEXPECTED_MESSAGE); | 387 | SSLerror(s, SSL_R_UNEXPECTED_MESSAGE); |
388 | goto fatal_err; | 388 | goto fatal_err; |
389 | } | 389 | } |
390 | *ok = 1; | ||
391 | s->internal->init_msg = s->internal->init_buf->data + DTLS1_HM_HEADER_LENGTH; | 390 | s->internal->init_msg = s->internal->init_buf->data + DTLS1_HM_HEADER_LENGTH; |
392 | s->internal->init_num = (int)S3I(s)->hs.tls12.message_size; | 391 | s->internal->init_num = (int)S3I(s)->hs.tls12.message_size; |
393 | return s->internal->init_num; | 392 | return 1; |
394 | } | 393 | } |
395 | 394 | ||
396 | msg_hdr = &D1I(s)->r_msg_hdr; | 395 | msg_hdr = &D1I(s)->r_msg_hdr; |
397 | memset(msg_hdr, 0, sizeof(struct hm_header_st)); | 396 | memset(msg_hdr, 0, sizeof(struct hm_header_st)); |
398 | 397 | ||
399 | again: | 398 | again: |
400 | i = dtls1_get_message_fragment(s, st1, stn, max, ok); | 399 | i = dtls1_get_message_fragment(s, st1, stn, max, &ok); |
401 | if (i == DTLS1_HM_BAD_FRAGMENT || | 400 | if (i == DTLS1_HM_BAD_FRAGMENT || |
402 | i == DTLS1_HM_FRAGMENT_RETRY) /* bad fragment received */ | 401 | i == DTLS1_HM_FRAGMENT_RETRY) /* bad fragment received */ |
403 | goto again; | 402 | goto again; |
404 | else if (i <= 0 && !*ok) | 403 | else if (i <= 0 && !ok) |
405 | return i; | 404 | return i; |
406 | 405 | ||
407 | p = (unsigned char *)s->internal->init_buf->data; | 406 | p = (unsigned char *)s->internal->init_buf->data; |
@@ -425,15 +424,13 @@ dtls1_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok) | |||
425 | D1I(s)->handshake_read_seq++; | 424 | D1I(s)->handshake_read_seq++; |
426 | 425 | ||
427 | s->internal->init_msg = s->internal->init_buf->data + DTLS1_HM_HEADER_LENGTH; | 426 | s->internal->init_msg = s->internal->init_buf->data + DTLS1_HM_HEADER_LENGTH; |
428 | return s->internal->init_num; | 427 | return 1; |
429 | 428 | ||
430 | fatal_err: | 429 | fatal_err: |
431 | ssl3_send_alert(s, SSL3_AL_FATAL, al); | 430 | ssl3_send_alert(s, SSL3_AL_FATAL, al); |
432 | *ok = 0; | ||
433 | return -1; | 431 | return -1; |
434 | } | 432 | } |
435 | 433 | ||
436 | |||
437 | static int | 434 | static int |
438 | dtls1_preprocess_fragment(SSL *s, struct hm_header_st *msg_hdr, int max) | 435 | dtls1_preprocess_fragment(SSL *s, struct hm_header_st *msg_hdr, int max) |
439 | { | 436 | { |
@@ -847,8 +844,6 @@ dtls1_get_message_fragment(SSL *s, int st1, int stn, long max, int *ok) | |||
847 | goto fatal_err; | 844 | goto fatal_err; |
848 | } | 845 | } |
849 | 846 | ||
850 | *ok = 1; | ||
851 | |||
852 | /* | 847 | /* |
853 | * Note that s->internal->init_num is *not* used as current offset in | 848 | * Note that s->internal->init_num is *not* used as current offset in |
854 | * s->internal->init_buf->data, but as a counter summing up fragments' | 849 | * s->internal->init_buf->data, but as a counter summing up fragments' |
@@ -856,6 +851,7 @@ dtls1_get_message_fragment(SSL *s, int st1, int stn, long max, int *ok) | |||
856 | * length, we assume we have got all the fragments. | 851 | * length, we assume we have got all the fragments. |
857 | */ | 852 | */ |
858 | s->internal->init_num = frag_len; | 853 | s->internal->init_num = frag_len; |
854 | *ok = 1; | ||
859 | return frag_len; | 855 | return frag_len; |
860 | 856 | ||
861 | fatal_err: | 857 | fatal_err: |