Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: GnuPG: devel

[PATCH] tests: avoid use of freed pointer

 

 

GnuPG devel RSS feed   Index | Next | Previous | View Threaded


jim at meyering

Sep 20, 2011, 7:35 AM

Post #1 of 1 (145 views)
Permalink
[PATCH] tests: avoid use of freed pointer

[spotted by coverity]

This is only in tests/, but easy to fix, so...
I've included extra context so you can see how var->value would
be used in the following atoi call.

>From cf9ae83fd2da8d7a289b048ef0feed4096f6d263 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering [at] redhat>
Date: Tue, 20 Sep 2011 16:32:59 +0200
Subject: [PATCH] avoid use of free'd pointer

* asschk.c (set_type_var): Set var->value to NULL after freeing it,
to avoid subsequent use of freed pointer.
---
tests/ChangeLog | 6 ++++++
tests/asschk.c | 5 ++++-
2 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/tests/ChangeLog b/tests/ChangeLog
index b2e95f3..aa93f07 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,6 +1,12 @@
+2011-09-20 Jim Meyering <meyering [at] redhat>
+
+ avoid use of free'd pointer
+ * asschk.c (set_type_var): Set var->value to NULL after freeing it,
+ to avoid subsequent use of freed pointer.
+
2009-10-13 Werner Koch <wk [at] g10code>

* asschk.c (die): Replace this vararg macro by C-89 compliant
macros die_0, die_1, die_2 and die 3. Change all callers.
Reported by Nelson H. F. Beebe.

diff --git a/tests/asschk.c b/tests/asschk.c
index 3eb2621..c0108e7 100644
--- a/tests/asschk.c
+++ b/tests/asschk.c
@@ -511,13 +511,16 @@ set_type_var (const char *name, const char *value, VARTYPE type)
var = xcalloc (1, sizeof *var + strlen (name));
strcpy (var->name, name);
var->next = variable_list;
variable_list = var;
}
else
- free (var->value);
+ {
+ free (var->value);
+ var->value = NULL;
+ }

if (var->type == VARTYPE_FD && var->value)
{
int fd;

fd = atoi (var->value);
--
1.7.7.rc0.362.g5a14

_______________________________________________
Gnupg-devel mailing list
Gnupg-devel [at] gnupg
http://lists.gnupg.org/mailman/listinfo/gnupg-devel

GnuPG devel RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.