git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gpg-interface.c: Fix potentially freeing NULL values
@ 2018-08-17  9:17 Michał Górny
  2018-08-17  9:28 ` Eric Sunshine
  0 siblings, 1 reply; 12+ messages in thread
From: Michał Górny @ 2018-08-17  9:17 UTC (permalink / raw)
  To: git; +Cc: Michał Górny

Fix signature_check_clear() to free only values that are non-NULL.  This
especially applies to 'key' and 'signer' members that can be NULL during
normal operations, depending on exact GnuPG output.  While at it, also
allow other members to be NULL to make the function easier to use,
even if there is no real need to account for that right now.

Signed-off-by: Michał Górny <mgorny@gentoo.org>
---
 gpg-interface.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/gpg-interface.c b/gpg-interface.c
index 35c25106a..9aedaf464 100644
--- a/gpg-interface.c
+++ b/gpg-interface.c
@@ -15,9 +15,14 @@ static const char *gpg_program = "gpg";
 void signature_check_clear(struct signature_check *sigc)
 {
-	FREE_AND_NULL(sigc->payload);
-	FREE_AND_NULL(sigc->gpg_output);
-	FREE_AND_NULL(sigc->gpg_status);
-	FREE_AND_NULL(sigc->signer);
-	FREE_AND_NULL(sigc->key);
+	if (sigc->payload)
+		FREE_AND_NULL(sigc->payload);
+	if (sigc->gpg_output)
+		FREE_AND_NULL(sigc->gpg_output);
+	if (sigc->gpg_status)
+		FREE_AND_NULL(sigc->gpg_status);
+	if (sigc->signer)
+		FREE_AND_NULL(sigc->signer);
+	if (sigc->key)
+		FREE_AND_NULL(sigc->key);
 }
 
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2018-08-17 18:29 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-17  9:17 [PATCH] gpg-interface.c: Fix potentially freeing NULL values Michał Górny
2018-08-17  9:28 ` Eric Sunshine
2018-08-17  9:40   ` Michał Górny
2018-08-17 13:02     ` [PATCH] refactor various if (x) FREE_AND_NULL(x) to just FREE_AND_NULL(x) Ævar Arnfjörð Bjarmason
2018-08-17 14:36       ` Duy Nguyen
2018-08-17 15:10         ` Duy Nguyen
2018-08-17 16:53           ` Junio C Hamano
2018-08-17 17:07             ` Junio C Hamano
2018-08-17 17:33               ` Jeff King
2018-08-17 17:39                 ` Jeff King
2018-08-17 17:44                   ` Jeff King
2018-08-17 18:29                 ` Duy Nguyen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).