From 357c6b751ff94c0d7866238d74244b5e22d6d05d Mon Sep 17 00:00:00 2001 From: tb Date: Sun, 18 Feb 2024 16:56:33 +0000 Subject: [PATCH] Adjust regress test for memset() requested by jsing on review --- regress/lib/libcrypto/asn1/asn1time.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/regress/lib/libcrypto/asn1/asn1time.c b/regress/lib/libcrypto/asn1/asn1time.c index b3418c46165..f764df12d59 100644 --- a/regress/lib/libcrypto/asn1/asn1time.c +++ b/regress/lib/libcrypto/asn1/asn1time.c @@ -1,4 +1,4 @@ -/* $OpenBSD: asn1time.c,v 1.22 2024/02/18 16:32:29 tb Exp $ */ +/* $OpenBSD: asn1time.c,v 1.23 2024/02/18 16:56:33 tb Exp $ */ /* * Copyright (c) 2015 Joel Sing * Copyright (c) 2024 Google Inc. @@ -576,7 +576,7 @@ static int asn1_time_overflow(void) { struct tm overflow_year = {0}, overflow_month = {0}; - struct tm copy, max_time = {0}, min_time = {0}; + struct tm copy, max_time = {0}, min_time = {0}, zero = {0}; int64_t valid_time_range = INT64_C(315569519999); int64_t posix_u64; time_t posix_time; @@ -654,6 +654,12 @@ asn1_time_overflow(void) "fail for maximum time\n"); goto err; } + if (memcmp(&zero, &max_time, sizeof(max_time)) != 0) { + fprintf(stderr, "FAIL: failing OPENSSL_gmtime_adj didn't " + "zero out max_time\n"); + goto err; + } + max_time = copy; min_time.tm_year = 0 - 1900; min_time.tm_mon = 1 - 1; @@ -678,6 +684,12 @@ asn1_time_overflow(void) "fail for minimum time\n"); goto err; } + if (memcmp(&zero, &min_time, sizeof(min_time)) != 0) { + fprintf(stderr, "FAIL: failing OPENSSL_gmtime_adj didn't " + "zero out max_time\n"); + goto err; + } + min_time = copy; /* Test that we can offset by the valid minimum and maximum times. */ if (!OPENSSL_gmtime_adj(©, 0, valid_time_range)) { @@ -686,8 +698,10 @@ asn1_time_overflow(void) goto err; } if (memcmp(©, &max_time, sizeof(max_time)) != 0) { - fprintf(stderr, "FAIL: maximally adjusted copy didn't match" + fprintf(stderr, "FAIL: maximally adjusted copy didn't match " "max_time\n"); + hexdump((unsigned char *)&max_time, sizeof(max_time)); + hexdump((unsigned char *)©, sizeof(copy)); goto err; } if (!OPENSSL_gmtime_adj(©, 0, -valid_time_range)) { @@ -696,7 +710,7 @@ asn1_time_overflow(void) goto err; } if (memcmp(©, &min_time, sizeof(min_time)) != 0) { - fprintf(stderr, "FAIL: maximally adjusted copy didn't match" + fprintf(stderr, "FAIL: maximally adjusted copy didn't match " "min_time\n"); goto err; } -- 2.20.1