Import OpenSSL 1.1.1l

This commit is contained in:
Steve Dower
2021-08-26 19:30:20 +01:00
parent b439f09b29
commit b123b12c0d
104 changed files with 2011 additions and 524 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2018-2019 The OpenSSL Project Authors. All Rights Reserved.
* Copyright 2018-2021 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
@@ -10,6 +10,8 @@
#include <string.h>
#include <openssl/buffer.h>
#include <openssl/bio.h>
#include <openssl/pkcs7.h>
#include <openssl/obj_mac.h>
#include "testutil.h"
@@ -35,7 +37,7 @@ static int test_bio_memleak(void)
goto finish;
ok = 1;
finish:
finish:
BIO_free(bio);
return ok;
}
@@ -62,7 +64,7 @@ static int test_bio_get_mem(void)
goto finish;
ok = 1;
finish:
finish:
BIO_free(bio);
BUF_MEM_free(bufmem);
return ok;
@@ -98,7 +100,7 @@ static int test_bio_new_mem_buf(void)
goto finish;
ok = 1;
finish:
finish:
BIO_free(bio);
return ok;
}
@@ -139,7 +141,7 @@ static int test_bio_rdonly_mem_buf(void)
goto finish;
ok = 1;
finish:
finish:
BIO_free(bio);
BIO_free(bio2);
return ok;
@@ -176,7 +178,7 @@ static int test_bio_rdwr_rdonly(void)
ok = 1;
finish:
finish:
BIO_free(bio);
return ok;
}
@@ -216,11 +218,72 @@ static int test_bio_nonclear_rst(void)
ok = 1;
finish:
finish:
BIO_free(bio);
return ok;
}
static int error_callback_fired;
static long BIO_error_callback(BIO *bio, int cmd, const char *argp,
size_t len, int argi,
long argl, int ret, size_t *processed)
{
if ((cmd & (BIO_CB_READ | BIO_CB_RETURN)) != 0) {
error_callback_fired = 1;
ret = 0; /* fail for read operations to simulate error in input BIO */
}
return ret;
}
/* Checks i2d_ASN1_bio_stream() is freeing all memory when input BIO ends unexpectedly. */
static int test_bio_i2d_ASN1_mime(void)
{
int ok = 0;
BIO *bio = NULL, *out = NULL;
BUF_MEM bufmem;
static const char str[] = "BIO mime test\n";
PKCS7 *p7 = NULL;
if (!TEST_ptr(bio = BIO_new(BIO_s_mem())))
goto finish;
bufmem.length = sizeof(str);
bufmem.data = (char *) str;
bufmem.max = bufmem.length;
BIO_set_mem_buf(bio, &bufmem, BIO_NOCLOSE);
BIO_set_flags(bio, BIO_FLAGS_MEM_RDONLY);
BIO_set_callback_ex(bio, BIO_error_callback);
if (!TEST_ptr(out = BIO_new(BIO_s_mem())))
goto finish;
if (!TEST_ptr(p7 = PKCS7_new()))
goto finish;
if (!TEST_true(PKCS7_set_type(p7, NID_pkcs7_data)))
goto finish;
error_callback_fired = 0;
/*
* The call succeeds even if the input stream ends unexpectedly as
* there is no handling for this case in SMIME_crlf_copy().
*/
if (!TEST_true(i2d_ASN1_bio_stream(out, (ASN1_VALUE*) p7, bio,
SMIME_STREAM | SMIME_BINARY,
ASN1_ITEM_rptr(PKCS7))))
goto finish;
if (!TEST_int_eq(error_callback_fired, 1))
goto finish;
ok = 1;
finish:
BIO_free(bio);
BIO_free(out);
PKCS7_free(p7);
return ok;
}
int global_init(void)
{
CRYPTO_set_mem_debug(1);
@@ -236,5 +299,6 @@ int setup_tests(void)
ADD_TEST(test_bio_rdonly_mem_buf);
ADD_TEST(test_bio_rdwr_rdonly);
ADD_TEST(test_bio_nonclear_rst);
ADD_TEST(test_bio_i2d_ASN1_mime);
return 1;
}