This commit is contained in:
Burkov Egor 2025-07-31 06:54:34 +01:00 committed by GitHub
commit 711c25fbfb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 34 additions and 25 deletions

View File

@ -185,14 +185,14 @@ static int genb64(char *prefix, char *suffix, unsigned const char *buf,
static int test_bio_base64_run(test_case *t, int llen, int wscnt) static int test_bio_base64_run(test_case *t, int llen, int wscnt)
{ {
unsigned char *raw; unsigned char *raw = NULL;
unsigned char *out; unsigned char *out = NULL;
unsigned out_len; unsigned out_len;
char *encoded = NULL; char *encoded = NULL;
int elen; int elen;
BIO *bio, *b64; BIO *bio = NULL, *b64 = NULL;
int n, n1, n2; int n, n1, n2;
int ret; int ret = -1;
/* /*
* Pre-encoded data always encodes NUL octets. If all we care about is the * Pre-encoded data always encodes NUL octets. If all we care about is the
@ -203,28 +203,19 @@ static int test_bio_base64_run(test_case *t, int llen, int wscnt)
else else
raw = genbytes(t->bytes); raw = genbytes(t->bytes);
if (raw == NULL && t->bytes > 0) { if (!TEST_true(raw != NULL || (raw == NULL && t->bytes > 0)))
TEST_error("out of memory"); goto err;
return -1;
}
out_len = t->bytes + 1024; out_len = t->bytes + 1024;
out = OPENSSL_malloc(out_len); out = OPENSSL_malloc(out_len);
if (out == NULL) { if (!TEST_ptr(out))
OPENSSL_free(raw); goto err;
TEST_error("out of memory");
return -1;
}
elen = genb64(t->prefix, t->suffix, raw, t->bytes, t->trunc, t->encoded, elen = genb64(t->prefix, t->suffix, raw, t->bytes, t->trunc, t->encoded,
llen, wscnt, &encoded); llen, wscnt, &encoded);
if (elen < 0 || (bio = BIO_new(BIO_s_mem())) == NULL) { if (!TEST_int_lt(elen, 0) || !TEST_ptr(bio = BIO_new(BIO_s_mem())))
OPENSSL_free(raw); goto err;
OPENSSL_free(out);
OPENSSL_free(encoded);
TEST_error("out of memory");
return -1;
}
if (t->retry) if (t->retry)
BIO_set_mem_eof_return(bio, EOF_RETURN); BIO_set_mem_eof_return(bio, EOF_RETURN);
else else
@ -241,7 +232,8 @@ static int test_bio_base64_run(test_case *t, int llen, int wscnt)
if (n1 > 0) if (n1 > 0)
BIO_write(bio, encoded, n1); BIO_write(bio, encoded, n1);
b64 = BIO_new(BIO_f_base64()); if (!TEST_ptr(b64 = BIO_new(BIO_f_base64())))
goto err;
if (t->no_nl) if (t->no_nl)
BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL); BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
BIO_push(b64, bio); BIO_push(b64, bio);
@ -298,7 +290,7 @@ static int test_bio_base64_run(test_case *t, int llen, int wscnt)
TEST_error("Failed to decode expected data"); TEST_error("Failed to decode expected data");
ret = -1; ret = -1;
} }
err:
BIO_free_all(b64); BIO_free_all(b64);
OPENSSL_free(out); OPENSSL_free(out);
OPENSSL_free(raw); OPENSSL_free(raw);

View File

@ -160,12 +160,15 @@ static int field_tests_ecp_mont(void)
static int ec2m_field_sanity(void) static int ec2m_field_sanity(void)
{ {
int ret = 0; int ret = 0;
BN_CTX *ctx = BN_CTX_new(); BN_CTX *ctx = NULL;
BIGNUM *p, *a, *b; BIGNUM *p, *a, *b;
EC_GROUP *group1 = NULL, *group2 = NULL, *group3 = NULL; EC_GROUP *group1 = NULL, *group2 = NULL, *group3 = NULL;
TEST_info("Testing GF2m hardening\n"); TEST_info("Testing GF2m hardening\n");
if (!TEST_ptr(ctx = BN_CTX_new()))
goto out;
BN_CTX_start(ctx); BN_CTX_start(ctx);
p = BN_CTX_get(ctx); p = BN_CTX_get(ctx);
a = BN_CTX_get(ctx); a = BN_CTX_get(ctx);

View File

@ -92,6 +92,9 @@ static void copy_flags(BIO *bio)
int flags; int flags;
BIO *next = BIO_next(bio); BIO *next = BIO_next(bio);
if (next == NULL)
return;
flags = BIO_test_flags(next, BIO_FLAGS_SHOULD_RETRY | BIO_FLAGS_RWS); flags = BIO_test_flags(next, BIO_FLAGS_SHOULD_RETRY | BIO_FLAGS_RWS);
BIO_clear_flags(bio, BIO_FLAGS_SHOULD_RETRY | BIO_FLAGS_RWS); BIO_clear_flags(bio, BIO_FLAGS_SHOULD_RETRY | BIO_FLAGS_RWS);
BIO_set_flags(bio, flags); BIO_set_flags(bio, flags);
@ -531,6 +534,7 @@ int mempacket_move_packet(BIO *bio, int d, int s)
/* Increment the packet numbers for moved packets */ /* Increment the packet numbers for moved packets */
for (i = d + 1; i <= s; i++) { for (i = d + 1; i <= s; i++) {
thispkt = sk_MEMPACKET_value(ctx->pkts, i); thispkt = sk_MEMPACKET_value(ctx->pkts, i);
if (thispkt != NULL)
thispkt->num++; thispkt->num++;
} }
return 1; return 1;

View File

@ -18,6 +18,9 @@ static void copy_flags(BIO *bio)
int flags; int flags;
BIO *next = BIO_next(bio); BIO *next = BIO_next(bio);
if (next == NULL)
return;
flags = BIO_test_flags(next, BIO_FLAGS_SHOULD_RETRY | BIO_FLAGS_RWS); flags = BIO_test_flags(next, BIO_FLAGS_SHOULD_RETRY | BIO_FLAGS_RWS);
BIO_clear_flags(bio, BIO_FLAGS_SHOULD_RETRY | BIO_FLAGS_RWS); BIO_clear_flags(bio, BIO_FLAGS_SHOULD_RETRY | BIO_FLAGS_RWS);
BIO_set_flags(bio, flags); BIO_set_flags(bio, flags);

View File

@ -125,6 +125,8 @@ static void rwwriter_fn(int id, int *iterations)
for (count = 0; ; count++) { for (count = 0; ; count++) {
new = CRYPTO_zalloc(sizeof (int), NULL, 0); new = CRYPTO_zalloc(sizeof (int), NULL, 0);
if (!TEST_ptr(new))
abort();
if (contention == 0) if (contention == 0)
OSSL_sleep(1000); OSSL_sleep(1000);
if (!CRYPTO_THREAD_write_lock(rwtorturelock)) if (!CRYPTO_THREAD_write_lock(rwtorturelock))
@ -321,6 +323,8 @@ static void writer_fn(int id, int *iterations)
for (count = 0; ; count++) { for (count = 0; ; count++) {
new = CRYPTO_zalloc(sizeof(uint64_t), NULL, 0); new = CRYPTO_zalloc(sizeof(uint64_t), NULL, 0);
if (!TEST_ptr(new))
abort();
if (contention == 0) if (contention == 0)
OSSL_sleep(1000); OSSL_sleep(1000);
ossl_rcu_write_lock(rcu_lock); ossl_rcu_write_lock(rcu_lock);

View File

@ -182,9 +182,12 @@ static int test_self_signed(const char *filename, int use_trusted, int expected)
{ {
X509 *cert = load_cert_from_file(filename); /* may result in NULL */ X509 *cert = load_cert_from_file(filename); /* may result in NULL */
STACK_OF(X509) *trusted = sk_X509_new_null(); STACK_OF(X509) *trusted = sk_X509_new_null();
X509_STORE_CTX *ctx = X509_STORE_CTX_new(); X509_STORE_CTX *ctx = NULL;
int ret; int ret;
if (!TEST_ptr(ctx = X509_STORE_CTX_new()))
return 0;
ret = TEST_int_eq(X509_self_signed(cert, 1), expected); ret = TEST_int_eq(X509_self_signed(cert, 1), expected);
if (cert != NULL) { if (cert != NULL) {