diff options
author | jthorn <jthorn@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2006-04-21 15:50:40 +0000 |
---|---|---|
committer | jthorn <jthorn@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2006-04-21 15:50:40 +0000 |
commit | 9061b6677c560f48573d0f84211d8a062a9a3be7 (patch) | |
tree | c065c2bf3f9c07531265e014a4d993fde65489c2 /src/main | |
parent | 4829abab50985ad4fe8fcb13b5c090338f33f0ab (diff) |
Fix a bug in CCTK_ParameterSet() .
The symptoms were that if you
(a) set the same parameter twice, *and*
(b) the second setting is an invalid value,
then current-CVS Cactus core-dumps inside the flesh trying to free()
a garbage (uninitialized) pointer.
For example, the following par file suffices to trigger the core-dump,
using only flesh parameters (*no* thorns activated):
# this par file causes a core dump in current-CVS Cactus
Cactus::cctk_timer_output = "off"
Cactus::cctk_timer_output = "foo" # an illegal value for this parameter
Looking at the code,
599 /* check if a parameter is set more than once in a parfile */
600 if (cctk_parameter_set_mask == PARAMETER_RECOVERY_PRE &&
601 param->props->n_set > 0)
602 {
603 if (retval == 0)
604 {
605 new_value = CCTK_ParameterValString (param->props->name,
606 param->props->thorn);
607 retval = strcmp (old_value, new_value) ? -10 : -11;
608 }
609 free (new_value);
610 }
Notice that the free() at line 609 may be executed even if new_value
was *not* assigned a value at line 605. Alas, new_value is a local
variable in this function, and is not explicitly initialized, so it
has a garbage value initially... and line 605 is its only assignment
in this function.
The fix is easy -- just move the free() up to right after line 607,
so it's executed if and only if new_value has been assigned.
patch was
http://www.cactuscode.org/old/pipermail/patches/2006-April/000162.html
developers discussion was
http://www.cactuscode.org/old/pipermail/developers/2006-April/001758.html
http://www.cactuscode.org/old/pipermail/developers/2006-April/001759.html
git-svn-id: http://svn.cactuscode.org/flesh/trunk@4285 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/Parameters.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/main/Parameters.c b/src/main/Parameters.c index ef7069b3..cd8527ec 100644 --- a/src/main/Parameters.c +++ b/src/main/Parameters.c @@ -605,8 +605,8 @@ int CCTK_ParameterSet (const char *name, const char *thorn, const char *value) new_value = CCTK_ParameterValString (param->props->name, param->props->thorn); retval = strcmp (old_value, new_value) ? -10 : -11; + free (new_value); } - free (new_value); } /* register another set operation */ |