Simplify various CBS_write_bytes() calls
authortb <tb@openbsd.org>
Tue, 7 Jun 2022 17:45:13 +0000 (17:45 +0000)
committertb <tb@openbsd.org>
Tue, 7 Jun 2022 17:45:13 +0000 (17:45 +0000)
Now that session_id_length is a size_t, we can pass it directly to
CBS_write_bytes() instead of using a temporary variable.

ok jsing

lib/libssl/ssl_asn1.c
lib/libssl/ssl_clnt.c
lib/libssl/ssl_sess.c

index 86e0663..d513811 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssl_asn1.c,v 1.63 2022/06/07 17:20:26 tb Exp $ */
+/* $OpenBSD: ssl_asn1.c,v 1.64 2022/06/07 17:45:13 tb Exp $ */
 /*
  * Copyright (c) 2016 Joel Sing <jsing@openbsd.org>
  *
@@ -295,11 +295,8 @@ d2i_SSL_SESSION(SSL_SESSION **a, const unsigned char **pp, long length)
        if (!CBS_get_asn1(&session, &session_id, CBS_ASN1_OCTETSTRING))
                goto err;
        if (!CBS_write_bytes(&session_id, s->session_id, sizeof(s->session_id),
-           &data_len))
+           &s->session_id_length))
                goto err;
-       if (data_len > UINT_MAX)
-               goto err;
-       s->session_id_length = (unsigned int)data_len;
 
        /* Master key. */
        if (!CBS_get_asn1(&session, &master_key, CBS_ASN1_OCTETSTRING))
index f8a80ee..c509771 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssl_clnt.c,v 1.145 2022/06/07 17:39:16 tb Exp $ */
+/* $OpenBSD: ssl_clnt.c,v 1.146 2022/06/07 17:45:13 tb Exp $ */
 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  * All rights reserved.
  *
@@ -815,7 +815,6 @@ ssl3_get_server_hello(SSL *s)
        const SSL_CIPHER *cipher;
        const SSL_METHOD *method;
        unsigned long alg_k;
-       size_t outlen;
        int al, ret;
 
        s->internal->first_packet = 1;
@@ -975,9 +974,9 @@ ssl3_get_server_hello(SSL *s)
                 * zero length session identifier.
                 */
                if (!CBS_write_bytes(&session_id, s->session->session_id,
-                   sizeof(s->session->session_id), &outlen))
+                   sizeof(s->session->session_id),
+                   &s->session->session_id_length))
                        goto err;
-               s->session->session_id_length = outlen;
 
                s->session->ssl_version = s->version;
        }
index 969371b..504c402 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssl_sess.c,v 1.114 2022/06/07 17:32:53 tb Exp $ */
+/* $OpenBSD: ssl_sess.c,v 1.115 2022/06/07 17:45:13 tb Exp $ */
 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  * All rights reserved.
  *
@@ -526,7 +526,6 @@ int
 ssl_get_prev_session(SSL *s, CBS *session_id, CBS *ext_block, int *alert)
 {
        SSL_SESSION *sess = NULL;
-       size_t session_id_len;
        int alert_desc = SSL_AD_INTERNAL_ERROR, fatal = 0;
        int ticket_decrypted = 0;
 
@@ -555,11 +554,10 @@ ssl_get_prev_session(SSL *s, CBS *session_id, CBS *ext_block, int *alert)
                 * ticket has been accepted so we copy it into sess.
                 */
                if (!CBS_write_bytes(session_id, sess->session_id,
-                   sizeof(sess->session_id), &session_id_len)) {
+                   sizeof(sess->session_id), &sess->session_id_length)) {
                        fatal = 1;
                        goto err;
                }
-               sess->session_id_length = (unsigned int)session_id_len;
                break;
        default:
                SSLerror(s, ERR_R_INTERNAL_ERROR);