From 15a01889cd1cbb8eac0d394b8e04d1ef305eb93d Mon Sep 17 00:00:00 2001 From: Mike Black W9MDB Date: Mon, 22 May 2023 08:47:01 -0500 Subject: [PATCH] Prevent segfault in rig_get_caps_int/cptr calls --- src/misc.c | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/src/misc.c b/src/misc.c index 779d4728f..e24ca01fa 100644 --- a/src/misc.c +++ b/src/misc.c @@ -986,15 +986,17 @@ int check_level_param(RIG *rig, setting_t level, value_t val, gran_t **gran) /* If min==max==step==0, all values are OK here */ maxval = this_gran->max.f; + if (this_gran->min.f == 0.0f && maxval == 0.0f) { - /* if step==0 also, we're good */ - if (this_gran->step.f == 0.0f) - { - return RIG_OK; - } - /* non-zero step, check for max of 1.0 */ - maxval = 1.0f; + /* if step==0 also, we're good */ + if (this_gran->step.f == 0.0f) + { + return RIG_OK; + } + + /* non-zero step, check for max of 1.0 */ + maxval = 1.0f; } if (val.f < this_gran->min.f || val.f > maxval) @@ -2560,7 +2562,15 @@ long long HAMLIB_API rig_get_caps_int(rig_model_t rig_model, enum rig_caps_int_e rig_caps) { const struct rig_caps *caps = rig_get_caps(rig_model); - rig_debug(RIG_DEBUG_TRACE, "%s: getting rig_caps for model=%d, rig_caps=%d\n", __func__, rig_model, rig_caps); + rig_debug(RIG_DEBUG_TRACE, "%s: getting rig_caps for model=%d, rig_caps=%d\n", + __func__, rig_model, rig_caps); + + if (caps == NULL) + { + rig_debug(RIG_DEBUG_ERR, "%s: called with NULL caps...returning -1\n", + __func__); + return -1; + } switch (rig_caps) { @@ -2591,6 +2601,13 @@ const char *HAMLIB_API rig_get_caps_cptr(rig_model_t rig_model, { const struct rig_caps *caps = rig_get_caps(rig_model); + if (caps == NULL) + { + rig_debug(RIG_DEBUG_ERR, "%s: called with NULL caps...returning NULL\n", + __func__); + return NULL; + } + switch (rig_caps) { case RIG_CAPS_VERSION_CPTR: