Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 29708a5
Author: Richard Levitte <levitte@openssl.org>
Date:   Tue Jul 5 11:08:33 2022 +0200

    Prepare for 1.1.1q release

    Reviewed-by: Paul Dale <pauli@openssl.org>
    Release: yes

commit 95a17c0
Author: Richard Levitte <levitte@openssl.org>
Date:   Tue Jul 5 10:33:00 2022 +0200

    Update copyright year

    Reviewed-by: Paul Dale <pauli@openssl.org>
    Release: yes

commit 78ba51a
Author: Richard Levitte <levitte@openssl.org>
Date:   Tue Jul 5 10:25:00 2022 +0200

    Update CHANGES and NEWS for upcoming release 1.1.1q

    Reviewed-by: Paul Dale <pauli@openssl.org>
    Release: yes

commit 9131afd
Author: Alex Chernyakhovsky <achernya@google.com>
Date:   Thu Jun 16 12:02:37 2022 +1000

    AES OCB test vectors

    Add test vectors for AES OCB for x86 AES-NI multiple of 96 byte issue.

    Co-authored-by: Alejandro Sedeño <asedeno@google.com>
    Co-authored-by: David Benjamin <davidben@google.com>

    Reviewed-by: Paul Dale <pauli@openssl.org>
    Reviewed-by: Tomas Mraz <tomas@openssl.org>

commit 9199256
Author: Alex Chernyakhovsky <achernya@google.com>
Date:   Thu Jun 16 12:00:22 2022 +1000

    Fix AES OCB encrypt/decrypt for x86 AES-NI

    aesni_ocb_encrypt and aesni_ocb_decrypt operate by having a fast-path
    that performs operations on 6 16-byte blocks concurrently (the
    "grandloop") and then proceeds to handle the "short" tail (which can
    be anywhere from 0 to 5 blocks) that remain.

    As part of initialization, the assembly initializes $len to the true
    length, less 96 bytes and converts it to a pointer so that the $inp
    can be compared to it. Each iteration of "grandloop" checks to see if
    there's a full 96-byte chunk to process, and if so, continues. Once
    this has been exhausted, it falls through to "short", which handles
    the remaining zero to five blocks.

    Unfortunately, the jump at the end of "grandloop" had a fencepost
    error, doing a `jb` ("jump below") rather than `jbe` (jump below or
    equal). This should be `jbe`, as $inp is pointing to the *end* of the
    chunk currently being handled. If $inp == $len, that means that
    there's a whole 96-byte chunk waiting to be handled. If $inp > $len,
    then there's 5 or fewer 16-byte blocks left to be handled, and the
    fall-through is intended.

    The net effect of `jb` instead of `jbe` is that the last 16-byte block
    of the last 96-byte chunk was completely omitted. The contents of
    `out` in this position were never written to. Additionally, since
    those bytes were never processed, the authentication tag generated is
    also incorrect.

    The same fencepost error, and identical logic, exists in both
    aesni_ocb_encrypt and aesni_ocb_decrypt.

    This addresses CVE-2022-2097.

    Co-authored-by: Alejandro Sedeño <asedeno@google.com>
    Co-authored-by: David Benjamin <davidben@google.com>

    Reviewed-by: Paul Dale <pauli@openssl.org>
    Reviewed-by: Tomas Mraz <tomas@openssl.org>

