From 4be25979a6b3e2a79d7c9667b07db8b09fb046e9 Mon Sep 17 00:00:00 2001
From: Werner Koch <wk@gnupg.org>
Date: Thu, 13 Mar 2025 11:35:34 +0100
Subject: [PATCH] gpg: Fix double free of internal data.

* g10/sig-check.c (check_signature_over_key_or_uid): Do not free in
no-sig-cache mode if allocated by caller.
--

GnuPG-bug-id: 7547
Fixes-commit: 44cdb9d73f1a0b7d2c8483a119b9c4d6caabc1ec

CVE: CVE-2025-30258
Upstream-Status: Backport [https://dev.gnupg.org/rG4be25979a6b3e2a79d7c9667b07db8b09fb046e9]

Signed-off-by: Yogita Urade <yogita.urade@windriver.com>
---
 g10/sig-check.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/g10/sig-check.c b/g10/sig-check.c
index 11f3e0c..a8fbdc7 100644
--- a/g10/sig-check.c
+++ b/g10/sig-check.c
@@ -1013,7 +1013,8 @@ check_signature_over_key_or_uid (ctrl_t ctrl, PKT_public_key *signer,
               rc = get_pubkey_for_sig (ctrl, signer, sig, NULL, NULL);
               if (rc)
                 {
-                  xfree (signer);
+                  if (signer_alloced != 1)
+                    xfree (signer);
                   signer = NULL;
                   signer_alloced = 0;
                   goto leave;
--
2.40.0
