From 5508d27e6c36d40d5cc75a4f81a5374522797121 Mon Sep 17 00:00:00 2001 From: tb Date: Mon, 6 Jun 2022 15:20:54 +0000 Subject: [PATCH] Minor style cleanup in ssl_txt.c Wrap long lines and fix a bug where the wrong struct member was checked for NULL. ok jsing --- lib/libssl/ssl_txt.c | 64 ++++++++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 23 deletions(-) diff --git a/lib/libssl/ssl_txt.c b/lib/libssl/ssl_txt.c index 72ce1a0bce4..09685436198 100644 --- a/lib/libssl/ssl_txt.c +++ b/lib/libssl/ssl_txt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ssl_txt.c,v 1.31 2021/11/29 18:36:27 tb Exp $ */ +/* $OpenBSD: ssl_txt.c,v 1.32 2022/06/06 15:20:54 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -96,92 +96,110 @@ SSL_SESSION_print_fp(FILE *fp, const SSL_SESSION *x) if ((b = BIO_new(BIO_s_file())) == NULL) { SSLerrorx(ERR_R_BUF_LIB); - return (0); + return 0; } BIO_set_fp(b, fp, BIO_NOCLOSE); ret = SSL_SESSION_print(b, x); BIO_free(b); - return (ret); + return ret; } int SSL_SESSION_print(BIO *bp, const SSL_SESSION *x) { unsigned int i; - const char *s; + int ret = 0; if (x == NULL) goto err; + if (BIO_puts(bp, "SSL-Session:\n") <= 0) goto err; - s = ssl_version_string(x->ssl_version); - if (BIO_printf(bp, " Protocol : %s\n", s) <= 0) + if (BIO_printf(bp, " Protocol : %s\n", + ssl_version_string(x->ssl_version)) <= 0) goto err; if (x->cipher == NULL) { - if (((x->cipher_id) & 0xff000000) == 0x02000000) { - if (BIO_printf(bp, " Cipher : %06lX\n", x->cipher_id&0xffffff) <= 0) + if ((x->cipher_id & 0xff000000) == 0x02000000) { + if (BIO_printf(bp, " Cipher : %06lX\n", + x->cipher_id & 0xffffff) <= 0) goto err; } else { - if (BIO_printf(bp, " Cipher : %04lX\n", x->cipher_id&0xffff) <= 0) + if (BIO_printf(bp, " Cipher : %04lX\n", + x->cipher_id & 0xffff) <= 0) goto err; } } else { - if (BIO_printf(bp, " Cipher : %s\n",((x->cipher == NULL)?"unknown":x->cipher->name)) <= 0) + const char *cipher_name = "unknown"; + + if (x->cipher->name != NULL) + cipher_name = x->cipher->name; + + if (BIO_printf(bp, " Cipher : %s\n", cipher_name) <= 0) goto err; } + if (BIO_puts(bp, " Session-ID: ") <= 0) goto err; + for (i = 0; i < x->session_id_length; i++) { if (BIO_printf(bp, "%02X", x->session_id[i]) <= 0) goto err; } + if (BIO_puts(bp, "\n Session-ID-ctx: ") <= 0) goto err; + for (i = 0; i < x->sid_ctx_length; i++) { if (BIO_printf(bp, "%02X", x->sid_ctx[i]) <= 0) goto err; } + if (BIO_puts(bp, "\n Master-Key: ") <= 0) goto err; + for (i = 0; i < (unsigned int)x->master_key_length; i++) { if (BIO_printf(bp, "%02X", x->master_key[i]) <= 0) goto err; } - if (x->tlsext_tick_lifetime_hint) { + + if (x->tlsext_tick_lifetime_hint > 0) { if (BIO_printf(bp, "\n TLS session ticket lifetime hint: %u (seconds)", x->tlsext_tick_lifetime_hint) <= 0) goto err; } - if (x->tlsext_tick) { + + if (x->tlsext_tick != NULL) { if (BIO_puts(bp, "\n TLS session ticket:\n") <= 0) goto err; - if (BIO_dump_indent(bp, (char *)x->tlsext_tick, x->tlsext_ticklen, 4) <= 0) + if (BIO_dump_indent(bp, x->tlsext_tick, x->tlsext_ticklen, + 4) <= 0) goto err; } if (x->time != 0) { - if (BIO_printf(bp, "\n Start Time: %lld", (long long)x->time) <= 0) + if (BIO_printf(bp, "\n Start Time: %lld", + (long long)x->time) <= 0) goto err; } - if (x->timeout != 0L) { - if (BIO_printf(bp, "\n Timeout : %ld (sec)", x->timeout) <= 0) + + if (x->timeout != 0) { + if (BIO_printf(bp, "\n Timeout : %ld (sec)", + x->timeout) <= 0) goto err; } - if (BIO_puts(bp, "\n") <= 0) - goto err; - if (BIO_puts(bp, " Verify return code: ") <= 0) + if (BIO_puts(bp, "\n") <= 0) goto err; - if (BIO_printf(bp, "%ld (%s)\n", x->verify_result, + if (BIO_printf(bp, " Verify return code: %ld (%s)\n", + x->verify_result, X509_verify_cert_error_string(x->verify_result)) <= 0) goto err; - return (1); + ret = 1; err: - return (0); + return ret; } - -- 2.20.1