From 054c5de2e852004e06211ff00af4c880504a256f Mon Sep 17 00:00:00 2001 From: jsing <> Date: Sat, 25 Jun 2022 15:41:14 +0000 Subject: Add regress for ASN1_INTEGER_{get,set}_{u,}int64() --- src/regress/lib/libcrypto/asn1/asn1basic.c | 104 ++++++++++++++++++++++++++++- 1 file changed, 103 insertions(+), 1 deletion(-) diff --git a/src/regress/lib/libcrypto/asn1/asn1basic.c b/src/regress/lib/libcrypto/asn1/asn1basic.c index 543ee93ee8..e46f9430a6 100644 --- a/src/regress/lib/libcrypto/asn1/asn1basic.c +++ b/src/regress/lib/libcrypto/asn1/asn1basic.c @@ -1,4 +1,4 @@ -/* $OpenBSD: asn1basic.c,v 1.7 2022/06/25 13:57:17 jsing Exp $ */ +/* $OpenBSD: asn1basic.c,v 1.8 2022/06/25 15:41:14 jsing Exp $ */ /* * Copyright (c) 2017, 2021 Joel Sing * @@ -459,6 +459,107 @@ asn1_integer_decode_test(struct asn1_integer_test *ait) return failed; } +static int +asn1_integer_set_val_test(void) +{ + ASN1_INTEGER *aint = NULL; + uint64_t uval; + int64_t val; + int failed = 1; + + if ((aint = ASN1_INTEGER_new()) == NULL) { + fprintf(stderr, "FAIL: ASN1_INTEGER_new() == NULL\n"); + goto failed; + } + + if (!ASN1_INTEGER_set_uint64(aint, 0)) { + fprintf(stderr, "FAIL: ASN_INTEGER_set_uint64() failed with " + "0\n"); + goto failed; + } + if (!ASN1_INTEGER_get_uint64(&uval, aint)) { + fprintf(stderr, "FAIL: ASN_INTEGER_get_uint64() failed with " + "0\n"); + goto failed; + } + if (uval != 0) { + fprintf(stderr, "FAIL: uval != 0\n"); + goto failed; + } + + if (!ASN1_INTEGER_set_uint64(aint, UINT64_MAX)) { + fprintf(stderr, "FAIL: ASN_INTEGER_set_uint64() failed with " + "UINT64_MAX\n"); + goto failed; + } + if (!ASN1_INTEGER_get_uint64(&uval, aint)) { + fprintf(stderr, "FAIL: ASN_INTEGER_get_uint64() failed with " + "UINT64_MAX\n"); + goto failed; + } + if (uval != UINT64_MAX) { + fprintf(stderr, "FAIL: uval != UINT64_MAX\n"); + goto failed; + } + if (ASN1_INTEGER_get_int64(&val, aint)) { + fprintf(stderr, "FAIL: ASN_INTEGER_get_int64() succeeded " + "with UINT64_MAX\n"); + goto failed; + } + + if (!ASN1_INTEGER_set_int64(aint, INT64_MIN)) { + fprintf(stderr, "FAIL: ASN_INTEGER_set_int64() failed with " + "INT64_MIN\n"); + goto failed; + } + if (!ASN1_INTEGER_get_int64(&val, aint)) { + fprintf(stderr, "FAIL: ASN_INTEGER_get_int64() failed with " + "INT64_MIN\n"); + goto failed; + } + if (val != INT64_MIN) { + fprintf(stderr, "FAIL: val != INT64_MIN\n"); + goto failed; + } + if (ASN1_INTEGER_get_uint64(&uval, aint)) { + fprintf(stderr, "FAIL: ASN_INTEGER_get_uint64() succeeded " + "with INT64_MIN\n"); + goto failed; + } + + if (!ASN1_INTEGER_set_int64(aint, INT64_MAX)) { + fprintf(stderr, "FAIL: ASN_INTEGER_set_int64() failed with " + "INT64_MAX\n"); + goto failed; + } + if (!ASN1_INTEGER_get_int64(&val, aint)) { + fprintf(stderr, "FAIL: ASN_INTEGER_get_int64() failed with " + "INT64_MAX\n"); + goto failed; + } + if (val != INT64_MAX) { + fprintf(stderr, "FAIL: ASN_INTEGER_get_int64() failed with " + "INT64_MAX\n"); + goto failed; + } + if (!ASN1_INTEGER_get_uint64(&uval, aint)) { + fprintf(stderr, "FAIL: ASN_INTEGER_get_uint64() failed with " + "INT64_MAX\n"); + goto failed; + } + if (uval != INT64_MAX) { + fprintf(stderr, "FAIL: uval != INT64_MAX\n"); + goto failed; + } + + failed = 0; + + failed: + ASN1_INTEGER_free(aint); + + return failed; +} + static int asn1_integer_cmp_test(void) { @@ -549,6 +650,7 @@ asn1_integer_test(void) } failed |= asn1_integer_cmp_test(); + failed |= asn1_integer_set_val_test(); return failed; } -- cgit v1.2.3-55-g6feb