commit 6495cab
Author: slontis <shane.lontis@oracle.com>
Date:   Fri Jul 1 13:47:11 2022 +1000

    Fix bn_gcd code to check return value when calling BN_one()

    BN_one() uses the expand function which calls malloc which may fail.
    All other places that reference BN_one() check the return value.

    The issue is triggered by a memory allocation failure.
    Detected by PR openssl#18355

    Reviewed-by: Tomas Mraz <tomas@openssl.org>
    Reviewed-by: Paul Dale <pauli@openssl.org>
    (Merged from openssl#18697)

    (cherry picked from commit 7fe7cc5)

commit 7a05fcb
Author: xkernel <xkernel.wang@foxmail.com>
Date:   Mon Jun 20 17:46:39 2022 +0800

    v3_sxnet: add a check for the return of i2s_ASN1_INTEGER()

    Reviewed-by: Matt Caswell <matt@openssl.org>
    Reviewed-by: Ben Kaduk <kaduk@mit.edu>
    (Merged from openssl#18608)

    (cherry picked from commit 9ef1f84)

commit a1d80ed
Author: Matt Caswell <matt@openssl.org>
Date:   Fri Jun 10 15:58:58 2022 +0100

    Fix range_should_be_prefix() to actually return the correct result

    range_should_be_prefix() was misidentifying whether an IP address range
    should in fact be represented as a prefix. This was due to a bug introduced
    in commit 42d7d7d which made this incorrect change:

    -    OPENSSL_assert(memcmp(min, max, length) <= 0);
    +    if (memcmp(min, max, length) <= 0)
    +        return -1;

    This error leads to incorrect DER being encoded/accepted.

    Reported by Theo Buehler (@botovq)

    Reviewed-by: Paul Dale <pauli@openssl.org>
    Reviewed-by: Tomas Mraz <tomas@openssl.org>
    (Merged from openssl#18524)

    (cherry picked from commit 30532e5)
    (cherry picked from commit 2c6550c)

commit 4c1cf6d
Author: Bernd Edlinger <bernd.edlinger@hotmail.de>
Date:   Fri Jun 17 10:25:24 2022 +0200

    Fix compile issues in test/v3ext.c with no-rfc3779

    There are no ASIdentifiers if OPENSSL_NO_RFC3779 is defined,
    therefore the test cannot be compiled.

    Reviewed-by: Matt Caswell <matt@openssl.org>
    Reviewed-by: Tomas Mraz <tomas@openssl.org>
    Reviewed-by: Paul Dale <pauli@openssl.org>
    (Merged from openssl#18634)

    (cherry picked from commit b76efe6)
    (cherry picked from commit 665ab12)

commit 8825732
Author: olszomal <Malgorzata.Olszowka@stunnel.org>
Date:   Fri Jun 17 15:01:11 2022 +0200

    SSL_get_current_cipher() and SSL_get_pending_cipher() return 'const SSL_CIPHER *'

    Fix the documentation.

    CLA: trivial

    Reviewed-by: Matt Caswell <matt@openssl.org>
    Reviewed-by: Todd Short <todd.short@me.com>
    Reviewed-by: Paul Dale <pauli@openssl.org>
    Reviewed-by: Tomas Mraz <tomas@openssl.org>
    (Merged from openssl#18599)

    (cherry picked from commit d842b6e)

commit 6c8879c
Author: Bernd Edlinger <bernd.edlinger@hotmail.de>
Date:   Wed Jun 22 17:05:55 2022 +0200

    Fix a memory leak in EC_GROUP_new_from_ecparameters

    This can be reproduced with my error injection patch.

    The test vector has been validated on the 1.1.1 branch
    but the issue is of course identical in all branches.

    $ ERROR_INJECT=1656112173 ../util/shlib_wrap.sh ./x509-test ./corpora/x509/fe543a8d7e09109a9a08114323eefec802ad79e2
        #0 0x7fb61945eeba in __sanitizer_print_stack_trace ../../../../gcc-trunk/libsanitizer/asan/asan_stack.cpp:87
        #1 0x402f84 in my_malloc fuzz/test-corpus.c:114
        #2 0x7fb619092430 in CRYPTO_zalloc crypto/mem.c:230
        #3 0x7fb618ef7561 in bn_expand_internal crypto/bn/bn_lib.c:280
        #4 0x7fb618ef7561 in bn_expand2 crypto/bn/bn_lib.c:304
        #5 0x7fb618ef819d in BN_bin2bn crypto/bn/bn_lib.c:454
        #6 0x7fb618e7aa13 in asn1_string_to_bn crypto/asn1/a_int.c:503
        #7 0x7fb618e7aa13 in ASN1_INTEGER_to_BN crypto/asn1/a_int.c:559
        #8 0x7fb618fd8e79 in EC_GROUP_new_from_ecparameters crypto/ec/ec_asn1.c:814
        #9 0x7fb618fd98e8 in EC_GROUP_new_from_ecpkparameters crypto/ec/ec_asn1.c:935
        #10 0x7fb618fd9aec in d2i_ECPKParameters crypto/ec/ec_asn1.c:966
        #11 0x7fb618fdace9 in d2i_ECParameters crypto/ec/ec_asn1.c:1184
        #12 0x7fb618fd1fc7 in eckey_type2param crypto/ec/ec_ameth.c:119
        openssl#13 0x7fb618fd57b4 in eckey_pub_decode crypto/ec/ec_ameth.c:165
        openssl#14 0x7fb6191a9c62 in x509_pubkey_decode crypto/x509/x_pubkey.c:124
        openssl#15 0x7fb6191a9e42 in pubkey_cb crypto/x509/x_pubkey.c:46
        openssl#16 0x7fb618eac032 in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:432
        openssl#17 0x7fb618eacaf5 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:643
        openssl#18 0x7fb618ead288 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:518
        openssl#19 0x7fb618eab9ce in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:382
        openssl#20 0x7fb618eacaf5 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:643
        openssl#21 0x7fb618ead288 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:518
        openssl#22 0x7fb618eab9ce in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:382
        openssl#23 0x7fb618eadd1f in ASN1_item_ex_d2i crypto/asn1/tasn_dec.c:124
        openssl#24 0x7fb618eade35 in ASN1_item_d2i crypto/asn1/tasn_dec.c:114
        openssl#25 0x40310c in FuzzerTestOneInput fuzz/x509.c:33
        openssl#26 0x402afb in testfile fuzz/test-corpus.c:182
        openssl#27 0x402656 in main fuzz/test-corpus.c:226
        openssl#28 0x7fb618551f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)
        openssl#29 0x402756  (/home/ed/OPC/openssl/fuzz/x509-test+0x402756)

    =================================================================
    ==12221==ERROR: LeakSanitizer: detected memory leaks

    Direct leak of 24 byte(s) in 1 object(s) allocated from:
        #0 0x7fb61945309f in __interceptor_malloc ../../../../gcc-trunk/libsanitizer/asan/asan_malloc_linux.cpp:69
        #1 0x7fb619092430 in CRYPTO_zalloc crypto/mem.c:230
        #2 0x7fb618ef5f11 in BN_new crypto/bn/bn_lib.c:246
        #3 0x7fb618ef82f4 in BN_bin2bn crypto/bn/bn_lib.c:440
        #4 0x7fb618fd8933 in EC_GROUP_new_from_ecparameters crypto/ec/ec_asn1.c:618
        #5 0x7fb618fd98e8 in EC_GROUP_new_from_ecpkparameters crypto/ec/ec_asn1.c:935
        #6 0x7fb618fd9aec in d2i_ECPKParameters crypto/ec/ec_asn1.c:966
        #7 0x7fb618fdace9 in d2i_ECParameters crypto/ec/ec_asn1.c:1184
        #8 0x7fb618fd1fc7 in eckey_type2param crypto/ec/ec_ameth.c:119
        #9 0x7fb618fd57b4 in eckey_pub_decode crypto/ec/ec_ameth.c:165
        #10 0x7fb6191a9c62 in x509_pubkey_decode crypto/x509/x_pubkey.c:124
        #11 0x7fb6191a9e42 in pubkey_cb crypto/x509/x_pubkey.c:46
        #12 0x7fb618eac032 in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:432
        openssl#13 0x7fb618eacaf5 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:643
        openssl#14 0x7fb618ead288 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:518
        openssl#15 0x7fb618eab9ce in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:382
        openssl#16 0x7fb618eacaf5 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:643
        openssl#17 0x7fb618ead288 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:518
        openssl#18 0x7fb618eab9ce in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:382
        openssl#19 0x7fb618eadd1f in ASN1_item_ex_d2i crypto/asn1/tasn_dec.c:124
        openssl#20 0x7fb618eade35 in ASN1_item_d2i crypto/asn1/tasn_dec.c:114
        openssl#21 0x40310c in FuzzerTestOneInput fuzz/x509.c:33
        openssl#22 0x402afb in testfile fuzz/test-corpus.c:182
        openssl#23 0x402656 in main fuzz/test-corpus.c:226
        openssl#24 0x7fb618551f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)

    Indirect leak of 56 byte(s) in 1 object(s) allocated from:
        #0 0x7fb61945309f in __interceptor_malloc ../../../../gcc-trunk/libsanitizer/asan/asan_malloc_linux.cpp:69
        #1 0x7fb619092430 in CRYPTO_zalloc crypto/mem.c:230
        #2 0x7fb618ef7561 in bn_expand_internal crypto/bn/bn_lib.c:280
        #3 0x7fb618ef7561 in bn_expand2 crypto/bn/bn_lib.c:304
        #4 0x7fb618ef819d in BN_bin2bn crypto/bn/bn_lib.c:454
        #5 0x7fb618fd8933 in EC_GROUP_new_from_ecparameters crypto/ec/ec_asn1.c:618
        #6 0x7fb618fd98e8 in EC_GROUP_new_from_ecpkparameters crypto/ec/ec_asn1.c:935
        #7 0x7fb618fd9aec in d2i_ECPKParameters crypto/ec/ec_asn1.c:966
        #8 0x7fb618fdace9 in d2i_ECParameters crypto/ec/ec_asn1.c:1184
        #9 0x7fb618fd1fc7 in eckey_type2param crypto/ec/ec_ameth.c:119
        #10 0x7fb618fd57b4 in eckey_pub_decode crypto/ec/ec_ameth.c:165
        #11 0x7fb6191a9c62 in x509_pubkey_decode crypto/x509/x_pubkey.c:124
        #12 0x7fb6191a9e42 in pubkey_cb crypto/x509/x_pubkey.c:46
        openssl#13 0x7fb618eac032 in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:432
        openssl#14 0x7fb618eacaf5 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:643
        openssl#15 0x7fb618ead288 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:518
        openssl#16 0x7fb618eab9ce in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:382
        openssl#17 0x7fb618eacaf5 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:643
        openssl#18 0x7fb618ead288 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:518
        openssl#19 0x7fb618eab9ce in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:382
        openssl#20 0x7fb618eadd1f in ASN1_item_ex_d2i crypto/asn1/tasn_dec.c:124
        openssl#21 0x7fb618eade35 in ASN1_item_d2i crypto/asn1/tasn_dec.c:114
        openssl#22 0x40310c in FuzzerTestOneInput fuzz/x509.c:33
        openssl#23 0x402afb in testfile fuzz/test-corpus.c:182
        openssl#24 0x402656 in main fuzz/test-corpus.c:226
        openssl#25 0x7fb618551f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)

    SUMMARY: AddressSanitizer: 80 byte(s) leaked in 2 allocation(s).

    Reviewed-by: Tomas Mraz <tomas@openssl.org>
    Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
    (Merged from openssl#18632)

commit 7f77ecd
Author: Matt Caswell <matt@openssl.org>
Date:   Tue Jun 21 14:39:48 2022 +0100

    Prepare for 1.1.1q-dev

    Reviewed-by: Richard Levitte <levitte@openssl.org>
    Release: yes

commit 8aaca20
Author: Matt Caswell <matt@openssl.org>
Date:   Tue Jun 21 14:39:39 2022 +0100

    Prepare for 1.1.1p release

    Reviewed-by: Richard Levitte <levitte@openssl.org>
    Release: yes

commit a3fc812
Author: Matt Caswell <matt@openssl.org>
Date:   Tue Jun 21 14:07:32 2022 +0100

    Update copyright year

    Reviewed-by: Richard Levitte <levitte@openssl.org>
    Release: yes

commit 51e0652
Author: Matt Caswell <matt@openssl.org>
Date:   Mon Jun 20 14:14:20 2022 +0100

    Update CHANGES and NEWS for new release

    Reviewed-by: Tomas Mraz <tomas@openssl.org>
    Release: yes

commit 9639817
Author: Daniel Fiala <daniel@openssl.org>
Date:   Sun May 29 20:11:24 2022 +0200

    Fix file operations in c_rehash.

    CVE-2022-2068

    Reviewed-by: Matt Caswell <matt@openssl.org>
    Reviewed-by: Richard Levitte <levitte@openssl.org>

commit 20af01d
Author: Fraser Tweedale <ftweedal@redhat.com>
Date:   Wed Jun 15 10:50:57 2022 +1000

    Fix documentation of BIO_FLAGS_BASE64_NO_NL

    Commit 8bfb750 updated
    `BIO_f_base64(3)` to improve the documentation of the
    `BIO_FLAGS_BASE64_NO_NL` flag.  In particular, the updated text
    states that when this flag is used, all newlines in the input are
    ignored.  This is incorrect, as the following program proves:

    ```c

    unsigned char *in_buf =
        "IlRoZSBxdWljayBicm93biBmb3gganVt\ncHMgb3ZlciBhIGxhenkgZG9nLiI=\n";

    int main(int argc, char **argv) {
        BIO *b64 = BIO_new(BIO_f_base64());
        if (b64 == NULL) return 1;
        BIO_set_flags(b64, BIO_get_flags(b64) | BIO_FLAGS_BASE64_NO_NL);
        int in_len = strlen(in_buf);
        BIO *in = BIO_new_mem_buf(in_buf, in_len);
        if (in == NULL) return 2;
        in = BIO_push(b64, in);
        unsigned char *out_buf = calloc(in_len, sizeof(unsigned char));
        if (out_buf == NULL) return 3;
        size_t out_len;
        int r = BIO_read_ex(in, out_buf, in_len, &out_len);
        printf("rv = %d\n", r);
        printf("decoded = %s\n", out_buf);
        return 0;
    }
    ```

    Update the text of `BIO_f_base64(3)` to clarify that when the flag
    is set, the data must be all on one line (with or without a trailing
    newline character).

    Signed-off-by: Fraser Tweedale <ftweedal@redhat.com>

    Reviewed-by: Paul Dale <pauli@openssl.org>
    Reviewed-by: Tomas Mraz <tomas@openssl.org>
    (Merged from openssl#18568)

    (cherry picked from commit 0edcbac)

commit 8438d3a
Author: Tomas Mraz <tomas@openssl.org>
Date:   Thu Jun 9 16:20:05 2022 +0200

    Add an extra reduction step to RSAZ mod_exp implementations

    Inspired by BoringSSL fix by David Benjamin.

    Reviewed-by: Matt Caswell <matt@openssl.org>
    Reviewed-by: Paul Dale <pauli@openssl.org>
    (Merged from openssl#18511)

commit 0ed27fb
Author: Tomas Mraz <tomas@openssl.org>
Date:   Thu Jun 9 12:34:55 2022 +0200

    Always end BN_mod_exp_mont_consttime with normal Montgomery reduction.

    This partially fixes a bug where, on x86_64, BN_mod_exp_mont_consttime
    would sometimes return m, the modulus, when it should have returned
    zero. Thanks to Guido Vranken for reporting it. It is only a partial fix
    because the same bug also exists in the "rsaz" codepath.

    The bug only affects zero outputs (with non-zero inputs), so we believe
    it has no security impact on our cryptographic functions.

    The fx is to delete lowercase bn_from_montgomery altogether, and have the
    mont5 path use the same BN_from_montgomery ending as the non-mont5 path.
    This only impacts the final step of the whole exponentiation and has no
    measurable perf impact.

    See the original BoringSSL commit
    https://boringssl.googlesource.com/boringssl/+/13c9d5c69d04485a7a8840c12185c832026c8315
    for further analysis.

    Original-author: David Benjamin <davidben@google.com>

    Reviewed-by: Matt Caswell <matt@openssl.org>
    Reviewed-by: Paul Dale <pauli@openssl.org>
    (Merged from openssl#18511)

commit 8f07881
Author: Matt Caswell <matt@openssl.org>
Date:   Thu Jun 9 16:57:30 2022 +0100

    Fix a crash in X509v3_asid_subset()

    If the asnum or rdi fields are NULL and the ASIdentifiers are otherwise
    subsets then this will result in a crash. Of note is that rdi will usually
    be NULL.

    Reported by Theo Buehler (@botovq)

    Reviewed-by: Tomas Mraz <tomas@openssl.org>
    Reviewed-by: Paul Yang <kaishen.yy@antfin.com>
    Reviewed-by: Todd Short <todd.short@me.com>
    (Merged from openssl#18514)

    (cherry picked from commit 01fc9b6)

commit ab7d056
Author: Tomas Mraz <tomas@openssl.org>
Date:   Thu Jun 2 18:12:05 2022 +0200

    Update further expiring certificates that affect tests

    Namely the smime certificates used in test_cms
    will expire soon and affect tests.

    Fixes openssl#15179

    Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
    Reviewed-by: Paul Dale <pauli@openssl.org>
    (Merged from openssl#18481)

commit 3bd9765
Author: Tomas Mraz <tomas@openssl.org>
Date:   Tue Mar 29 13:31:34 2022 +0200

    Fix strict client chain check with TLS-1.3

    When TLS-1.3 is used and the server does not send any CA names
    the ca_dn will be NULL. sk_X509_NAME_num() returns -1 on null
    argument.

    Reviewed-by: Todd Short <todd.short@me.com>
    Reviewed-by: Matt Caswell <matt@openssl.org>
    (Merged from openssl#17986)

    (cherry picked from commit 89dd854)

commit b7ce611
Author: Tomas Mraz <tomas@openssl.org>
Date:   Wed Jun 1 13:06:46 2022 +0200

    ct_test.c: Update the epoch time

    Reviewed-by: Matt Caswell <matt@openssl.org>
    Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
    (Merged from openssl#18446)

commit 73db5d8
Author: Tomas Mraz <tomas@openssl.org>
Date:   Wed Jun 1 12:47:44 2022 +0200

    Update expired SCT certificates

    Reviewed-by: Matt Caswell <matt@openssl.org>
    Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
    (Merged from openssl#18446)

commit 8754fa5
Author: Bernd Edlinger <bernd.edlinger@hotmail.de>
Date:   Sat May 21 07:50:46 2022 +0200

    Fix a memory leak in crl_set_issuers

    This can be reproduced with my error injection patch.

    The test vector has been validated on the 1.1.1 branch
    but the issue is of course identical in all branches.

    $ ERROR_INJECT=1653520461 ../util/shlib_wrap.sh ./cms-test ./corpora/cms/3eff1d2f1232bd66d5635db2c3f9e7f23830dfd1
    log file: cms-3eff1d2f1232bd66d5635db2c3f9e7f23830dfd1-32454-test.out
    ERROR_INJECT=1653520461
        #0 0x7fd5d8b8eeba in __sanitizer_print_stack_trace ../../../../gcc-trunk/libsanitizer/asan/asan_stack.cpp:87
        #1 0x402fc4 in my_realloc fuzz/test-corpus.c:129
        #2 0x7fd5d8893c49 in sk_reserve crypto/stack/stack.c:198
        #3 0x7fd5d8893c49 in OPENSSL_sk_insert crypto/stack/stack.c:242
        #4 0x7fd5d88d6d7f in sk_GENERAL_NAMES_push include/openssl/x509v3.h:168
        #5 0x7fd5d88d6d7f in crl_set_issuers crypto/x509/x_crl.c:111
        #6 0x7fd5d88d6d7f in crl_cb crypto/x509/x_crl.c:246
        #7 0x7fd5d85dc032 in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:432
        #8 0x7fd5d85dcaf5 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:643
        #9 0x7fd5d85dd288 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:518
        #10 0x7fd5d85db2b5 in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:259
        #11 0x7fd5d85dc813 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:611
        #12 0x7fd5d85dd288 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:518
        openssl#13 0x7fd5d85db9ce in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:382
        openssl#14 0x7fd5d85dca28 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:633
        openssl#15 0x7fd5d85dd288 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:518
        openssl#16 0x7fd5d85db9ce in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:382
        openssl#17 0x7fd5d85dcaf5 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:643
        openssl#18 0x7fd5d85dd7d3 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:494
        openssl#19 0x7fd5d85db9ce in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:382
        openssl#20 0x7fd5d85ddd1f in ASN1_item_ex_d2i crypto/asn1/tasn_dec.c:124
        openssl#21 0x7fd5d85dde35 in ASN1_item_d2i crypto/asn1/tasn_dec.c:114
        openssl#22 0x7fd5d85a77e0 in ASN1_item_d2i_bio crypto/asn1/a_d2i_fp.c:69
        openssl#23 0x402845 in FuzzerTestOneInput fuzz/cms.c:43
        openssl#24 0x402bbb in testfile fuzz/test-corpus.c:182
        openssl#25 0x402626 in main fuzz/test-corpus.c:226
        openssl#26 0x7fd5d7c81f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)
        openssl#27 0x402706  (/home/ed/OPC/openssl/fuzz/cms-test+0x402706)

    =================================================================
    ==29625==ERROR: LeakSanitizer: detected memory leaks

    Direct leak of 32 byte(s) in 1 object(s) allocated from:
        #0 0x7fd5d8b8309f in __interceptor_malloc ../../../../gcc-trunk/libsanitizer/asan/asan_malloc_linux.cpp:69
        #1 0x7fd5d87c2430 in CRYPTO_zalloc crypto/mem.c:230
        #2 0x7fd5d889501f in OPENSSL_sk_new_reserve crypto/stack/stack.c:209
        #3 0x7fd5d85dcbc3 in sk_ASN1_VALUE_new_null include/openssl/asn1t.h:928
        #4 0x7fd5d85dcbc3 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:577
        #5 0x7fd5d85dd288 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:518
        #6 0x7fd5d85db104 in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:178
        #7 0x7fd5d85ddd1f in ASN1_item_ex_d2i crypto/asn1/tasn_dec.c:124
        #8 0x7fd5d85dde35 in ASN1_item_d2i crypto/asn1/tasn_dec.c:114
        #9 0x7fd5d88f86d9 in X509V3_EXT_d2i crypto/x509v3/v3_lib.c:142
        #10 0x7fd5d88d6d3c in crl_set_issuers crypto/x509/x_crl.c:97
        #11 0x7fd5d88d6d3c in crl_cb crypto/x509/x_crl.c:246
        #12 0x7fd5d85dc032 in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:432
        openssl#13 0x7fd5d85dcaf5 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:643
        openssl#14 0x7fd5d85dd288 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:518
        openssl#15 0x7fd5d85db2b5 in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:259
        openssl#16 0x7fd5d85dc813 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:611
        openssl#17 0x7fd5d85dd288 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:518
        openssl#18 0x7fd5d85db9ce in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:382
        openssl#19 0x7fd5d85dca28 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:633
        openssl#20 0x7fd5d85dd288 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:518
        openssl#21 0x7fd5d85db9ce in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:382
        openssl#22 0x7fd5d85dcaf5 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:643
        openssl#23 0x7fd5d85dd7d3 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:494
        openssl#24 0x7fd5d85db9ce in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:382
        openssl#25 0x7fd5d85ddd1f in ASN1_item_ex_d2i crypto/asn1/tasn_dec.c:124
        openssl#26 0x7fd5d85dde35 in ASN1_item_d2i crypto/asn1/tasn_dec.c:114
        openssl#27 0x7fd5d85a77e0 in ASN1_item_d2i_bio crypto/asn1/a_d2i_fp.c:69
        openssl#28 0x402845 in FuzzerTestOneInput fuzz/cms.c:43
        openssl#29 0x402bbb in testfile fuzz/test-corpus.c:182
        openssl#30 0x402626 in main fuzz/test-corpus.c:226
        openssl#31 0x7fd5d7c81f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)

    SUMMARY: AddressSanitizer: 32 byte(s) leaked in 1 allocation(s).

    Reviewed-by: Paul Dale <pauli@openssl.org>
    Reviewed-by: Tomas Mraz <tomas@openssl.org>
    (Merged from openssl#18391)

    (cherry picked from commit e9007e0)

commit 4a28f84
Author: Bernd Edlinger <bernd.edlinger@hotmail.de>
Date:   Sun May 22 20:12:56 2022 +0200

    Fix a crash in ssl_security_cert_chain

    Prior to the crash there is an out of memory error
    in X509_verify_cert which makes the chain NULL or
    empty.  The error is ignored by ssl_add_cert_chain,
    and ssl_security_cert_chain crashes due to the
    unchecked null pointer.

    This is reproducible with my error injection patch.

    The test vector has been validated on the 1.1.1 branch
    but the issue is of course identical in all branches.

    $ ERROR_INJECT=1652848273 ../util/shlib_wrap.sh ./server-test ./corpora/server/47c8e933c4ec66fa3c309422283dfe0f31aafae8# ./corpora/server/47c8e933c4ec66fa3c309422283dfe0f31aafae8
        #0 0x7f3a8f766eba in __sanitizer_print_stack_trace ../../../../gcc-trunk/libsanitizer/asan/asan_stack.cpp:87
        #1 0x403ba4 in my_malloc fuzz/test-corpus.c:114
        #2 0x7f3a8f39a430 in CRYPTO_zalloc crypto/mem.c:230
        #3 0x7f3a8f46bd3b in sk_reserve crypto/stack/stack.c:180
        #4 0x7f3a8f46bd3b in OPENSSL_sk_insert crypto/stack/stack.c:242
        #5 0x7f3a8f4a4fd8 in sk_X509_push include/openssl/x509.h:99
        #6 0x7f3a8f4a4fd8 in X509_verify_cert crypto/x509/x509_vfy.c:286
        #7 0x7f3a8fed726e in ssl_add_cert_chain ssl/statem/statem_lib.c:959
        #8 0x7f3a8fed726e in ssl3_output_cert_chain ssl/statem/statem_lib.c:1015
        #9 0x7f3a8fee1c50 in tls_construct_server_certificate ssl/statem/statem_srvr.c:3812
        #10 0x7f3a8feb8b0a in write_state_machine ssl/statem/statem.c:843
        #11 0x7f3a8feb8b0a in state_machine ssl/statem/statem.c:443
        #12 0x7f3a8fe84b3f in SSL_do_handshake ssl/ssl_lib.c:3718
        openssl#13 0x403202 in FuzzerTestOneInput fuzz/server.c:740
        openssl#14 0x40371b in testfile fuzz/test-corpus.c:182
        openssl#15 0x402856 in main fuzz/test-corpus.c:226
        openssl#16 0x7f3a8e859f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)
        openssl#17 0x402936  (/home/ed/OPC/openssl/fuzz/server-test+0x402936)

    AddressSanitizer:DEADLYSIGNAL
    =================================================================
    ==8400==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000158 (pc 0x7f3a8f4d822f bp 0x7ffc39b76190 sp 0x7ffc39b760a0 T0)
    ==8400==The signal is caused by a READ memory access.
    ==8400==Hint: address points to the zero page.
        #0 0x7f3a8f4d822f in x509v3_cache_extensions crypto/x509v3/v3_purp.c:386
        #1 0x7f3a8f4d9d3a in X509_check_purpose crypto/x509v3/v3_purp.c:84
        #2 0x7f3a8f4da02a in X509_get_extension_flags crypto/x509v3/v3_purp.c:921
        #3 0x7f3a8feff7d2 in ssl_security_cert_sig ssl/t1_lib.c:2518
        #4 0x7f3a8feff7d2 in ssl_security_cert ssl/t1_lib.c:2542
        #5 0x7f3a8feffa03 in ssl_security_cert_chain ssl/t1_lib.c:2562
        #6 0x7f3a8fed728d in ssl_add_cert_chain ssl/statem/statem_lib.c:963
        #7 0x7f3a8fed728d in ssl3_output_cert_chain ssl/statem/statem_lib.c:1015
        #8 0x7f3a8fee1c50 in tls_construct_server_certificate ssl/statem/statem_srvr.c:3812
        #9 0x7f3a8feb8b0a in write_state_machine ssl/statem/statem.c:843
        #10 0x7f3a8feb8b0a in state_machine ssl/statem/statem.c:443
        #11 0x7f3a8fe84b3f in SSL_do_handshake ssl/ssl_lib.c:3718
        #12 0x403202 in FuzzerTestOneInput fuzz/server.c:740
        openssl#13 0x40371b in testfile fuzz/test-corpus.c:182
        openssl#14 0x402856 in main fuzz/test-corpus.c:226
        openssl#15 0x7f3a8e859f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)
        openssl#16 0x402936  (/home/ed/OPC/openssl/fuzz/server-test+0x402936)

    AddressSanitizer can not provide additional info.
    SUMMARY: AddressSanitizer: SEGV crypto/x509v3/v3_purp.c:386 in x509v3_cache_extensions
    ==8400==ABORTING

    Reviewed-by: Tomas Mraz <tomas@openssl.org>
    Reviewed-by: Matt Caswell <matt@openssl.org>
    (Merged from openssl#18376)

    (cherry picked from commit dc0ef29)

commit 59b8eca
Author: Bernd Edlinger <bernd.edlinger@hotmail.de>
Date:   Sat May 21 15:41:46 2022 +0200

    Fix a memory leak in X509_issuer_and_serial_hash

    This is reproducible with my error injection patch:

    $ ERROR_INJECT=1653267699 ../util/shlib_wrap.sh ./x509-test ./corpora/x509/5f4034ae85d6587dcad4da3e812e80f3d312894d
    ERROR_INJECT=1653267699
        #0 0x7fd485a6ad4f in __sanitizer_print_stack_trace ../../../../src/libsanitizer/asan/asan_stack.cc:36
        #1 0x55c12d268724 in my_malloc fuzz/test-corpus.c:114
        #2 0x7fd484f51a75 in CRYPTO_zalloc crypto/mem.c:230
        #3 0x7fd484ed778d in EVP_DigestInit_ex crypto/evp/digest.c:139
        #4 0x7fd4850a9849 in X509_issuer_and_serial_hash crypto/x509/x509_cmp.c:44
        #5 0x55c12d268951 in FuzzerTestOneInput fuzz/x509.c:44
        #6 0x55c12d268239 in testfile fuzz/test-corpus.c:182
        #7 0x55c12d267c7f in main fuzz/test-corpus.c:226
        #8 0x7fd483a42082 in __libc_start_main ../csu/libc-start.c:308
        #9 0x55c12d267e5d in _start (/home/ed/OPCToolboxV5/Source/Core/OpenSSL/openssl/fuzz/x509-test+0x3e5d)

    =================================================================
    ==1058475==ERROR: LeakSanitizer: detected memory leaks

    Direct leak of 268 byte(s) in 1 object(s) allocated from:
        #0 0x7fd485a5dc3e in __interceptor_realloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:163
        #1 0x7fd484d2eb9b in BUF_MEM_grow crypto/buffer/buffer.c:97
        #2 0x7fd4850b2913 in X509_NAME_oneline crypto/x509/x509_obj.c:43
        #3 0x7fd4850a982f in X509_issuer_and_serial_hash crypto/x509/x509_cmp.c:41
        #4 0x55c12d268951 in FuzzerTestOneInput fuzz/x509.c:44
        #5 0x55c12d268239 in testfile fuzz/test-corpus.c:182
        #6 0x55c12d267c7f in main fuzz/test-corpus.c:226
        #7 0x7fd483a42082 in __libc_start_main ../csu/libc-start.c:308

    SUMMARY: AddressSanitizer: 268 byte(s) leaked in 1 allocation(s).

    Reviewed-by: Tomas Mraz <tomas@openssl.org>
    Reviewed-by: Matt Caswell <matt@openssl.org>
    (Merged from openssl#18370)

commit e4b84b7
Author: Bernd Edlinger <bernd.edlinger@hotmail.de>
Date:   Fri May 20 16:54:41 2022 +0200

    Fix undefined behaviour in EC_GROUP_new_from_ecparameters

    This happens for instance with
    fuzz/corpora/asn1/65cf44e85614c62f10cf3b7a7184c26293a19e4a
    and causes the OPENSSL_malloc below to choke on the
    zero length allocation request.

    Reviewed-by: Matt Caswell <matt@openssl.org>
    Reviewed-by: Tomas Mraz <tomas@openssl.org>
    (Merged from openssl#18363)

commit 8e1ece2
Author: Bernd Edlinger <bernd.edlinger@hotmail.de>
Date:   Fri May 20 16:15:44 2022 +0200

    Fix a memory leak in ec_key_simple_oct2priv

    This is reproducible with my error injection patch:

    $ ERROR_INJECT=1652710284 ../util/shlib_wrap.sh ./server-test ./corpora/server/4e48da8aecce6b9b58e8e4dbbf0523e6d2dd56dc
    140587884632000:error:03078041:bignum routines:bn_expand_internal:malloc failure:crypto/bn/bn_lib.c:282:
    140587884632000:error:10103003:elliptic curve routines:ec_key_simple_oct2priv:BN lib:crypto/ec/ec_key.c:662:
    140587884632000:error:100DE08E:elliptic curve routines:old_ec_priv_decode:decode error:crypto/ec/ec_ameth.c:464:
    140587884632000:error:0D0680A8:asn1 encoding routines:asn1_check_tlen:wrong tag:crypto/asn1/tasn_dec.c:1149:
    140587884632000:error:0D07803A:asn1 encoding routines:asn1_item_embed_d2i:nested asn1 error:crypto/asn1/tasn_dec.c:309:Type=X509_ALGOR
    140587884632000:error:0D08303A:asn1 encoding routines:asn1_template_noexp_d2i:nested asn1 error:crypto/asn1/tasn_dec.c:646:Field=pkeyalg, Type=PKCS8_PRIV_KEY_INFO
    140587884632000:error:0907B00D:PEM routines:PEM_read_bio_PrivateKey:ASN1 lib:crypto/pem/pem_pkey.c:88:

    =================================================================
    ==19676==ERROR: LeakSanitizer: detected memory leaks

    Direct leak of 24 byte(s) in 1 object(s) allocated from:
        #0 0x7fdd2a6bb09f in __interceptor_malloc ../../../../gcc-trunk/libsanitizer/asan/asan_malloc_linux.cpp:69
        #1 0x7fdd2a2fa430 in CRYPTO_zalloc crypto/mem.c:230
        #2 0x7fdd2a15df11 in BN_new crypto/bn/bn_lib.c:246
        #3 0x7fdd2a15df88 in BN_secure_new crypto/bn/bn_lib.c:257
        #4 0x7fdd2a247390 in ec_key_simple_oct2priv crypto/ec/ec_key.c:655
        #5 0x7fdd2a241fc5 in d2i_ECPrivateKey crypto/ec/ec_asn1.c:1030
        #6 0x7fdd2a23dac5 in old_ec_priv_decode crypto/ec/ec_ameth.c:463
        #7 0x7fdd2a109db7 in d2i_PrivateKey crypto/asn1/d2i_pr.c:46
        #8 0x7fdd2a33ab16 in PEM_read_bio_PrivateKey crypto/pem/pem_pkey.c:84
        #9 0x7fdd2a3330b6 in PEM_read_bio_ECPrivateKey crypto/pem/pem_all.c:151
        #10 0x402dba in FuzzerTestOneInput fuzz/server.c:592
        #11 0x40370b in testfile fuzz/test-corpus.c:182
        #12 0x402846 in main fuzz/test-corpus.c:226
        openssl#13 0x7fdd297b9f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)

    SUMMARY: AddressSanitizer: 24 byte(s) leaked in 1 allocation(s).

    Reviewed-by: Tomas Mraz <tomas@openssl.org>
    Reviewed-by: Matt Caswell <matt@openssl.org>
    (Merged from openssl#18361)

commit 8e60f41
Author: Bernd Edlinger <bernd.edlinger@hotmail.de>
Date:   Fri May 20 08:02:47 2022 +0200

    Fix a crash in asn1_item_embed_new

    This happens usually if an template object is created
    and there is an out of memory error before the ASN1_OP_NEW_POST
    method is called, but asn1_item_embed_free calls now the
    ASN1_OP_FREE_POST which may crash because the object is not
    properly initialized.  Apparently that is only an issue with
    the ASN1_OP_FREE_POST handling of crypot/x509/x_crl.c, which
    ought to be tolerant to incomplete initialized objects.

    The error can be reproduced with the reproducible error injection patch:

    $ ERROR_INJECT=1652890550 ../util/shlib_wrap.sh ./asn1-test ./corpora/asn1/0ff17293911f54d1538b9896563a4048d67d9ee4
        #0 0x7faae9dbeeba in __sanitizer_print_stack_trace ../../../../gcc-trunk/libsanitizer/asan/asan_stack.cpp:87
        #1 0x408dc4 in my_malloc fuzz/test-corpus.c:114
        #2 0x7faae99f2430 in CRYPTO_zalloc crypto/mem.c:230
        #3 0x7faae97f09e5 in ASN1_STRING_type_new crypto/asn1/asn1_lib.c:341
        #4 0x7faae98118f7 in asn1_primitive_new crypto/asn1/tasn_new.c:318
        #5 0x7faae9812401 in asn1_item_embed_new crypto/asn1/tasn_new.c:78
        #6 0x7faae9812401 in asn1_template_new crypto/asn1/tasn_new.c:240
        #7 0x7faae9812315 in asn1_item_embed_new crypto/asn1/tasn_new.c:137
        #8 0x7faae9812315 in asn1_template_new crypto/asn1/tasn_new.c:240
        #9 0x7faae9812a54 in asn1_item_embed_new crypto/asn1/tasn_new.c:137
        #10 0x7faae9812a54 in ASN1_item_ex_new crypto/asn1/tasn_new.c:39
        #11 0x7faae980be51 in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:325
        #12 0x7faae980c813 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:611
        openssl#13 0x7faae980d288 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:518
        openssl#14 0x7faae980b9ce in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:382
        openssl#15 0x7faae980caf5 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:643
        openssl#16 0x7faae980d7d3 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:494
        openssl#17 0x7faae980b9ce in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:382
        openssl#18 0x7faae980dd1f in ASN1_item_ex_d2i crypto/asn1/tasn_dec.c:124
        openssl#19 0x7faae980de35 in ASN1_item_d2i crypto/asn1/tasn_dec.c:114
        openssl#20 0x40712c in FuzzerTestOneInput fuzz/asn1.c:301
        openssl#21 0x40893b in testfile fuzz/test-corpus.c:182
        openssl#22 0x406b86 in main fuzz/test-corpus.c:226
        openssl#23 0x7faae8eb1f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)

    AddressSanitizer:DEADLYSIGNAL
    =================================================================
    ==1194==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000010 (pc 0x7faae9b0625f bp 0x7fffffe41a00 sp 0x7fffffe41920 T0)
    ==1194==The signal is caused by a READ memory access.
    ==1194==Hint: address points to the zero page.
        #0 0x7faae9b0625f in crl_cb crypto/x509/x_crl.c:258
        #1 0x7faae9811255 in asn1_item_embed_free crypto/asn1/tasn_fre.c:113
        #2 0x7faae9812a65 in asn1_item_embed_new crypto/asn1/tasn_new.c:150
        #3 0x7faae9812a65 in ASN1_item_ex_new crypto/asn1/tasn_new.c:39
        #4 0x7faae980be51 in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:325
        #5 0x7faae980c813 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:611
        #6 0x7faae980d288 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:518
        #7 0x7faae980b9ce in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:382
        #8 0x7faae980caf5 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:643
        #9 0x7faae980d7d3 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:494
        #10 0x7faae980b9ce in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:382
        #11 0x7faae980dd1f in ASN1_item_ex_d2i crypto/asn1/tasn_dec.c:124
        #12 0x7faae980de35 in ASN1_item_d2i crypto/asn1/tasn_dec.c:114
        openssl#13 0x40712c in FuzzerTestOneInput fuzz/asn1.c:301
        openssl#14 0x40893b in testfile fuzz/test-corpus.c:182
        openssl#15 0x406b86 in main fuzz/test-corpus.c:226
        openssl#16 0x7faae8eb1f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)

    AddressSanitizer can not provide additional info.
    SUMMARY: AddressSanitizer: SEGV crypto/x509/x_crl.c:258 in crl_cb
    ==1194==ABORTING

    Reviewed-by: Matt Caswell <matt@openssl.org>
    Reviewed-by: Tomas Mraz <tomas@openssl.org>
    (Merged from openssl#18360)

    (cherry picked from commit 557825a)

commit 17519e2
Author: Bernd Edlinger <bernd.edlinger@hotmail.de>
Date:   Thu May 19 15:50:28 2022 +0200

    Backport a missing bug-fix from master

    This is a backport of the following commit from master:

    commit 61b0fea
    Author: Matt Caswell <matt@openssl.org>
    Date:   Thu Nov 19 13:58:21 2020 +0000

        Don't Overflow when printing Thawte Strong Extranet Version

        When printing human readable info on the Thawte Strong Extranet extension
        the version number could overflow if the version number == LONG_MAX. This
        is undefined behaviour.

        Issue found by OSSFuzz.

        Reviewed-by: Ben Kaduk <kaduk@mit.edu>
        (Merged from openssl#13452)

    Reviewed-by: Matt Caswell <matt@openssl.org>
    Reviewed-by: Tomas Mraz <tomas@openssl.org>
    (Merged from openssl#18347)

commit 03ba56f
Author: Bernd Edlinger <bernd.edlinger@hotmail.de>
Date:   Thu May 19 10:59:25 2022 +0200

    Backport some fuzzing data files from master

    This is a backport of the following commit from master:

    commit 415e6ac
    Author: Tavis Ormandy <taviso@gmail.com>
    Date:   Tue Sep 21 15:48:27 2021 -0700

        increase x509 code coverage metrics

        Reviewed-by: Matt Caswell <matt@openssl.org>
        Reviewed-by: Tomas Mraz <tomas@openssl.org>
        (Merged from openssl#16651)

    Reviewed-by: Matt Caswell <matt@openssl.org>
    Reviewed-by: Tomas Mraz <tomas@openssl.org>
    (Merged from openssl#18347)

commit e04ba88
Author: Daniel Fiala <daniel@openssl.org>
Date:   Tue May 10 08:46:37 2022 +0000

    s_serve: Report an error if init-connection fails without an attempt to read.

    Fixes: openssl#18047.

    Reviewed-by: Paul Dale <pauli@openssl.org>
    Reviewed-by: Tomas Mraz <tomas@openssl.org>
    (Merged from openssl#18283)

commit 6ef91d8
Author: basavesh <basavesh.shivakumar@gmail.com>
Date:   Tue Apr 5 17:49:09 2022 +0200

    Fix leakage when the cacheline is 32-bytes in CBC_MAC_ROTATE_IN_PLACE

    rotated_mac is a 64-byte aligned buffer of size 64 and rotate_offset is secret.
    Consider a weaker leakage model(CL) where only cacheline base address is leaked,
    i.e address/32 for 32-byte cacheline(CL32).

    Previous code used to perform two loads
        1. rotated_mac[rotate_offset ^ 32] and
        2. rotated_mac[rotate_offset++]
    which would leak 2q + 1, 2q for 0 <= rotate_offset < 32
    and 2q, 2q + 1 for 32 <= rotate_offset < 64

    The proposed fix performs load operations which will always leak 2q, 2q + 1 and
    selects the appropriate value in constant-time.

    Reviewed-by: Matt Caswell <matt@openssl.org>
    Reviewed-by: Tomas Mraz <tomas@openssl.org>
    (Merged from openssl#18050)

commit c7d6c08
Author: Tomas Mraz <tomas@openssl.org>
Date:   Fri Apr 29 17:02:19 2022 +0200

    Add test for empty supported-groups extension

    Reviewed-by: Paul Dale <pauli@openssl.org>
    Reviewed-by: Matt Caswell <matt@openssl.org>
    (Merged from openssl#18213)

commit bd16488
Author: Tomas Mraz <tomas@openssl.org>
Date:   Fri Apr 29 16:36:36 2022 +0200

    Do not send an empty supported groups extension

    This allows handshake to proceed if the maximum TLS version enabled is <1.3

    Fixes openssl#13583

    Reviewed-by: Paul Dale <pauli@openssl.org>
    Reviewed-by: Matt Caswell <matt@openssl.org>
    (Merged from openssl#18213)

commit ac2d4cb
Author: Allan Jude <allan@klarasystems.com>
Date:   Fri Nov 19 19:06:52 2021 +0000

    1_1_1-stable: Detect arm64-*-*bsd and enable assembly optimizations

    Reviewed-by: Paul Dale <pauli@openssl.org>
    Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
    Reviewed-by: Tomas Mraz <tomas@openssl.org>
    (Merged from openssl#17085)

commit ec1b4bf
Author: Hugo Landau <hlandau@openssl.org>
Date:   Wed Apr 27 10:11:08 2022 +0100

    (1.1) Add SSL_(CTX_)?get0_(verify|chain)_cert_store functions

    Backport of openssl#18038 to 1.1.

    Fixes openssl#18035.

    Reviewed-by: Tomas Mraz <tomas@openssl.org>
    Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
    (Merged from openssl#18190)

commit 988c7b2
Author: Matt Caswell <matt@openssl.org>
Date:   Tue May 3 14:41:23 2022 +0100

    Prepare for 1.1.1p-dev

    Reviewed-by: Tomas Mraz <tomas@openssl.org>
    Release: yes
  • Loading branch information
rsbeckerca committed Jul 5, 2022
1 parent 5ea6414 commit d97281f
Show file tree
Hide file tree
Showing 12 changed files with 215 additions and 18 deletions.
13 changes: 13 additions & 0 deletions CHANGES
Expand Up @@ -7,6 +7,19 @@
https://github.com/openssl/openssl/commits/ and pick the appropriate
release branch.

Changes between 1.1.1p and 1.1.1q [5 Jul 2022]

*) AES OCB mode for 32-bit x86 platforms using the AES-NI assembly optimised
implementation would not encrypt the entirety of the data under some
circumstances. This could reveal sixteen bytes of data that was
preexisting in the memory that wasn't written. In the special case of
"in place" encryption, sixteen bytes of the plaintext would be revealed.

Since OpenSSL does not support OCB based cipher suites for TLS and DTLS,
they are both unaffected.
(CVE-2022-2097)
[Alex Chernyakhovsky, David Benjamin, Alejandro Sedeño]

Changes between 1.1.1o and 1.1.1p [21 Jun 2022]

*) In addition to the c_rehash shell command injection identified in
Expand Down
5 changes: 5 additions & 0 deletions NEWS
Expand Up @@ -5,6 +5,11 @@
This file gives a brief overview of the major changes between each OpenSSL
release. For more details please read the CHANGES file.

Major changes between OpenSSL 1.1.1p and OpenSSL 1.1.1q [5 Jul 2022]

o Fixed AES OCB failure to encrypt some bytes on 32-bit x86 platforms
(CVE-2022-2097)

Major changes between OpenSSL 1.1.1o and OpenSSL 1.1.1p [21 Jun 2022]

o Fixed additional bugs in the c_rehash script which was not properly
Expand Down
2 changes: 1 addition & 1 deletion README
@@ -1,5 +1,5 @@

OpenSSL 1.1.1p 21 Jun 2022
OpenSSL 1.1.1q 5 Jul 2022

Copyright (c) 1998-2022 The OpenSSL Project
Copyright (c) 1995-1998 Eric A. Young, Tim J. Hudson
Expand Down
6 changes: 3 additions & 3 deletions crypto/aes/asm/aesni-x86.pl
@@ -1,5 +1,5 @@
#! /usr/bin/env perl
# Copyright 2009-2020 The OpenSSL Project Authors. All Rights Reserved.
# Copyright 2009-2022 The OpenSSL Project Authors. All Rights Reserved.
#
# Licensed under the OpenSSL license (the "License"). You may not use
# this file except in compliance with the License. You can obtain a copy
Expand Down Expand Up @@ -2027,7 +2027,7 @@ sub aesni_generate6
&movdqu (&QWP(-16*2,$out,$inp),$inout4);
&movdqu (&QWP(-16*1,$out,$inp),$inout5);
&cmp ($inp,$len); # done yet?
&jb (&label("grandloop"));
&jbe (&label("grandloop"));

&set_label("short");
&add ($len,16*6);
Expand Down Expand Up @@ -2453,7 +2453,7 @@ sub aesni_generate6
&pxor ($rndkey1,$inout5);
&movdqu (&QWP(-16*1,$out,$inp),$inout5);
&cmp ($inp,$len); # done yet?
&jb (&label("grandloop"));
&jbe (&label("grandloop"));

&set_label("short");
&add ($len,16*6);
Expand Down
8 changes: 5 additions & 3 deletions crypto/bn/bn_gcd.c
@@ -1,5 +1,5 @@
/*
* Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
* Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
Expand Down Expand Up @@ -47,7 +47,8 @@ BIGNUM *bn_mod_inverse_no_branch(BIGNUM *in,
if (R == NULL)
goto err;

BN_one(X);
if (!BN_one(X))
goto err;
BN_zero(Y);
if (BN_copy(B, a) == NULL)
goto err;
Expand Down Expand Up @@ -235,7 +236,8 @@ BIGNUM *int_bn_mod_inverse(BIGNUM *in,
if (R == NULL)
goto err;

BN_one(X);
if (!BN_one(X))
goto err;
BN_zero(Y);
if (BN_copy(B, a) == NULL)
goto err;
Expand Down
4 changes: 2 additions & 2 deletions crypto/ec/ec_asn1.c
Expand Up @@ -794,7 +794,7 @@ EC_GROUP *EC_GROUP_new_from_ecparameters(const ECPARAMETERS *params)
}

/* extract the order */
if ((a = ASN1_INTEGER_to_BN(params->order, a)) == NULL) {
if (ASN1_INTEGER_to_BN(params->order, a) == NULL) {
ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, ERR_R_ASN1_LIB);
goto err;
}
Expand All @@ -811,7 +811,7 @@ EC_GROUP *EC_GROUP_new_from_ecparameters(const ECPARAMETERS *params)
if (params->cofactor == NULL) {
BN_free(b);
b = NULL;
} else if ((b = ASN1_INTEGER_to_BN(params->cofactor, b)) == NULL) {
} else if (ASN1_INTEGER_to_BN(params->cofactor, b) == NULL) {
ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, ERR_R_ASN1_LIB);
goto err;
}
Expand Down
16 changes: 13 additions & 3 deletions crypto/x509v3/v3_addr.c
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2016 The OpenSSL Project Authors. All Rights Reserved.
* Copyright 2006-2022 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
Expand All @@ -13,6 +13,8 @@

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>

#include "internal/cryptlib.h"
#include <openssl/conf.h>
Expand Down Expand Up @@ -342,8 +344,13 @@ static int range_should_be_prefix(const unsigned char *min,
unsigned char mask;
int i, j;

if (memcmp(min, max, length) <= 0)
return -1;
/*
* It is the responsibility of the caller to confirm min <= max. We don't
* use ossl_assert() here since we have no way of signalling an error from
* this function - so we just use a plain assert instead.
*/
assert(memcmp(min, max, length) <= 0);

for (i = 0; i < length && min[i] == max[i]; i++) ;
for (j = length - 1; j >= 0 && min[j] == 0x00 && max[j] == 0xFF; j--) ;
if (i < j)
Expand Down Expand Up @@ -426,6 +433,9 @@ static int make_addressRange(IPAddressOrRange **result,
IPAddressOrRange *aor;
int i, prefixlen;

if (memcmp(min, max, length) > 0)
return 0;

if ((prefixlen = range_should_be_prefix(min, max, length)) >= 0)
return make_addressPrefix(result, min, prefixlen);

Expand Down
2 changes: 2 additions & 0 deletions crypto/x509v3/v3_sxnet.c
Expand Up @@ -78,6 +78,8 @@ static int sxnet_i2r(X509V3_EXT_METHOD *method, SXNET *sx, BIO *out,
for (i = 0; i < sk_SXNETID_num(sx->ids); i++) {
id = sk_SXNETID_value(sx->ids, i);
tmp = i2s_ASN1_INTEGER(NULL, id->zone);
if (tmp == NULL)
return 0;
BIO_printf(out, "\n%*sZone: %s, User: ", indent, "", tmp);
OPENSSL_free(tmp);
ASN1_STRING_print(out, id->user);
Expand Down
6 changes: 3 additions & 3 deletions doc/man3/SSL_get_current_cipher.pod
Expand Up @@ -10,8 +10,8 @@ SSL_get_pending_cipher - get SSL_CIPHER of a connection

#include <openssl/ssl.h>

SSL_CIPHER *SSL_get_current_cipher(const SSL *ssl);
SSL_CIPHER *SSL_get_pending_cipher(const SSL *ssl);
const SSL_CIPHER *SSL_get_current_cipher(const SSL *ssl);
const SSL_CIPHER *SSL_get_pending_cipher(const SSL *ssl);

const char *SSL_get_cipher_name(const SSL *s);
const char *SSL_get_cipher(const SSL *s);
Expand Down Expand Up @@ -61,7 +61,7 @@ L<ssl(7)>, L<SSL_CIPHER_get_name(3)>

=head1 COPYRIGHT

Copyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved.
Copyright 2000-2022 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the OpenSSL license (the "License"). You may not use
this file except in compliance with the License. You can obtain a copy
Expand Down
4 changes: 2 additions & 2 deletions include/openssl/opensslv.h
Expand Up @@ -39,8 +39,8 @@ extern "C" {
* (Prior to 0.9.5a beta1, a different scheme was used: MMNNFFRBB for
* major minor fix final patch/beta)
*/
# define OPENSSL_VERSION_NUMBER 0x1010110fL
# define OPENSSL_VERSION_TEXT "OpenSSL 1.1.1p 21 Jun 2022"
# define OPENSSL_VERSION_NUMBER 0x1010111fL
# define OPENSSL_VERSION_TEXT "OpenSSL 1.1.1q 5 Jul 2022"

/*-
* The macros below are to be used for shared library (.so, .dll, ...)
Expand Down
52 changes: 51 additions & 1 deletion test/recipes/30-test_evp_data/evpciph.txt
@@ -1,5 +1,5 @@
#
# Copyright 2001-2019 The OpenSSL Project Authors. All Rights Reserved.
# Copyright 2001-2022 The OpenSSL Project Authors. All Rights Reserved.
#
# Licensed under the OpenSSL license (the "License"). You may not use
# this file except in compliance with the License. You can obtain a copy
Expand Down Expand Up @@ -1188,6 +1188,56 @@ Ciphertext = 09A4FD29DE949D9A9AA9924248422097AD4883B4713E6C214FF6567ADA08A967B21
Operation = DECRYPT
Result = CIPHERFINAL_ERROR

#Test vectors generated to validate aesni_ocb_encrypt on x86
Cipher = aes-128-ocb
Key = 000102030405060708090A0B0C0D0E0F
IV = 000000000001020304050607
Tag = C14DFF7D62A13C4A3422456207453190
Plaintext = 000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F
Ciphertext = F5186C9CC3506386919B6FD9443956E05B203313F8AB35E916AB36932EBDDCD2945901BABE7CF29404929F322F954C916065FABF8F1E52F4BD7C538C0F96899519DBC6BC504D837D8EBD1436B45D33F528CB642FA2EB2C403FE604C12B819333

Cipher = aes-128-ocb
Key = 000102030405060708090A0B0C0D0E0F
IV = 000000000001020304050607
Tag = D47D84F6FF912C79B6A4223AB9BE2DB8
Plaintext = 000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F
Ciphertext = F5186C9CC3506386919B6FD9443956E05B203313F8AB35E916AB36932EBDDCD2945901BABE7CF29404929F322F954C916065FABF8F1E52F4BD7C538C0F96899519DBC6BC504D837D8EBD1436B45D33F528CB642FA2EB2C403FE604C12B8193332374120A78A1171D23ED9E9CB1ADC204

Cipher = aes-128-ocb
Key = 000102030405060708090A0B0C0D0E0F
IV = 000000000001020304050607
Tag = 41970D13737B7BD1B5FBF49ED4412CA5
Plaintext = 000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F7071000102030405060708090A0B0C0D
Ciphertext = F5186C9CC3506386919B6FD9443956E05B203313F8AB35E916AB36932EBDDCD2945901BABE7CF29404929F322F954C916065FABF8F1E52F4BD7C538C0F96899519DBC6BC504D837D8EBD1436B45D33F528CB642FA2EB2C403FE604C12B8193332374120A78A1171D23ED9E9CB1ADC20412C017AD0CA498827C768DDD99B26E91

Cipher = aes-128-ocb
Key = 000102030405060708090A0B0C0D0E0F
IV = 000000000001020304050607
Tag = BE0228651ED4E48A11BDED68D953F3A0
Plaintext = 000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F7071000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D
Ciphertext = F5186C9CC3506386919B6FD9443956E05B203313F8AB35E916AB36932EBDDCD2945901BABE7CF29404929F322F954C916065FABF8F1E52F4BD7C538C0F96899519DBC6BC504D837D8EBD1436B45D33F528CB642FA2EB2C403FE604C12B8193332374120A78A1171D23ED9E9CB1ADC20412C017AD0CA498827C768DDD99B26E91EDB8681700FF30366F07AEDE8CEACC1F

Cipher = aes-128-ocb
Key = 000102030405060708090A0B0C0D0E0F
IV = 000000000001020304050607
Tag = 17BC6E10B16E5FDC52836E7D589518C7
Plaintext = 000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F7071000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D
Ciphertext = F5186C9CC3506386919B6FD9443956E05B203313F8AB35E916AB36932EBDDCD2945901BABE7CF29404929F322F954C916065FABF8F1E52F4BD7C538C0F96899519DBC6BC504D837D8EBD1436B45D33F528CB642FA2EB2C403FE604C12B8193332374120A78A1171D23ED9E9CB1ADC20412C017AD0CA498827C768DDD99B26E91EDB8681700FF30366F07AEDE8CEACC1F39BE69B91BC808FA7A193F7EEA43137B

Cipher = aes-128-ocb
Key = 000102030405060708090A0B0C0D0E0F
IV = 000000000001020304050607
Tag = E84AAC18666116990A3A37B3A5FC55BD
Plaintext = 000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F7071000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D
Ciphertext = F5186C9CC3506386919B6FD9443956E05B203313F8AB35E916AB36932EBDDCD2945901BABE7CF29404929F322F954C916065FABF8F1E52F4BD7C538C0F96899519DBC6BC504D837D8EBD1436B45D33F528CB642FA2EB2C403FE604C12B8193332374120A78A1171D23ED9E9CB1ADC20412C017AD0CA498827C768DDD99B26E91EDB8681700FF30366F07AEDE8CEACC1F39BE69B91BC808FA7A193F7EEA43137B11CF99263D693AEBDF8ADE1A1D838DED

Cipher = aes-128-ocb
Key = 000102030405060708090A0B0C0D0E0F
IV = 000000000001020304050607
Tag = 3E5EA7EE064FE83B313E28D411E91EAD
Plaintext = 000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F7071000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D
Ciphertext = F5186C9CC3506386919B6FD9443956E05B203313F8AB35E916AB36932EBDDCD2945901BABE7CF29404929F322F954C916065FABF8F1E52F4BD7C538C0F96899519DBC6BC504D837D8EBD1436B45D33F528CB642FA2EB2C403FE604C12B8193332374120A78A1171D23ED9E9CB1ADC20412C017AD0CA498827C768DDD99B26E91EDB8681700FF30366F07AEDE8CEACC1F39BE69B91BC808FA7A193F7EEA43137B11CF99263D693AEBDF8ADE1A1D838DED48D9E09F452F8E6FBEB76A3DED47611C

Title = AES XTS test vectors from IEEE Std 1619-2007

# Using the same key twice for encryption is always banned.
Expand Down
115 changes: 115 additions & 0 deletions test/v3ext.c
Expand Up @@ -12,6 +12,7 @@
#include <openssl/x509v3.h>
#include <openssl/pem.h>
#include <openssl/err.h>
#include "internal/nelem.h"

#include "testutil.h"

Expand All @@ -37,6 +38,7 @@ static int test_pathlen(void)
return ret;
}

#ifndef OPENSSL_NO_RFC3779
static int test_asid(void)
{
ASN1_INTEGER *val1 = NULL, *val2 = NULL;
Expand Down Expand Up @@ -114,12 +116,125 @@ static int test_asid(void)
return testresult;
}

static struct ip_ranges_st {
const unsigned int afi;
const char *ip1;
const char *ip2;
int rorp;
} ranges[] = {
{ IANA_AFI_IPV4, "192.168.0.0", "192.168.0.1", IPAddressOrRange_addressPrefix},
{ IANA_AFI_IPV4, "192.168.0.0", "192.168.0.2", IPAddressOrRange_addressRange},
{ IANA_AFI_IPV4, "192.168.0.0", "192.168.0.3", IPAddressOrRange_addressPrefix},
{ IANA_AFI_IPV4, "192.168.0.0", "192.168.0.254", IPAddressOrRange_addressRange},
{ IANA_AFI_IPV4, "192.168.0.0", "192.168.0.255", IPAddressOrRange_addressPrefix},
{ IANA_AFI_IPV4, "192.168.0.1", "192.168.0.255", IPAddressOrRange_addressRange},
{ IANA_AFI_IPV4, "192.168.0.1", "192.168.0.1", IPAddressOrRange_addressPrefix},
{ IANA_AFI_IPV4, "192.168.0.0", "192.168.255.255", IPAddressOrRange_addressPrefix},
{ IANA_AFI_IPV4, "192.168.1.0", "192.168.255.255", IPAddressOrRange_addressRange},
{ IANA_AFI_IPV6, "2001:0db8::0", "2001:0db8::1", IPAddressOrRange_addressPrefix},
{ IANA_AFI_IPV6, "2001:0db8::0", "2001:0db8::2", IPAddressOrRange_addressRange},
{ IANA_AFI_IPV6, "2001:0db8::0", "2001:0db8::3", IPAddressOrRange_addressPrefix},
{ IANA_AFI_IPV6, "2001:0db8::0", "2001:0db8::fffe", IPAddressOrRange_addressRange},
{ IANA_AFI_IPV6, "2001:0db8::0", "2001:0db8::ffff", IPAddressOrRange_addressPrefix},
{ IANA_AFI_IPV6, "2001:0db8::1", "2001:0db8::ffff", IPAddressOrRange_addressRange},
{ IANA_AFI_IPV6, "2001:0db8::1", "2001:0db8::1", IPAddressOrRange_addressPrefix},
{ IANA_AFI_IPV6, "2001:0db8::0:0", "2001:0db8::ffff:ffff", IPAddressOrRange_addressPrefix},
{ IANA_AFI_IPV6, "2001:0db8::1:0", "2001:0db8::ffff:ffff", IPAddressOrRange_addressRange}
};

static int check_addr(IPAddrBlocks *addr, int type)
{
IPAddressFamily *fam;
IPAddressOrRange *aorr;

if (!TEST_int_eq(sk_IPAddressFamily_num(addr), 1))
return 0;

fam = sk_IPAddressFamily_value(addr, 0);
if (!TEST_ptr(fam))
return 0;

if (!TEST_int_eq(fam->ipAddressChoice->type, IPAddressChoice_addressesOrRanges))
return 0;

if (!TEST_int_eq(sk_IPAddressOrRange_num(fam->ipAddressChoice->u.addressesOrRanges), 1))
return 0;

aorr = sk_IPAddressOrRange_value(fam->ipAddressChoice->u.addressesOrRanges, 0);
if (!TEST_ptr(aorr))
return 0;

if (!TEST_int_eq(aorr->type, type))
return 0;

return 1;
}

static int test_addr_ranges(void)
{
IPAddrBlocks *addr = NULL;
ASN1_OCTET_STRING *ip1 = NULL, *ip2 = NULL;
size_t i;
int testresult = 0;

for (i = 0; i < OSSL_NELEM(ranges); i++) {
addr = sk_IPAddressFamily_new_null();
if (!TEST_ptr(addr))
goto end;
/*
* Has the side effect of installing the comparison function onto the
* stack.
*/
if (!TEST_true(X509v3_addr_canonize(addr)))
goto end;

ip1 = a2i_IPADDRESS(ranges[i].ip1);
if (!TEST_ptr(ip1))
goto end;
if (!TEST_true(ip1->length == 4 || ip1->length == 16))
goto end;
ip2 = a2i_IPADDRESS(ranges[i].ip2);
if (!TEST_ptr(ip2))
goto end;
if (!TEST_int_eq(ip2->length, ip1->length))
goto end;
if (!TEST_true(memcmp(ip1->data, ip2->data, ip1->length) <= 0))
goto end;

if (!TEST_true(X509v3_addr_add_range(addr, ranges[i].afi, NULL, ip1->data, ip2->data)))
goto end;

if (!TEST_true(X509v3_addr_is_canonical(addr)))
goto end;

if (!check_addr(addr, ranges[i].rorp))
goto end;

sk_IPAddressFamily_pop_free(addr, IPAddressFamily_free);
addr = NULL;
ASN1_OCTET_STRING_free(ip1);
ASN1_OCTET_STRING_free(ip2);
ip1 = ip2 = NULL;
}

testresult = 1;
end:
sk_IPAddressFamily_pop_free(addr, IPAddressFamily_free);
ASN1_OCTET_STRING_free(ip1);
ASN1_OCTET_STRING_free(ip2);
return testresult;
}
#endif /* OPENSSL_NO_RFC3779 */

int setup_tests(void)
{
if (!TEST_ptr(infile = test_get_argument(0)))
return 0;

ADD_TEST(test_pathlen);
#ifndef OPENSSL_NO_RFC3779
ADD_TEST(test_asid);
ADD_TEST(test_addr_ranges);
#endif /* OPENSSL_NO_RFC3779 */
return 1;
}

0 comments on commit d97281f

Please sign in to comment.