From f59c9ebcb75ad8d97680c5fe43531d72b2633aa3 Mon Sep 17 00:00:00 2001 From: Tim Edwards Date: Tue, 3 Oct 2023 19:39:01 -0400 Subject: [PATCH] Corrected an issue where a mismatch in property type (e.g., string vs. integer) will cause a segfault. Not sure if type promotion is needed at that point because the failing case was a syntax error that caused a double value to be interpreted as a string because it could not be cast into a numeric form. --- VERSION | 2 +- base/netcmp.c | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/VERSION b/VERSION index 194f066..e30bd8b 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.5.258 +1.5.259 diff --git a/base/netcmp.c b/base/netcmp.c index d05f8a8..d055c47 100644 --- a/base/netcmp.c +++ b/base/netcmp.c @@ -5026,21 +5026,30 @@ int PropertyOptimize(struct objlist *ob, struct nlist *tp, int run, int series, switch(vl->type) { case PROP_DOUBLE: case PROP_VALUE: - dval = 2 * fabs(vl->value.dval - vl2->value.dval) + if ((vl2->type == PROP_DOUBLE) || (vl2->type == PROP_VALUE)) { + dval = 2 * fabs(vl->value.dval - vl2->value.dval) / (vl->value.dval + vl2->value.dval); - if (dval <= kl->slop.dval) pmatch++; + if (dval <= kl->slop.dval) pmatch++; + } break; case PROP_INTEGER: - ival = abs(vl->value.ival - vl2->value.ival); - if (ival <= kl->slop.ival) pmatch++; + if (vl2->type == PROP_INTEGER) { + ival = abs(vl->value.ival - vl2->value.ival); + if (ival <= kl->slop.ival) pmatch++; + } break; case PROP_STRING: - if ((*matchfunc)(vl->value.string, vl2->value.string)) pmatch++; + if (vl2->type == PROP_STRING) { + if ((*matchfunc)(vl->value.string, vl2->value.string)) pmatch++; + } break; - /* will not attempt to match expressions, but it could + /* Will not attempt to match expressions, but it could * be done with some minor effort by matching each * stack token and comparing those that are strings. + * Likewise, will not attempt to match properties + * whose types are mismatched, but they could be + * promoted here. */ } }