Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: "Kacper Michajłow" <kasper93@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Cc: "Kacper Michajłow" <kasper93@gmail.com>
Subject: [FFmpeg-devel] [PATCH] avutil/hmac: avoid calling functions through pointer of invalid type
Date: Thu, 17 Jul 2025 22:38:13 +0200
Message-ID: <20250717203813.85994-1-kasper93@gmail.com> (raw)

Add type removed function wrappers to resolve UB of calling function
through pointer to incorrect function type.

Fixes: call to function av_md5_init through pointer to incorrect
       function type 'void (*)(void *)' and similar for others.
Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
---
 libavutil/hmac.c | 68 +++++++++++++++++++++++++++++-------------------
 1 file changed, 41 insertions(+), 27 deletions(-)

diff --git a/libavutil/hmac.c b/libavutil/hmac.c
index 302d7b04cf..6daca00b8f 100644
--- a/libavutil/hmac.c
+++ b/libavutil/hmac.c
@@ -47,23 +47,37 @@ struct AVHMAC {
     int keylen;
 };
 
-#define DEFINE_SHA(bits)                           \
-static av_cold void sha ## bits ##_init(void *ctx) \
+#define DEFINE_ALGO_BITS_INIT(prefix, bits)        \
+static av_cold void prefix##bits##_init(void *ctx) \
 {                                                  \
-    av_sha_init(ctx, bits);                        \
+    av_##prefix##_init(ctx, bits);                 \
 }
 
-#define DEFINE_SHA512(bits)                        \
-static av_cold void sha ## bits ##_init(void *ctx) \
-{                                                  \
-    av_sha512_init(ctx, bits);                     \
+#define DEFINE_ALGO_INIT(prefix)             \
+static av_cold void prefix##_init(void *ctx) \
+{                                            \
+    av_##prefix##_init(ctx);                 \
+}
+
+#define DEFINE_ALGO(prefix)                                            \
+static void prefix##_update(void *ctx, const uint8_t *src, size_t len) \
+{                                                                      \
+    av_##prefix##_update(ctx, src, len);                               \
+}                                                                      \
+static void prefix##_final(void *ctx, uint8_t *dst)                    \
+{                                                                      \
+    av_##prefix##_final(ctx, dst);                                     \
 }
 
-DEFINE_SHA(160)
-DEFINE_SHA(224)
-DEFINE_SHA(256)
-DEFINE_SHA512(384)
-DEFINE_SHA512(512)
+DEFINE_ALGO_INIT(md5)
+DEFINE_ALGO_BITS_INIT(sha, 160)
+DEFINE_ALGO_BITS_INIT(sha, 224)
+DEFINE_ALGO_BITS_INIT(sha, 256)
+DEFINE_ALGO_BITS_INIT(sha512, 384)
+DEFINE_ALGO_BITS_INIT(sha512, 512)
+DEFINE_ALGO(md5)
+DEFINE_ALGO(sha)
+DEFINE_ALGO(sha512)
 
 AVHMAC *av_hmac_alloc(enum AVHMACType type)
 {
@@ -74,49 +88,49 @@ AVHMAC *av_hmac_alloc(enum AVHMACType type)
     case AV_HMAC_MD5:
         c->blocklen = 64;
         c->hashlen  = 16;
-        c->init     = (hmac_init) av_md5_init;
-        c->update   = (hmac_update) av_md5_update;
-        c->final    = (hmac_final) av_md5_final;
+        c->init     = md5_init;
+        c->update   = md5_update;
+        c->final    = md5_final;
         c->hash     = av_md5_alloc();
         break;
     case AV_HMAC_SHA1:
         c->blocklen = 64;
         c->hashlen  = 20;
         c->init     = sha160_init;
-        c->update   = (hmac_update) av_sha_update;
-        c->final    = (hmac_final) av_sha_final;
+        c->update   = sha_update;
+        c->final    = sha_final;
         c->hash     = av_sha_alloc();
         break;
     case AV_HMAC_SHA224:
         c->blocklen = 64;
         c->hashlen  = 28;
         c->init     = sha224_init;
-        c->update   = (hmac_update) av_sha_update;
-        c->final    = (hmac_final) av_sha_final;
+        c->update   = sha_update;
+        c->final    = sha_final;
         c->hash     = av_sha_alloc();
         break;
     case AV_HMAC_SHA256:
         c->blocklen = 64;
         c->hashlen  = 32;
         c->init     = sha256_init;
-        c->update   = (hmac_update) av_sha_update;
-        c->final    = (hmac_final) av_sha_final;
+        c->update   = sha_update;
+        c->final    = sha_final;
         c->hash     = av_sha_alloc();
         break;
     case AV_HMAC_SHA384:
         c->blocklen = 128;
         c->hashlen  = 48;
-        c->init     = sha384_init;
-        c->update   = (hmac_update) av_sha512_update;
-        c->final    = (hmac_final) av_sha512_final;
+        c->init     = sha512384_init;
+        c->update   = sha512_update;
+        c->final    = sha512_final;
         c->hash     = av_sha512_alloc();
         break;
     case AV_HMAC_SHA512:
         c->blocklen = 128;
         c->hashlen  = 64;
-        c->init     = sha512_init;
-        c->update   = (hmac_update) av_sha512_update;
-        c->final    = (hmac_final) av_sha512_final;
+        c->init     = sha512512_init;
+        c->update   = sha512_update;
+        c->final    = sha512_final;
         c->hash     = av_sha512_alloc();
         break;
     default:
-- 
2.50.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

                 reply	other threads:[~2025-07-17 20:38 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250717203813.85994-1-kasper93@gmail.com \
    --to=kasper93@gmail.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git