fuzz: Silence warnings on Win64 builds

Reviewed-by: Saša Nedvědický <sashan@openssl.org>
Reviewed-by: Neil Horman <nhorman@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/27806)
This commit is contained in:
Tomas Mraz 2025-06-18 10:50:27 +02:00
parent c62cd07d14
commit c2482c68e5
23 changed files with 49 additions and 48 deletions

View File

@ -27,7 +27,7 @@ int FuzzerTestOneInput(const uint8_t *buf, size_t len)
const unsigned char *p = buf;
unsigned char *der = NULL;
X509_ACERT *acert = d2i_X509_ACERT(NULL, &p, len);
X509_ACERT *acert = d2i_X509_ACERT(NULL, &p, (long)len);
if (acert != NULL) {
BIO *bio = BIO_new(BIO_s_null());

View File

@ -214,7 +214,7 @@ static ASN1_PCTX *pctx;
#define DO_TEST(TYPE, D2I, I2D, PRINT) { \
const unsigned char *p = buf; \
unsigned char *der = NULL; \
TYPE *type = D2I(NULL, &p, len); \
TYPE *type = D2I(NULL, &p, (long)len); \
\
if (type != NULL) { \
int len2; \
@ -234,7 +234,7 @@ static ASN1_PCTX *pctx;
#define DO_TEST_PRINT_OFFSET(TYPE, D2I, I2D, PRINT) { \
const unsigned char *p = buf; \
unsigned char *der = NULL; \
TYPE *type = D2I(NULL, &p, len); \
TYPE *type = D2I(NULL, &p, (long)len); \
\
if (type != NULL) { \
BIO *bio = BIO_new(BIO_s_null()); \
@ -252,7 +252,7 @@ static ASN1_PCTX *pctx;
#define DO_TEST_PRINT_PCTX(TYPE, D2I, I2D, PRINT) { \
const unsigned char *p = buf; \
unsigned char *der = NULL; \
TYPE *type = D2I(NULL, &p, len); \
TYPE *type = D2I(NULL, &p, (long)len); \
\
if (type != NULL) { \
BIO *bio = BIO_new(BIO_s_null()); \
@ -271,7 +271,7 @@ static ASN1_PCTX *pctx;
#define DO_TEST_NO_PRINT(TYPE, D2I, I2D) { \
const unsigned char *p = buf; \
unsigned char *der = NULL; \
TYPE *type = D2I(NULL, &p, len); \
TYPE *type = D2I(NULL, &p, (long)len); \
\
if (type != NULL) { \
BIO *bio = BIO_new(BIO_s_null()); \
@ -311,7 +311,7 @@ int FuzzerTestOneInput(const uint8_t *buf, size_t len)
const uint8_t *b = buf;
unsigned char *der = NULL;
const ASN1_ITEM *i = ASN1_ITEM_ptr(item_type[n]);
ASN1_VALUE *o = ASN1_item_d2i(NULL, &b, len, i);
ASN1_VALUE *o = ASN1_item_d2i(NULL, &b, (long)len, i);
if (o != NULL) {
/*

View File

@ -34,7 +34,7 @@ int FuzzerInitialize(int *argc, char ***argv)
int FuzzerTestOneInput(const uint8_t *buf, size_t len)
{
(void)ASN1_parse_dump(bio_out, buf, len, 0, 0);
(void)ASN1_parse_dump(bio_out, buf, (long)len, 0, 0);
ERR_clear_error();
return 0;
}

View File

@ -63,10 +63,10 @@ int FuzzerTestOneInput(const uint8_t *buf, size_t len)
s3 = buf[0] & 4;
++buf;
}
OPENSSL_assert(BN_bin2bn(buf, l1, b1) == b1);
OPENSSL_assert(BN_bin2bn(buf, (int)l1, b1) == b1);
BN_set_negative(b1, s1);
OPENSSL_assert(BN_bin2bn(buf + l1, l2, b2) == b2);
OPENSSL_assert(BN_bin2bn(buf + l1 + l2, l3, b3) == b3);
OPENSSL_assert(BN_bin2bn(buf + l1, (int)l2, b2) == b2);
OPENSSL_assert(BN_bin2bn(buf + l1 + l2, (int)l3, b3) == b3);
BN_set_negative(b3, s3);
/* mod 0 is undefined */

View File

@ -69,9 +69,9 @@ int FuzzerTestOneInput(const uint8_t *buf, size_t len)
++buf;
l2 = len - l1;
}
OPENSSL_assert(BN_bin2bn(buf, l1, b1) == b1);
OPENSSL_assert(BN_bin2bn(buf, (int)l1, b1) == b1);
BN_set_negative(b1, s1);
OPENSSL_assert(BN_bin2bn(buf + l1, l2, b2) == b2);
OPENSSL_assert(BN_bin2bn(buf + l1, (int)l2, b2) == b2);
BN_set_negative(b2, s2);
/* divide by 0 is an error */

View File

@ -60,7 +60,7 @@ int FuzzerTestOneInput(const uint8_t *buf, size_t len)
BIO *out;
SSL_CTX *ctx;
if (len == 0)
if (len == 0 || len > INT_MAX)
return 0;
/* This only fuzzes the initial flow from the client so far. */
@ -84,7 +84,7 @@ int FuzzerTestOneInput(const uint8_t *buf, size_t len)
}
SSL_set_bio(client, in, out);
SSL_set_connect_state(client);
OPENSSL_assert((size_t)BIO_write(in, buf, len) == len);
OPENSSL_assert((size_t)BIO_write(in, buf, (int)len) == len);
if (SSL_do_handshake(client) == 1) {
/* Keep reading application data until error or EOF. */
uint8_t tmp[1024];

View File

@ -172,11 +172,11 @@ int FuzzerTestOneInput(const uint8_t *buf, size_t len)
OSSL_CMP_MSG *msg;
BIO *in;
if (len == 0)
if (len == 0 || len > INT_MAX)
return 0;
in = BIO_new(BIO_s_mem());
OPENSSL_assert((size_t)BIO_write(in, buf, len) == len);
OPENSSL_assert((size_t)BIO_write(in, buf, (int)len) == len);
msg = d2i_OSSL_CMP_MSG_bio(in, NULL);
if (msg != NULL) {
BIO *out = BIO_new(BIO_s_null());

View File

@ -30,11 +30,11 @@ int FuzzerTestOneInput(const uint8_t *buf, size_t len)
CMS_ContentInfo *cms;
BIO *in;
if (len == 0)
if (len == 0 || len > INT_MAX)
return 0;
in = BIO_new(BIO_s_mem());
OPENSSL_assert((size_t)BIO_write(in, buf, len) == len);
OPENSSL_assert((size_t)BIO_write(in, buf, (int)len) == len);
cms = d2i_CMS_bio(in, NULL);
if (cms != NULL) {
BIO *out = BIO_new(BIO_s_null());

View File

@ -29,12 +29,12 @@ int FuzzerTestOneInput(const uint8_t *buf, size_t len)
BIO *in;
long eline;
if (len == 0)
if (len == 0 || len > INT_MAX)
return 0;
conf = NCONF_new(NULL);
in = BIO_new(BIO_s_mem());
OPENSSL_assert((size_t)BIO_write(in, buf, len) == len);
OPENSSL_assert((size_t)BIO_write(in, buf, (int)len) == len);
NCONF_load_bio(conf, in, &eline);
NCONF_free(conf);
BIO_free(in);

View File

@ -26,7 +26,7 @@ int FuzzerTestOneInput(const uint8_t *buf, size_t len)
const unsigned char *p = buf;
unsigned char *der = NULL;
X509_CRL *crl = d2i_X509_CRL(NULL, &p, len);
X509_CRL *crl = d2i_X509_CRL(NULL, &p, (long)len);
if (crl != NULL) {
BIO *bio = BIO_new(BIO_s_null());
X509_CRL_print(bio, crl);

View File

@ -29,7 +29,7 @@ int FuzzerTestOneInput(const uint8_t *buf, size_t len)
{
const uint8_t **pp = &buf;
unsigned char *der = NULL;
STACK_OF(SCT) *scts = d2i_SCT_LIST(NULL, pp, len);
STACK_OF(SCT) *scts = d2i_SCT_LIST(NULL, pp, (long)len);
if (scts != NULL) {
BIO *bio = BIO_new(BIO_s_null());
SCT_LIST_print(scts, bio, 4, "\n", NULL);

View File

@ -60,7 +60,7 @@ int FuzzerTestOneInput(const uint8_t *buf, size_t len)
BIO *out;
SSL_CTX *ctx;
if (len == 0)
if (len == 0 || len > INT_MAX)
return 0;
/* This only fuzzes the initial flow from the client so far. */
@ -84,7 +84,7 @@ int FuzzerTestOneInput(const uint8_t *buf, size_t len)
}
SSL_set_bio(client, in, out);
SSL_set_connect_state(client);
OPENSSL_assert((size_t)BIO_write(in, buf, len) == len);
OPENSSL_assert((size_t)BIO_write(in, buf, (int)len) == len);
if (SSL_do_handshake(client) == 1) {
/* Keep reading application data until error or EOF. */
uint8_t tmp[1024];

View File

@ -612,7 +612,7 @@ int FuzzerTestOneInput(const uint8_t *buf, size_t len)
DSA *dsakey = NULL;
#endif
if (len < 2)
if (len < 2 || len > INT_MAX)
return 0;
/* This only fuzzes the initial flow from the client so far. */
@ -702,7 +702,7 @@ int FuzzerTestOneInput(const uint8_t *buf, size_t len)
SSL_set_bio(server, in, out);
SSL_set_accept_state(server);
OPENSSL_assert((size_t)BIO_write(in, buf, len) == len);
OPENSSL_assert((size_t)BIO_write(in, buf, (int)len) == len);
if (SSL_do_handshake(server) == 1) {
/* Keep reading application data until error or EOF. */

View File

@ -198,7 +198,7 @@ static void create_ml_dsa_raw_key(uint8_t **buf, size_t *len,
* typically much less (between 1 and 100 bytes) so use RAND_bytes here
* instead
*/
if (!RAND_bytes(key, keylen))
if (!RAND_bytes(key, (int)keylen))
return;
/*

View File

@ -166,7 +166,7 @@ static void create_mlkem_raw_key(uint8_t **buf, size_t *len,
* buffers, but its typically much less (between 1 and 100 bytes)
* so use RAND_bytes here instead
*/
if (!RAND_bytes(key, keylen))
if (!RAND_bytes(key, (int)keylen))
return;
/*
@ -289,7 +289,7 @@ static void mlkem_encap_decap(uint8_t **buf, size_t *len, void *key1, void *in2,
goto err;
}
if (!RAND_bytes(genkey, genkey_len))
if (!RAND_bytes(genkey, (int)genkey_len))
goto err;
if (EVP_PKEY_encapsulate(ctx, wrapkey, &wrapkey_len, genkey, &genkey_len) <= 0) {

View File

@ -27,16 +27,16 @@ int FuzzerTestOneInput(const uint8_t *buf, size_t len)
unsigned char *data = NULL;
long outlen;
if (len <= 1)
if (len <= 1 || len > INT_MAX)
return 0;
in = BIO_new(BIO_s_mem());
OPENSSL_assert((size_t)BIO_write(in, buf + 1, len - 1) == len - 1);
OPENSSL_assert((size_t)BIO_write(in, buf + 1, (int)(len - 1)) == len - 1);
if (PEM_read_bio_ex(in, &name, &header, &data, &outlen, buf[0]) == 1) {
/* Try to read all the data we get to see if allocated properly. */
BIO_write(in, name, strlen(name));
BIO_write(in, header, strlen(header));
BIO_write(in, data, outlen);
/* Try to read all the data we get to see if allocated properly. */
BIO_write(in, name, (int)strlen(name));
BIO_write(in, header, (int)strlen(header));
BIO_write(in, data, outlen);
}
if (buf[0] & PEM_FLAG_SECURE) {
OPENSSL_secure_free(name);

View File

@ -214,7 +214,7 @@ static int read_octet_string(const uint8_t **buf, size_t *len, char **res)
*res = (char *) *buf;
r = ptr - *buf;
r = (int)(ptr - *buf);
*len -= r;
*buf = ptr;
@ -409,7 +409,8 @@ static int do_evp_cipher(const EVP_CIPHER *evp_cipher, const OSSL_PARAM param[])
return 0;
}
if (!EVP_EncryptUpdate(ctx, outbuf, &outlen, (const unsigned char *) intext, strlen(intext))) {
if (!EVP_EncryptUpdate(ctx, outbuf, &outlen, (const unsigned char *) intext,
(int)strlen(intext))) {
/* Error */
EVP_CIPHER_CTX_free(ctx);
return 0;

View File

@ -249,7 +249,7 @@ int FuzzerTestOneInput(const uint8_t *buf, size_t len)
break;
if (size > 0)
BIO_write(in, buf+2, size);
BIO_write(in, buf+2, (int)size);
len -= size + 2;
buf += size + 2;
}

View File

@ -239,7 +239,7 @@ int FuzzerTestOneInput(const uint8_t *buf, size_t len)
break;
if (size > 0)
BIO_write(in, buf + 2, size);
BIO_write(in, buf + 2, (int)size);
len -= size + 2;
buf += size + 2;
}

View File

@ -535,7 +535,7 @@ int FuzzerTestOneInput(const uint8_t *buf, size_t len)
#endif
uint8_t opt;
if (len < 2)
if (len < 2 || len > INT_MAX)
return 0;
/* This only fuzzes the initial flow from the client so far. */
@ -632,7 +632,7 @@ int FuzzerTestOneInput(const uint8_t *buf, size_t len)
opt = (uint8_t)buf[len-1];
len--;
OPENSSL_assert((size_t)BIO_write(in, buf, len) == len);
OPENSSL_assert((size_t)BIO_write(in, buf, (int)len) == len);
if ((opt & 0x01) != 0) {
do {

View File

@ -21,7 +21,7 @@ int FuzzerInitialize(int *argc, char ***argv)
int FuzzerTestOneInput(const uint8_t *buf, size_t len)
{
BIO *b = BIO_new_mem_buf(buf, len);
BIO *b = BIO_new_mem_buf(buf, (int)len);
PKCS7 *p7 = SMIME_read_PKCS7(b, NULL);
if (p7 != NULL) {

View File

@ -28,9 +28,9 @@ int FuzzerTestOneInput(const uint8_t* data, size_t size){
* We create two versions of each GENERAL_NAME so that we ensure when
* we compare them they are always different pointers.
*/
namesa = d2i_GENERAL_NAME(NULL, &derp, size);
namesa = d2i_GENERAL_NAME(NULL, &derp, (long)size);
derp = data;
namesb = d2i_GENERAL_NAME(NULL, &derp, size);
namesb = d2i_GENERAL_NAME(NULL, &derp, (long)size);
GENERAL_NAME_cmp(namesa, namesb);
if (namesa != NULL)
GENERAL_NAME_free(namesa);

View File

@ -47,7 +47,7 @@ int FuzzerTestOneInput(const uint8_t *buf, size_t len)
OCSP_BASICRESP *bs = NULL;
OCSP_CERTID *id = NULL;
x509_1 = d2i_X509(NULL, &p, len);
x509_1 = d2i_X509(NULL, &p, (long)len);
if (x509_1 == NULL)
goto err;
@ -65,17 +65,17 @@ int FuzzerTestOneInput(const uint8_t *buf, size_t len)
OPENSSL_free(der);
len = orig_len - (p - buf);
x509_2 = d2i_X509(NULL, &p, len);
x509_2 = d2i_X509(NULL, &p, (long)len);
if (x509_2 == NULL)
goto err;
len = orig_len - (p - buf);
crl = d2i_X509_CRL(NULL, &p, len);
crl = d2i_X509_CRL(NULL, &p, (long)len);
if (crl == NULL)
goto err;
len = orig_len - (p - buf);
resp = d2i_OCSP_RESPONSE(NULL, &p, len);
resp = d2i_OCSP_RESPONSE(NULL, &p, (long)len);
store = X509_STORE_new();
if (store == NULL)