]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Fix archive_wincrypt_version compilation
authorTobias Stoeckmann <tobias@stoeckmann.org>
Fri, 23 May 2025 16:59:05 +0000 (18:59 +0200)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Fri, 23 May 2025 17:05:21 +0000 (19:05 +0200)
Cast address of "version" to BYTE pointer for CryptGetProvParam.
Fix "major" variable assignment for picky compilers like MSVC.

The "length" variable is an in/out variable. It must be set to the size
of available memory within "version". Right now it is undefined behavior
and 0 would crash during runtime.

Fixes https://github.com/libarchive/libarchive/issues/2628

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
libarchive/archive_version_details.c

index 186e53e50c843dc43602404290bf7a91fb545255..0bd566473d47066b90584639fb3df14df7fb2da5 100644 (file)
@@ -439,11 +439,11 @@ archive_wincrypt_version(void)
                if (!CryptAcquireContext(&prov, NULL, NULL, PROV_RSA_FULL, CRYPT_NEWKEYSET))
                        return NULL;
        }
-       DWORD length, version;
-       if (!CryptGetProvParam(prov, PP_VERSION, &version, &length, 0)) {
+       DWORD version, length = sizeof(version);
+       if (!CryptGetProvParam(prov, PP_VERSION, (BYTE *)&version, &length, 0)) {
                return NULL;
        } else {
-               char major = version >> 8;
+               char major = (version >> 8) & 0xFF;
                char minor = version & 0xFF;
                static char wincrypt_version[6];
                snprintf(wincrypt_version, 6, "%hhd.%hhd", major, minor);