]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Fix FreeBSD builds with WARNS=6 (#1869)
authorEnji Cooper <1574099+ngie-eign@users.noreply.github.com>
Sat, 13 May 2023 04:11:07 +0000 (21:11 -0700)
committerGitHub <noreply@github.com>
Sat, 13 May 2023 04:11:07 +0000 (21:11 -0700)
WARNS=6 on FreeBSD passes several CFLAGS that causes the previous code
to fail with `-Wincompatible-pointer-types-discards-qualifiers` when
compiled with clang.

This particular change adjusts the code to be
`-Wincompatible-pointer-types-discards-qualifiers` clean. This change
changes the calls to use OSSL_PARAM macro abbreviated calls, instead of
calling more verbose (and less documented) callers.

While here, also address a `mac` object leak if `ctx` cannot be
allocated cleanly by always free'ing `mac` after it's been attached to
`ctx`.

Co-authored-by: Pierre Pronchery <pierre@freebsdfoundation.org>
Sponsored by: The FreeBSD Foundation
Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>

libarchive/archive_hmac.c
libarchive/archive_hmac_private.h

index 012fe1596211d327d833b593d63d74b955446852..edb3bf5abd42102f4de40a79451e43a2654196ae 100644 (file)
@@ -231,15 +231,20 @@ static int
 __hmac_sha1_init(archive_hmac_sha1_ctx *ctx, const uint8_t *key, size_t key_len)
 {
 #if OPENSSL_VERSION_NUMBER >= 0x30000000L
-       OSSL_PARAM params[2];
+       EVP_MAC *mac;
 
-       EVP_MAC *mac = EVP_MAC_fetch(NULL, "HMAC", NULL);
+       char sha1[] = "SHA1";
+       OSSL_PARAM params[] = {
+               OSSL_PARAM_utf8_string("digest", sha1, sizeof(sha1) - 1),
+               OSSL_PARAM_END
+       };
+
+       mac = EVP_MAC_fetch(NULL, "HMAC", NULL);
        *ctx = EVP_MAC_CTX_new(mac);
+       EVP_MAC_free(mac);
        if (*ctx == NULL)
                return -1;
-       EVP_MAC_free(mac);
-       params[0] = OSSL_PARAM_construct_utf8_string("digest", "SHA1", 0);
-       params[1] = OSSL_PARAM_construct_end();
+
        EVP_MAC_init(*ctx, key, key_len, params);
 #else
        *ctx = HMAC_CTX_new();
index 50044a045e377bd75f65eff028fafddc8b216f09..d0fda7f9667a01d999b9da0e408167f194b779cd 100644 (file)
@@ -77,6 +77,8 @@ typedef       struct hmac_sha1_ctx archive_hmac_sha1_ctx;
 #include <openssl/opensslv.h>
 #include <openssl/hmac.h>
 #if OPENSSL_VERSION_NUMBER >= 0x30000000L
+#include <openssl/params.h>
+
 typedef EVP_MAC_CTX *archive_hmac_sha1_ctx;
 
 #else