[vlc-commits] [Git][videolan/vlc][master] keystore: avoid dirty function pointer casts

Steve Lhomme (@robUx4) gitlab at videolan.org
Wed Jan 29 14:57:23 UTC 2025



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
837f9778 by Steve Lhomme at 2025-01-29T13:53:37+00:00
keystore: avoid dirty function pointer casts

Especially when mixing LPCWSTR and LPWSTR*.

- - - - -


1 changed file:

- modules/keystore/file_crypt_win32.c


Changes:

=====================================
modules/keystore/file_crypt_win32.c
=====================================
@@ -28,8 +28,17 @@
 #include <windows.h>
 #include <dpapi.h>
 
-typedef BOOL (WINAPI *ProcessFunc)(DATA_BLOB*, LPCWSTR, DATA_BLOB*, PVOID,
-                                   CRYPTPROTECT_PROMPTSTRUCT*, DWORD, DATA_BLOB*);
+typedef BOOL (*ProcessFunc)(DATA_BLOB*, DATA_BLOB*);
+
+static BOOL FuncProtect(DATA_BLOB *input_blob, DATA_BLOB *output_blob)
+{
+    return CryptProtectData( input_blob, NULL, NULL, NULL, NULL, CRYPTPROTECT_UI_FORBIDDEN, output_blob);
+}
+
+static BOOL FuncUnprotect(DATA_BLOB *input_blob, DATA_BLOB *output_blob)
+{
+    return CryptUnprotectData( input_blob, NULL, NULL, NULL, NULL, CRYPTPROTECT_UI_FORBIDDEN, output_blob);
+}
 
 static size_t Process(const uint8_t *p_src, size_t i_src_len, uint8_t **pp_dst, ProcessFunc pf_process)
 {
@@ -40,7 +49,7 @@ static size_t Process(const uint8_t *p_src, size_t i_src_len, uint8_t **pp_dst,
     };
     DATA_BLOB output_blob;
 
-    if (pf_process( &input_blob, NULL, NULL, NULL, NULL, CRYPTPROTECT_UI_FORBIDDEN, &output_blob) == FALSE)
+    if (pf_process( &input_blob, &output_blob) == FALSE)
         return 0;
     *pp_dst = malloc(output_blob.cbData);
     if( unlikely( *pp_dst == NULL ) )
@@ -58,10 +67,7 @@ static size_t Decrypt( vlc_keystore *p_keystore, void *p_ctx, const uint8_t *p_s
 {
     VLC_UNUSED( p_keystore );
     VLC_UNUSED( p_ctx );
-    // Cast the function pointer to avoid an invalid parameter warning, regarding the "description"
-    // parameter. It's LPCWSTR in the case of CryptProtectData, and LPWSTR* in the case of CryptUnprotect
-    // Since we pass NULL anyway, we don't care
-    return Process( p_src, i_src_len, pp_dst, (ProcessFunc)&CryptUnprotectData );
+    return Process( p_src, i_src_len, pp_dst, FuncUnprotect );
 }
 
 static size_t Encrypt( vlc_keystore *p_keystore, void *p_ctx, const uint8_t *p_src,
@@ -69,7 +75,7 @@ static size_t Encrypt( vlc_keystore *p_keystore, void *p_ctx, const uint8_t *p_s
 {
     VLC_UNUSED( p_keystore );
     VLC_UNUSED( p_ctx );
-    return Process( p_src, i_src_len, pp_dst, CryptProtectData );
+    return Process( p_src, i_src_len, pp_dst, FuncProtect );
 }
 
 int CryptInit(vlc_keystore *p_keystore, struct crypt *p_crypt)



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/837f9778eee974e5274b9c84aad3a78b894ba1e9

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/837f9778eee974e5274b9c84aad3a78b894ba1e9
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list