File: 0034-gpg-Fix-memory-leak-in-the-error-case-of-signature-c.patch

package info (click to toggle)
gnupg2 2.1.18-8~deb9u4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 46,748 kB
  • sloc: ansic: 222,789; sh: 7,531; lisp: 5,090; makefile: 1,459; awk: 126; sed: 16; python: 16; php: 14; perl: 13
file content (51 lines) | stat: -rw-r--r-- 1,690 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
From: Werner Koch <wk@gnupg.org>
Date: Fri, 10 Feb 2017 17:16:07 +0100
Subject: gpg: Fix memory leak in the error case of signature creation.
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit

* g10/sign.c (write_signature_packets): Free SIG.  Also replace
xcalloc by xtrycalloc.
--

If do_sign fails SIG was not released.  Note that in the good case SIG
is transferred to PKT and freed by free_packet.

Reported-by: Stephan Müller
Signed-off-by: Werner Koch <wk@gnupg.org>
(cherry picked from commit 5996c7bf99f3a681393fd9589276399ebc956cff)
---
 g10/sign.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/g10/sign.c b/g10/sign.c
index acc894c49..ff099b31c 100644
--- a/g10/sign.c
+++ b/g10/sign.c
@@ -686,7 +686,10 @@ write_signature_packets (SK_LIST sk_list, IOBUF out, gcry_md_hd_t hash,
       pk = sk_rover->pk;
 
       /* Build the signature packet.  */
-      sig = xmalloc_clear (sizeof *sig);
+      sig = xtrycalloc (1, sizeof *sig);
+      if (!sig)
+        return gpg_error_from_syserror ();
+
       if (duration || opt.sig_policy_url
           || opt.sig_notations || opt.sig_keyserver_url)
         sig->version = 4;
@@ -731,8 +734,12 @@ write_signature_packets (SK_LIST sk_list, IOBUF out, gcry_md_hd_t hash,
             print_status_sig_created (pk, sig, status_letter);
           free_packet (&pkt);
           if (rc)
-            log_error ("build signature packet failed: %s\n", gpg_strerror (rc));
+            log_error ("build signature packet failed: %s\n",
+                       gpg_strerror (rc));
 	}
+      else
+        xfree (sig);
+
       if (rc)
         return rc;
     }