From: Tomas Mraz Date: Tue, 17 Jun 2025 18:08:49 +0000 (+0200) Subject: apps: Silence warnings on Win64 builds X-Git-Tag: openssl-3.6.0-alpha1~500 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c62cd07d142574973646c17a177541446350a9e9;p=thirdparty%2Fopenssl.git apps: Silence warnings on Win64 builds Reviewed-by: Saša Nedvědický Reviewed-by: Neil Horman (Merged from https://github.com/openssl/openssl/pull/27806) --- diff --git a/apps/ca.c b/apps/ca.c index 6d1d1c0a6ea..236b511de29 100644 --- a/apps/ca.c +++ b/apps/ca.c @@ -707,7 +707,7 @@ end_of_options: goto end; } p = pp[DB_serial]; - j = strlen(p); + j = (int)strlen(p); if (*p == '-') { p++; j--; @@ -2406,9 +2406,9 @@ static char *make_revocation_str(REVINFO_TYPE rev_type, const char *rev_arg) i = revtm->length + 1; if (reason) - i += strlen(reason) + 1; + i += (int)(strlen(reason) + 1); if (other) - i += strlen(other) + 1; + i += (int)(strlen(other) + 1); str = app_malloc(i, "revocation reason"); OPENSSL_strlcpy(str, (char *)revtm->data, i); diff --git a/apps/cmp.c b/apps/cmp.c index 2b4340d9fb4..6f2fea4f556 100644 --- a/apps/cmp.c +++ b/apps/cmp.c @@ -1145,7 +1145,7 @@ static OSSL_CMP_SRV_CTX *setup_srv_ctx(ENGINE *engine) } } else { if (!OSSL_CMP_CTX_set1_referenceValue(ctx, (unsigned char *)opt_srv_ref, - strlen(opt_srv_ref))) + (int)strlen(opt_srv_ref))) goto err; } @@ -1156,7 +1156,7 @@ static OSSL_CMP_SRV_CTX *setup_srv_ctx(ENGINE *engine) if (pass_str != NULL) { cleanse(opt_srv_secret); res = OSSL_CMP_CTX_set1_secretValue(ctx, (unsigned char *)pass_str, - strlen(pass_str)); + (int)strlen(pass_str)); clear_free(pass_str); if (res == 0) goto err; @@ -1550,7 +1550,7 @@ static int setup_protection_ctx(OSSL_CMP_CTX *ctx, ENGINE *engine) cleanse(opt_secret); res = OSSL_CMP_CTX_set1_secretValue(ctx, (unsigned char *)pass_string, - strlen(pass_string)); + (int)strlen(pass_string)); clear_free(pass_string); if (res == 0) return 0; @@ -1560,7 +1560,7 @@ static int setup_protection_ctx(OSSL_CMP_CTX *ctx, ENGINE *engine) } if (opt_ref != NULL && !OSSL_CMP_CTX_set1_referenceValue(ctx, (unsigned char *)opt_ref, - strlen(opt_ref))) + (int)strlen(opt_ref))) return 0; if (opt_key != NULL) { diff --git a/apps/dgst.c b/apps/dgst.c index 0fb1f45200a..3257acd0c3b 100644 --- a/apps/dgst.c +++ b/apps/dgst.c @@ -576,7 +576,7 @@ static void print_out(BIO *out, unsigned char *buf, size_t len, int i, backslash = 0; if (binout) { - BIO_write(out, buf, len); + BIO_write(out, buf, (int)len); } else if (sep == 2) { file = newline_escape_filename(file, &backslash); diff --git a/apps/enc.c b/apps/enc.c index cf26ac0a7d5..a3133aa2549 100644 --- a/apps/enc.c +++ b/apps/enc.c @@ -582,7 +582,7 @@ int enc_main(int argc, char **argv) /* not needed if HASH_UPDATE() is fixed : */ int islen = (sptr != NULL ? saltlen : 0); - if (!PKCS5_PBKDF2_HMAC(str, str_len, sptr, islen, + if (!PKCS5_PBKDF2_HMAC(str, (int)str_len, sptr, islen, iter, dgst, iklen+ivlen, tmpkeyiv)) { BIO_printf(bio_err, "PKCS5_PBKDF2_HMAC failed\n"); goto end; @@ -596,7 +596,7 @@ int enc_main(int argc, char **argv) "deprecated key derivation used.\n" "Using -iter or -pbkdf2 would be better.\n"); if (!EVP_BytesToKey(cipher, dgst, sptr, - (unsigned char *)str, str_len, + (unsigned char *)str, (int)str_len, 1, key, iv)) { BIO_printf(bio_err, "EVP_BytesToKey failed\n"); goto end; @@ -825,7 +825,7 @@ static int set_hex(const char *in, unsigned char *out, int size) unsigned char j; i = size * 2; - n = strlen(in); + n = (int)strlen(in); if (n > i) { BIO_printf(bio_err, "hex string is too long, ignoring excess\n"); n = i; /* ignore exceeding part */ diff --git a/apps/engine.c b/apps/engine.c index edd78751488..90e3e8be3fc 100644 --- a/apps/engine.c +++ b/apps/engine.c @@ -55,14 +55,14 @@ const OPTIONS engine_options[] = { static int append_buf(char **buf, int *size, const char *s) { const int expand = 256; - int len = strlen(s) + 1; + int len = (int)(strlen(s) + 1); char *p = *buf; if (p == NULL) { *size = ((len + expand - 1) / expand) * expand; p = *buf = app_malloc(*size, "engine buffer"); } else { - const int blen = strlen(p); + const int blen = (int)strlen(p); if (blen > 0) len += 2 + blen; diff --git a/apps/fipsinstall.c b/apps/fipsinstall.c index 0daa55a1b8a..1bece042e6e 100644 --- a/apps/fipsinstall.c +++ b/apps/fipsinstall.c @@ -853,7 +853,7 @@ int fipsinstall_main(int argc, char **argv) /* Calculate the MAC for the indicator status - it may not be used */ mem_bio = BIO_new_mem_buf((const void *)INSTALL_STATUS_VAL, - strlen(INSTALL_STATUS_VAL)); + (int)strlen(INSTALL_STATUS_VAL)); if (mem_bio == NULL) { BIO_printf(bio_err, "Unable to create memory BIO\n"); goto end; diff --git a/apps/kdf.c b/apps/kdf.c index 89ee1f69c76..8be5fed2a0e 100644 --- a/apps/kdf.c +++ b/apps/kdf.c @@ -75,7 +75,7 @@ int kdf_main(int argc, char **argv) char *prog, *hexout = NULL; const char *outfile = NULL; unsigned char *dkm_bytes = NULL; - size_t dkm_len = 0; + int dkm_len = 0; BIO *out = NULL; EVP_KDF *kdf = NULL; EVP_KDF_CTX *ctx = NULL; @@ -96,7 +96,7 @@ opthelp: out_bin = 1; break; case OPT_KEYLEN: - dkm_len = (size_t)atoi(opt_arg()); + dkm_len = atoi(opt_arg()); break; case OPT_OUT: outfile = opt_arg(); diff --git a/apps/list.c b/apps/list.c index 8421876fdd7..2aeedbbda89 100644 --- a/apps/list.c +++ b/apps/list.c @@ -847,7 +847,7 @@ static void list_tls_groups(int version, int all) { SSL_CTX *ctx = NULL; STACK_OF(OPENSSL_CSTRING) *groups; - size_t i, num; + int i, num; if ((groups = sk_OPENSSL_CSTRING_new_null()) == NULL) { BIO_printf(bio_err, "ERROR: Memory allocation\n"); diff --git a/apps/mac.c b/apps/mac.c index 0a07b2ea433..eb835335fc1 100644 --- a/apps/mac.c +++ b/apps/mac.c @@ -212,7 +212,7 @@ opthelp: } if (out_bin) { - BIO_write(out, buf, len); + BIO_write(out, buf, (int)len); } else { for (i = 0; i < (int)len; ++i) BIO_printf(out, "%02X", buf[i]); diff --git a/apps/openssl.c b/apps/openssl.c index f0f9a5cdcdd..da0fc9db3ff 100644 --- a/apps/openssl.c +++ b/apps/openssl.c @@ -132,8 +132,10 @@ static size_t internal_trace_cb(const char *buf, size_t cnt, BIO_printf(bio_err, "ERROR: writing when tracing not started\n"); return 0; } + if (cnt > INT_MAX) + cnt = INT_MAX; - ret = BIO_write(trace_data->bio, buf, cnt); + ret = BIO_write(trace_data->bio, buf, (int)cnt); break; case OSSL_TRACE_CTRL_END: if (!trace_data->ingroup) { diff --git a/apps/passwd.c b/apps/passwd.c index 8b233538d87..e16f73473e5 100644 --- a/apps/passwd.c +++ b/apps/passwd.c @@ -241,7 +241,7 @@ int passwd_main(int argc, char **argv) passwds = passwds_static; if (in == NULL) { if (EVP_read_pw_string - (passwd_malloc, passwd_malloc_size, "Password: ", + (passwd_malloc, (int)passwd_malloc_size, "Password: ", !(passed_salt || in_noverify)) != 0) goto end; } @@ -269,7 +269,7 @@ int passwd_main(int argc, char **argv) assert(passwd != NULL); do { - int r = BIO_gets(in, passwd, pw_maxlen + 1); + int r = BIO_gets(in, passwd, (int)(pw_maxlen + 1)); if (r > 0) { char *c = (strchr(passwd, '\n')); if (c != NULL) { @@ -395,14 +395,14 @@ static char *md5crypt(const char *passwd, const char *magic, const char *salt) || !EVP_DigestFinal_ex(md2, buf, NULL)) goto err; - for (i = passwd_len; i > sizeof(buf); i -= sizeof(buf)) { + for (i = (unsigned int)passwd_len; i > sizeof(buf); i -= sizeof(buf)) { if (!EVP_DigestUpdate(md, buf, sizeof(buf))) goto err; } if (!EVP_DigestUpdate(md, buf, i)) goto err; - n = passwd_len; + n = (int)passwd_len; while (n) { if (!EVP_DigestUpdate(md, (n & 1) ? "\0" : passwd, 1)) goto err; @@ -797,7 +797,7 @@ static int do_passwd(int passed_salt, char **salt_p, char **salt_malloc_p, if (*salt_malloc_p == NULL) *salt_p = *salt_malloc_p = app_malloc(saltlen + 1, "salt buffer"); - if (RAND_bytes((unsigned char *)*salt_p, saltlen) <= 0) + if (RAND_bytes((unsigned char *)*salt_p, (int)saltlen) <= 0) goto end; for (i = 0; i < saltlen; i++) diff --git a/apps/pkcs8.c b/apps/pkcs8.c index 22978afb909..407da0357c7 100644 --- a/apps/pkcs8.c +++ b/apps/pkcs8.c @@ -284,7 +284,7 @@ int pkcs8_main(int argc, char **argv) BIO_printf(bio_err, "Password required\n"); goto end; } - p8 = PKCS8_set0_pbe(p8pass, strlen(p8pass), p8inf, pbe); + p8 = PKCS8_set0_pbe(p8pass, (int)strlen(p8pass), p8inf, pbe); if (p8 == NULL) { X509_ALGOR_free(pbe); BIO_printf(bio_err, "Error encrypting key\n"); @@ -344,7 +344,7 @@ int pkcs8_main(int argc, char **argv) BIO_printf(bio_err, "Password required\n"); goto end; } - p8inf = PKCS8_decrypt(p8, p8pass, strlen(p8pass)); + p8inf = PKCS8_decrypt(p8, p8pass, (int)strlen(p8pass)); } if (p8inf == NULL) { diff --git a/apps/pkeyutl.c b/apps/pkeyutl.c index 79ad4c6f29f..900af11c38b 100644 --- a/apps/pkeyutl.c +++ b/apps/pkeyutl.c @@ -550,14 +550,14 @@ int pkeyutl_main(int argc, char **argv) if (rawin) { /* rawin allocates the buffer in do_raw_keyop() */ rv = do_raw_keyop(pkey_op, mctx, pkey, in, filesize, NULL, 0, - &buf_out, (size_t *)&buf_outlen); + &buf_out, &buf_outlen); } else { if (kdflen != 0) { buf_outlen = kdflen; rv = 1; } else { - rv = do_keyop(ctx, pkey_op, NULL, (size_t *)&buf_outlen, - buf_in, (size_t)buf_inlen, NULL, (size_t *)&secretlen); + rv = do_keyop(ctx, pkey_op, NULL, &buf_outlen, + buf_in, (size_t)buf_inlen, NULL, &secretlen); } if (rv > 0 && (secretlen > 0 || (pkey_op != EVP_PKEY_OP_ENCAPSULATE @@ -568,8 +568,8 @@ int pkeyutl_main(int argc, char **argv) if (secretlen > 0) secret = app_malloc(secretlen, "secret output"); rv = do_keyop(ctx, pkey_op, - buf_out, (size_t *)&buf_outlen, - buf_in, (size_t)buf_inlen, secret, (size_t *)&secretlen); + buf_out, &buf_outlen, + buf_in, (size_t)buf_inlen, secret, &secretlen); } } if (rv <= 0) { @@ -583,16 +583,16 @@ int pkeyutl_main(int argc, char **argv) ret = 0; if (asn1parse) { - if (!ASN1_parse_dump(out, buf_out, buf_outlen, 1, -1)) + if (!ASN1_parse_dump(out, buf_out, (long)buf_outlen, 1, -1)) ERR_print_errors(bio_err); /* but still return success */ } else if (hexdump) { - BIO_dump(out, (char *)buf_out, buf_outlen); + BIO_dump(out, (char *)buf_out, (int)buf_outlen); } else { - BIO_write(out, buf_out, buf_outlen); + BIO_write(out, buf_out, (int)buf_outlen); } /* Backwards compatible decap output fallback */ if (secretlen > 0) - BIO_write(secout ? secout : out, secret, secretlen); + BIO_write(secout ? secout : out, secret, (int)secretlen); end: if (ret != 0) diff --git a/apps/prime.c b/apps/prime.c index fbc20ccb311..8241c3eae01 100644 --- a/apps/prime.c +++ b/apps/prime.c @@ -173,7 +173,6 @@ opthelp: } else { for ( ; *argv; argv++) { int bytes_read = 0; - int valid_digits_length = 0; if (!in_file) { process_num(argv[0], hex); @@ -185,6 +184,8 @@ opthelp: } while ((bytes_read = BIO_get_line(in, file_read_buf, BUFSIZE)) > 0) { + size_t valid_digits_length; + /* Number is too long. Discard remainder of the line */ if (bytes_read == BUFSIZE - 1 && file_read_buf[BUFSIZE - 2] != '\n') { BIO_printf(bio_err, "Value in %s is over the maximum size (%d digits)\n", diff --git a/apps/req.c b/apps/req.c index c5627ffda54..d0368a76925 100644 --- a/apps/req.c +++ b/apps/req.c @@ -1418,7 +1418,7 @@ static int build_data(char *text, const char *def, char *value, return 1; } - i = strlen(buf); + i = (int)strlen(buf); if (buf[i - 1] != '\n') { BIO_printf(bio_err, "Missing newline at end of input\n"); return 0; @@ -1512,9 +1512,9 @@ static EVP_PKEY_CTX *set_keygen_ctx(const char *gstr, int len; if (p != NULL) - len = p - gstr; + len = (int)(p - gstr); else - len = strlen(gstr); + len = (int)strlen(gstr); if (strncmp(gstr, "param", len) == 0) { expect_paramfile = 1; diff --git a/apps/rsautl.c b/apps/rsautl.c index 3ee8224f48d..c4720a674eb 100644 --- a/apps/rsautl.c +++ b/apps/rsautl.c @@ -271,13 +271,13 @@ int rsautl_main(int argc, char **argv) } ret = 0; if (asn1parse) { - if (!ASN1_parse_dump(out, rsa_out, rsa_outlen, 1, -1)) { + if (!ASN1_parse_dump(out, rsa_out, (long)rsa_outlen, 1, -1)) { ERR_print_errors(bio_err); } } else if (hexdump) { - BIO_dump(out, (char *)rsa_out, rsa_outlen); + BIO_dump(out, (char *)rsa_out, (int)rsa_outlen); } else { - BIO_write(out, rsa_out, rsa_outlen); + BIO_write(out, rsa_out, (int)rsa_outlen); } end: EVP_PKEY_CTX_free(ctx); diff --git a/apps/s_client.c b/apps/s_client.c index c2bda406b8f..dbef77ec03a 100644 --- a/apps/s_client.c +++ b/apps/s_client.c @@ -311,7 +311,8 @@ static int next_proto_cb(SSL *s, unsigned char **out, unsigned char *outlen, } ctx->status = - SSL_select_next_proto(out, outlen, in, inlen, ctx->data, ctx->len); + SSL_select_next_proto(out, outlen, in, inlen, + ctx->data, (unsigned int)ctx->len); return SSL_TLSEXT_ERR_OK; } #endif /* ndef OPENSSL_NO_NEXTPROTONEG */ @@ -333,7 +334,7 @@ static int serverinfo_cli_parse_cb(SSL *s, unsigned int ext_type, BIO_snprintf(pem_name, sizeof(pem_name), "SERVERINFO FOR EXTENSION %d", ext_type); - PEM_write_bio(bio_c_out, pem_name, "", ext_buf, 4 + inlen); + PEM_write_bio(bio_c_out, pem_name, "", ext_buf, (long)(4 + inlen)); return 1; } @@ -1482,7 +1483,7 @@ int s_client_main(int argc, char **argv) break; case OPT_SERVERINFO: p = opt_arg(); - len = strlen(p); + len = (int)strlen(p); for (start = 0, i = 0; i <= len; ++i) { if (i == len || p[i] == ',') { serverinfo_types[serverinfo_count] = atoi(p + start); @@ -1965,7 +1966,7 @@ int s_client_main(int argc, char **argv) goto end; } /* Returns 0 on success! */ - if (SSL_CTX_set_alpn_protos(ctx, alpn, alpn_len) != 0) { + if (SSL_CTX_set_alpn_protos(ctx, alpn, (unsigned int)alpn_len) != 0) { BIO_printf(bio_err, "Error setting ALPN\n"); goto end; } @@ -3687,7 +3688,7 @@ static int ldap_ExtendedResponse_parse(const char *buf, long rem) /* pull SEQUENCE */ inf = ASN1_get_object(&cur, &len, &tag, &xclass, rem); if (inf != V_ASN1_CONSTRUCTED || tag != V_ASN1_SEQUENCE || - (rem = end - cur, len > rem)) { + (rem = (long)(end - cur), len > rem)) { BIO_printf(bio_err, "Unexpected LDAP response\n"); goto end; } @@ -3697,7 +3698,7 @@ static int ldap_ExtendedResponse_parse(const char *buf, long rem) /* pull MessageID */ inf = ASN1_get_object(&cur, &len, &tag, &xclass, rem); if (inf != V_ASN1_UNIVERSAL || tag != V_ASN1_INTEGER || - (rem = end - cur, len > rem)) { + (rem = (long)(end - cur), len > rem)) { BIO_printf(bio_err, "No MessageID\n"); goto end; } @@ -3705,7 +3706,7 @@ static int ldap_ExtendedResponse_parse(const char *buf, long rem) cur += len; /* shall we check for MessageId match or just skip? */ /* pull [APPLICATION 24] */ - rem = end - cur; + rem = (long)(end - cur); inf = ASN1_get_object(&cur, &len, &tag, &xclass, rem); if (inf != V_ASN1_CONSTRUCTED || xclass != V_ASN1_APPLICATION || tag != 24) { @@ -3714,10 +3715,10 @@ static int ldap_ExtendedResponse_parse(const char *buf, long rem) } /* pull resultCode */ - rem = end - cur; + rem = (long)(end - cur); inf = ASN1_get_object(&cur, &len, &tag, &xclass, rem); if (inf != V_ASN1_UNIVERSAL || tag != V_ASN1_ENUMERATED || len == 0 || - (rem = end - cur, len > rem)) { + (rem = (long)(end - cur), len > rem)) { BIO_printf(bio_err, "Not LDAPResult\n"); goto end; } diff --git a/apps/s_server.c b/apps/s_server.c index 8a36122a25b..13809de8198 100644 --- a/apps/s_server.c +++ b/apps/s_server.c @@ -660,7 +660,7 @@ static int next_proto_cb(SSL *s, const unsigned char **data, tlsextnextprotoctx *next_proto = arg; *data = next_proto->data; - *len = next_proto->len; + *len = (unsigned int)next_proto->len; return SSL_TLSEXT_ERR_OK; } @@ -691,8 +691,8 @@ static int alpn_cb(SSL *s, const unsigned char **out, unsigned char *outlen, } if (SSL_select_next_proto - ((unsigned char **)out, outlen, alpn_ctx->data, alpn_ctx->len, in, - inlen) != OPENSSL_NPN_NEGOTIATED) { + ((unsigned char **)out, outlen, alpn_ctx->data, + (unsigned int)alpn_ctx->len, in, inlen) != OPENSSL_NPN_NEGOTIATED) { return SSL_TLSEXT_ERR_ALERT_FATAL; } @@ -2476,7 +2476,7 @@ static int sv_body(int s, int stype, int prot, unsigned char *context) if (context != NULL && !SSL_set_session_id_context(con, context, - strlen((char *)context))) { + (unsigned int)strlen((char *)context))) { BIO_printf(bio_err, "Error setting session id context\n"); ret = -1; goto err; @@ -3205,7 +3205,7 @@ static int www_body(int s, int stype, int prot, unsigned char *context) if (context != NULL && !SSL_set_session_id_context(con, context, - strlen((char *)context))) { + (unsigned int)strlen((char *)context))) { SSL_free(con); goto err; } @@ -3518,7 +3518,7 @@ static int www_body(int s, int stype, int prot, unsigned char *context) BIO_printf(bio_err, "FILE:%s\n", p); if (www == 2) { - i = strlen(p); + i = (int)strlen(p); if (((i > 5) && (strcmp(&(p[i - 5]), ".html") == 0)) || ((i > 4) && (strcmp(&(p[i - 4]), ".php") == 0)) || ((i > 4) && (strcmp(&(p[i - 4]), ".htm") == 0))) @@ -3667,7 +3667,7 @@ static int rev_body(int s, int stype, int prot, unsigned char *context) } if (context != NULL && !SSL_set_session_id_context(con, context, - strlen((char *)context))) { + (unsigned int)strlen((char *)context))) { SSL_free(con); ERR_print_errors(bio_err); goto err; @@ -3798,7 +3798,7 @@ static int generate_session_id(SSL *ssl, unsigned char *id, unsigned int *id_len) { unsigned int count = 0; - unsigned int session_id_prefix_len = strlen(session_id_prefix); + unsigned int session_id_prefix_len = (unsigned int)strlen(session_id_prefix); do { if (RAND_bytes(id, *id_len) <= 0) diff --git a/apps/sess_id.c b/apps/sess_id.c index 54b3d055634..c19669b2612 100644 --- a/apps/sess_id.c +++ b/apps/sess_id.c @@ -114,7 +114,7 @@ int sess_id_main(int argc, char **argv) goto end; } if (!SSL_SESSION_set1_id_context(x, (unsigned char *)context, - ctx_len)) { + (unsigned int)ctx_len)) { BIO_printf(bio_err, "Error setting id context\n"); goto end; } diff --git a/apps/speed.c b/apps/speed.c index 6c1eb59e91e..2c3ec37d123 100644 --- a/apps/speed.c +++ b/apps/speed.c @@ -2727,7 +2727,7 @@ int speed_main(int argc, char **argv) if (doit[D_HMAC]) { static const char hmac_key[] = "This is a key..."; - int len = strlen(hmac_key); + int len = (int)strlen(hmac_key); size_t hmac_name_len = sizeof("hmac()") + strlen(evp_mac_mdname); OSSL_PARAM params[3]; @@ -5128,7 +5128,7 @@ static void multiblock_speed(const EVP_CIPHER *evp_cipher, int lengths_single, aad[12] = (unsigned char)(len); pad = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_TLS1_AAD, EVP_AEAD_TLS1_AAD_LEN, aad); - ciph_success = EVP_Cipher(ctx, out, inp, len + pad); + ciph_success = EVP_Cipher(ctx, out, inp, (unsigned int)(len + pad)); } } d = Time_F(STOP); diff --git a/apps/x509.c b/apps/x509.c index 4d6709367f0..6051d8642f0 100644 --- a/apps/x509.c +++ b/apps/x509.c @@ -1258,7 +1258,7 @@ static int parse_ext_names(char *names, const char **result) int cnt = 0, len = 0; p = q = names; - len = strlen(names); + len = (int)strlen(names); while (q - names <= len) { if (*q != ',' && *q != '\0') {