From c55c6a0709e44599dc9784425fcb0f18c72b9bf5 Mon Sep 17 00:00:00 2001 From: Corey Mutter Date: Mon, 29 Jan 2024 19:15:59 +0000 Subject: [PATCH] fix: assert failures on null/empty maps (#504) Sometimes objects intended to be maps are null, or initialized but type IOT_DATA_NULL, causing map get/iterate functions to assert. Bypass these cases, treating it as an empty map. Signed-off-by: Corey Mutter --- src/c/config.c | 157 ++++++++++++++++------------ src/c/consul.c | 61 ++++++----- src/c/dto-read.c | 2 +- src/c/edgex-rest.c | 13 ++- src/c/examples/discovery/template.c | 22 +++- src/c/examples/template.c | 22 +++- src/c/secrets-insecure.c | 4 + src/c/transform.c | 4 +- src/c/validate.c | 17 +-- src/c/watchers.c | 21 ++-- 10 files changed, 197 insertions(+), 126 deletions(-) diff --git a/src/c/config.c b/src/c/config.c index 6b136e82..f9a8021f 100644 --- a/src/c/config.c +++ b/src/c/config.c @@ -124,7 +124,7 @@ iot_data_t *edgex_private_config_defaults (const iot_data_t *driverconf) iot_data_string_map_add (result, "Service/Port", iot_data_alloc_ui16 (59999)); iot_data_string_map_add (result, "Service/StartupMsg", iot_data_alloc_string ("", IOT_DATA_REF)); - if (driverconf) + if (driverconf && (iot_data_type(driverconf) == IOT_DATA_MAP)) { iot_data_map_iter_t iter; iot_data_map_iter (driverconf, &iter); @@ -281,39 +281,46 @@ void edgex_device_parseClients (iot_logger_t *lc, const iot_data_t *clients, edg static void addInsecureSecretsMap (iot_data_t *confmap, const iot_data_t *config) { + if ((!config) || (iot_data_type(config) != IOT_DATA_MAP)) + { + return; + } const iot_data_t *sub = iot_data_string_map_get (config, DYN_NAME); - if (sub) + if (sub && (iot_data_type(sub) == IOT_DATA_MAP)) { sub = iot_data_string_map_get (sub, INSECURE_NAME); } - if (sub) + if (sub && (iot_data_type(sub) == IOT_DATA_MAP)) { iot_data_map_iter_t iter; iot_data_map_iter (sub, &iter); while (iot_data_map_iter_next (&iter)) { const iot_data_t *tab = iot_data_map_iter_value (&iter); - const iot_data_t *sname = iot_data_string_map_get (tab, "SecretName"); - if (sname) - { - const iot_data_t *secrets = iot_data_string_map_get (tab, "SecretData"); - if (secrets) - { - char *cpath; - const char *key = iot_data_map_iter_string_key (&iter); - iot_data_map_iter_t elem; - iot_data_map_iter (secrets, &elem); - while (iot_data_map_iter_next (&elem)) + if (tab && (iot_data_type(tab) == IOT_DATA_MAP)) + { + const iot_data_t *sname = iot_data_string_map_get (tab, "SecretName"); + if (sname) + { + const iot_data_t *secrets = iot_data_string_map_get (tab, "SecretData"); + char *cpath; + const char *key = iot_data_map_iter_string_key (&iter); + iot_data_map_iter_t elem; + if (secrets && (iot_data_type(secrets) == IOT_DATA_MAP)) { - cpath = malloc (sizeof (DYN_PREFIX) + sizeof (INSECURE_NAME) + strlen (key) + sizeof ("/SecretData/") + strlen (iot_data_map_iter_string_key (&elem))); - strcpy (cpath, DYN_PREFIX); - strcat (cpath, INSECURE_NAME); - strcat (cpath, "/"); - strcat (cpath, key); - strcat (cpath, "/SecretData/"); - strcat (cpath, iot_data_map_iter_string_key (&elem)); - iot_data_map_add (confmap, iot_data_alloc_string (cpath, IOT_DATA_TAKE), iot_data_add_ref (iot_data_map_iter_value (&elem))); - } + iot_data_map_iter (secrets, &elem); + while (iot_data_map_iter_next (&elem)) + { + cpath = malloc (sizeof (DYN_PREFIX) + sizeof (INSECURE_NAME) + strlen (key) + sizeof ("/SecretData/") + strlen (iot_data_map_iter_string_key (&elem))); + strcpy (cpath, DYN_PREFIX); + strcat (cpath, INSECURE_NAME); + strcat (cpath, "/"); + strcat (cpath, key); + strcat (cpath, "/SecretData/"); + strcat (cpath, iot_data_map_iter_string_key (&elem)); + iot_data_map_add (confmap, iot_data_alloc_string (cpath, IOT_DATA_TAKE), iot_data_add_ref (iot_data_map_iter_value (&elem))); + } + } cpath = malloc (sizeof (DYN_PREFIX) + sizeof (INSECURE_NAME) + strlen (key) + sizeof ("/SecretName/")); strcpy (cpath, DYN_PREFIX); strcat (cpath, INSECURE_NAME); @@ -371,16 +378,19 @@ void edgex_device_overrideConfig_map (iot_data_t *config, const iot_data_t *map) const iot_data_t *replace; iot_data_map_iter_t iter; - iot_data_map_iter (config, &iter); - while (iot_data_map_iter_next (&iter)) + if (config && (iot_data_type(config) == IOT_DATA_MAP)) { - replace = findEntry (map, iot_data_map_iter_string_key (&iter)); - if (replace) + iot_data_map_iter (config, &iter); + while (iot_data_map_iter_next (&iter)) { - iot_data_t *newval = iot_data_transform (replace, iot_data_type (iot_data_map_iter_value (&iter))); - if (newval) + replace = findEntry (map, iot_data_map_iter_string_key (&iter)); + if (replace) { - iot_data_free (iot_data_map_iter_replace_value (&iter, newval)); + iot_data_t *newval = iot_data_transform (replace, iot_data_type (iot_data_map_iter_value (&iter))); + if (newval) + { + iot_data_free (iot_data_map_iter_replace_value (&iter, newval)); + } } } } @@ -394,6 +404,10 @@ void edgex_device_overrideConfig_env (iot_logger_t *lc, iot_data_t *config) const char *key; iot_data_map_iter_t iter; + if ((!config) || (iot_data_type(config) != IOT_DATA_MAP)) + { + return; + } iot_data_map_iter (config, &iter); while (iot_data_map_iter_next (&iter)) { @@ -435,16 +449,19 @@ void edgex_device_overrideConfig_nvpairs (iot_data_t *config, const devsdk_nvpai const char *raw; iot_data_map_iter_t iter; - iot_data_map_iter (config, &iter); - while (iot_data_map_iter_next (&iter)) + if (config && (iot_data_type(config) == IOT_DATA_MAP)) { - raw = devsdk_nvpairs_value (pairs, iot_data_map_iter_string_key (&iter)); - if (raw) + iot_data_map_iter (config, &iter); + while (iot_data_map_iter_next (&iter)) { - iot_data_t *newval = iot_data_alloc_from_string (iot_data_type (iot_data_map_iter_value (&iter)), raw); - if (newval) + raw = devsdk_nvpairs_value (pairs, iot_data_map_iter_string_key (&iter)); + if (raw) { - iot_data_free (iot_data_map_iter_replace_value (&iter, newval)); + iot_data_t *newval = iot_data_alloc_from_string (iot_data_type (iot_data_map_iter_value (&iter)), raw); + if (newval) + { + iot_data_free (iot_data_map_iter_replace_value (&iter, newval)); + } } } } @@ -519,20 +536,23 @@ void edgex_device_populateConfig (devsdk_service_t *svc, iot_data_t *config) svc->config.sdkconf = config; svc->config.driverconf = iot_data_alloc_map (IOT_DATA_STRING); - iot_data_map_iter (config, &iter); - while (iot_data_map_iter_next (&iter)) + if (config && (iot_data_type(config) == IOT_DATA_MAP)) { - const char *key = iot_data_map_iter_string_key (&iter); - if (strncmp (key, DRV_PREFIX, DRV_PREFIXLEN) == 0) - { - iot_data_map_add (svc->config.driverconf, iot_data_alloc_string (key + DRV_PREFIXLEN, IOT_DATA_COPY), iot_data_copy (iot_data_map_iter_value (&iter))); - } - else if (strncmp (key, DYN_DRV_PREFIX, DYN_DRV_PREFIXLEN) == 0) + iot_data_map_iter (config, &iter); + while (iot_data_map_iter_next (&iter)) { - char *nkey = malloc (strlen (key) - DRV_PREFIXLEN + 1); - strcpy (nkey, DYN_PREFIX); - strcat (nkey, key + DYN_DRV_PREFIXLEN); - iot_data_map_add (svc->config.driverconf, iot_data_alloc_string (nkey, IOT_DATA_TAKE), iot_data_copy (iot_data_map_iter_value (&iter))); + const char *key = iot_data_map_iter_string_key (&iter); + if (strncmp (key, DRV_PREFIX, DRV_PREFIXLEN) == 0) + { + iot_data_map_add (svc->config.driverconf, iot_data_alloc_string (key + DRV_PREFIXLEN, IOT_DATA_COPY), iot_data_copy (iot_data_map_iter_value (&iter))); + } + else if (strncmp (key, DYN_DRV_PREFIX, DYN_DRV_PREFIXLEN) == 0) + { + char *nkey = malloc (strlen (key) - DRV_PREFIXLEN + 1); + strcpy (nkey, DYN_PREFIX); + strcat (nkey, key + DYN_DRV_PREFIXLEN); + iot_data_map_add (svc->config.driverconf, iot_data_alloc_string (nkey, IOT_DATA_TAKE), iot_data_copy (iot_data_map_iter_value (&iter))); + } } } @@ -605,24 +625,27 @@ void edgex_device_updateConf (void *p, const devsdk_nvpairs *config) edgex_secrets_reconfigure (svc->secretstore, svc->config.sdkconf); } - iot_data_map_iter (svc->config.sdkconf, &iter); - while (iot_data_map_iter_next (&iter)) + if (svc->config.sdkconf && (iot_data_type(svc->config.sdkconf) == IOT_DATA_MAP)) { - const char *key = iot_data_map_iter_string_key (&iter); - if (strncmp (key, DYN_DRV_PREFIX, DYN_DRV_PREFIXLEN) == 0) + iot_data_map_iter (svc->config.sdkconf, &iter); + while (iot_data_map_iter_next (&iter)) { - char *nkey = malloc (strlen (key) - DRV_PREFIXLEN + 1); - strcpy (nkey, DYN_PREFIX); - strcat (nkey, key + DYN_DRV_PREFIXLEN); - const iot_data_t *driverval = iot_data_string_map_get (svc->config.driverconf, nkey); - if (driverval && !iot_data_equal (driverval, iot_data_map_iter_value (&iter))) - { - updatedriver = true; - iot_data_map_add (svc->config.driverconf, iot_data_alloc_string (nkey, IOT_DATA_TAKE), iot_data_copy (iot_data_map_iter_value (&iter))); - } - else + const char *key = iot_data_map_iter_string_key (&iter); + if (strncmp (key, DYN_DRV_PREFIX, DYN_DRV_PREFIXLEN) == 0) { - free (nkey); + char *nkey = malloc (strlen (key) - DRV_PREFIXLEN + 1); + strcpy (nkey, DYN_PREFIX); + strcat (nkey, key + DYN_DRV_PREFIXLEN); + const iot_data_t *driverval = iot_data_string_map_get (svc->config.driverconf, nkey); + if (driverval && !iot_data_equal (driverval, iot_data_map_iter_value (&iter))) + { + updatedriver = true; + iot_data_map_add (svc->config.driverconf, iot_data_alloc_string (nkey, IOT_DATA_TAKE), iot_data_copy (iot_data_map_iter_value (&iter))); + } + else + { + free (nkey); + } } } } @@ -636,6 +659,10 @@ void edgex_device_dumpConfig (iot_logger_t *lc, iot_data_t *config) { char *val; iot_data_map_iter_t iter; + if ((!config) || (iot_data_type(config) != IOT_DATA_MAP)) + { + return; + } iot_data_map_iter (config, &iter); while (iot_data_map_iter_next (&iter)) { @@ -773,7 +800,7 @@ static JSON_Value *edgex_device_config_toJson (devsdk_service_t *svc) json_object_set_value (obj, "Service", sval); - if (svc->config.driverconf) + if (svc->config.driverconf && (iot_data_type(svc->config.driverconf) == IOT_DATA_MAP)) { iot_data_map_iter_t iter; iot_data_map_iter (svc->config.driverconf, &iter); diff --git a/src/c/consul.c b/src/c/consul.c index 71d54fe1..7a2faa3c 100644 --- a/src/c/consul.c +++ b/src/c/consul.c @@ -398,38 +398,41 @@ static void edgex_consul_client_write_config (void *impl, const char *servicenam JSON_Array *jarray = json_value_get_array (jresult); iot_data_map_iter_t iter; - iot_data_map_iter (config, &iter); - while (iot_data_map_iter_next (&iter)) + if (config && (iot_data_type(config) == IOT_DATA_MAP)) { - char *base64val; - const iot_data_t *val = iot_data_map_iter_value (&iter); - if (iot_data_type (val) == IOT_DATA_STRING) + iot_data_map_iter (config, &iter); + while (iot_data_map_iter_next (&iter)) { - base64val = value_to_b64 (iot_data_string (val)); - } - else - { - char *json = iot_data_to_json (val); - base64val = value_to_b64 (json); - free (json); - } - - const char *k = iot_data_map_iter_string_key (&iter); - char *keystr = malloc (strlen (CONF_PREFIX) + strlen (servicename) + strlen (k) + 2); - sprintf (keystr, "%s%s/%s", CONF_PREFIX, servicename, k); - - JSON_Value *kvfields = json_value_init_object (); - JSON_Object *obj = json_value_get_object (kvfields); - json_object_set_string (obj, "Verb", "set"); - json_object_set_string (obj, "Key", keystr); - json_object_set_string (obj, "Value", base64val); - - JSON_Value *kvcmd = json_value_init_object (); - json_object_set_value (json_value_get_object (kvcmd), "KV", kvfields); - json_array_append_value (jarray, kvcmd); + char *base64val; + const iot_data_t *val = iot_data_map_iter_value (&iter); + if (iot_data_type (val) == IOT_DATA_STRING) + { + base64val = value_to_b64 (iot_data_string (val)); + } + else + { + char *json = iot_data_to_json (val); + base64val = value_to_b64 (json); + free (json); + } - free (base64val); - free (keystr); + const char *k = iot_data_map_iter_string_key (&iter); + char *keystr = malloc (strlen (CONF_PREFIX) + strlen (servicename) + strlen (k) + 2); + sprintf (keystr, "%s%s/%s", CONF_PREFIX, servicename, k); + + JSON_Value *kvfields = json_value_init_object (); + JSON_Object *obj = json_value_get_object (kvfields); + json_object_set_string (obj, "Verb", "set"); + json_object_set_string (obj, "Key", keystr); + json_object_set_string (obj, "Value", base64val); + + JSON_Value *kvcmd = json_value_init_object (); + json_object_set_value (json_value_get_object (kvcmd), "KV", kvfields); + json_array_append_value (jarray, kvcmd); + + free (base64val); + free (keystr); + } } char *json = json_serialize_to_string (jresult); diff --git a/src/c/dto-read.c b/src/c/dto-read.c index 8675dfbe..e93cdc3f 100644 --- a/src/c/dto-read.c +++ b/src/c/dto-read.c @@ -35,7 +35,7 @@ static edgex_device_operatingstate edgex_operatingstate_read (const iot_data_t * static devsdk_protocols *edgex_protocols_read (const iot_data_t *obj) { devsdk_protocols *result = NULL; - if (obj) + if (obj && (iot_data_type(obj) == IOT_DATA_MAP)) { iot_data_map_iter_t iter; iot_data_map_iter (obj, &iter); diff --git a/src/c/edgex-rest.c b/src/c/edgex-rest.c index 7e45347b..60d24502 100644 --- a/src/c/edgex-rest.c +++ b/src/c/edgex-rest.c @@ -159,11 +159,14 @@ static JSON_Value *string_map_write (const iot_data_t *map) JSON_Value *result = json_value_init_object (); JSON_Object *obj = json_value_get_object (result); - iot_data_map_iter_t iter; - iot_data_map_iter (map, &iter); - while (iot_data_map_iter_next (&iter)) - { - json_object_set_string (obj, iot_data_map_iter_string_key (&iter), iot_data_map_iter_string_value (&iter)); + if (map && (iot_data_type(map) == IOT_DATA_MAP)) + { + iot_data_map_iter_t iter; + iot_data_map_iter (map, &iter); + while (iot_data_map_iter_next (&iter)) + { + json_object_set_string (obj, iot_data_map_iter_string_key (&iter), iot_data_map_iter_string_value (&iter)); + } } return result; } diff --git a/src/c/examples/discovery/template.c b/src/c/examples/discovery/template.c index 0128564b..d20118ed 100644 --- a/src/c/examples/discovery/template.c +++ b/src/c/examples/discovery/template.c @@ -25,7 +25,12 @@ static void dump_protocols (iot_logger_t *lc, const devsdk_protocols *prots) { iot_data_map_iter_t iter; iot_log_debug (lc, " [Other] protocol:"); - iot_data_map_iter (devsdk_protocols_properties (prots, "Other"), &iter); + const iot_data_t *others = devsdk_protocols_properties(prots, "Other"); + if ((!others) || (iot_data_type(others) != IOT_DATA_MAP)) + { + return; + } + iot_data_map_iter (others, &iter); while (iot_data_map_iter_next (&iter)) { iot_log_debug (lc, " %s = %s", iot_data_map_iter_string_key (&iter), iot_data_map_iter_string_value (&iter)); @@ -35,6 +40,10 @@ static void dump_protocols (iot_logger_t *lc, const devsdk_protocols *prots) static void dump_attributes (iot_logger_t *lc, devsdk_resource_attr_t attrs) { iot_data_map_iter_t iter; + if ((!attrs) || (iot_data_type((iot_data_t *)attrs) != IOT_DATA_MAP)) + { + return; + } iot_data_map_iter ((iot_data_t *)attrs, &iter); while (iot_data_map_iter_next (&iter)) { @@ -55,7 +64,7 @@ static bool template_init { template_driver *driver = (template_driver *) impl; iot_log_debug (lc, "Template Init. Driver Config follows:"); - if (config) + if (config && (iot_data_type(config) == IOT_DATA_MAP)) { iot_data_map_iter_t iter; iot_data_map_iter (config, &iter); @@ -81,10 +90,13 @@ static void template_reconfigure iot_data_map_iter_t iter; template_driver *driver = (template_driver *) impl; iot_log_debug (driver->lc, "Template Reconfiguration. New Config follows:"); - iot_data_map_iter (config, &iter); - while (iot_data_map_iter_next (&iter)) + if (config && (iot_data_type(config) == IOT_DATA_MAP)) { - iot_log_debug (driver->lc, " %s = %s", iot_data_map_iter_string_key (&iter), iot_data_map_iter_string_value (&iter)); + iot_data_map_iter (config, &iter); + while (iot_data_map_iter_next (&iter)) + { + iot_log_debug (driver->lc, " %s = %s", iot_data_map_iter_string_key (&iter), iot_data_map_iter_string_value (&iter)); + } } } diff --git a/src/c/examples/template.c b/src/c/examples/template.c index dcd4688f..ab06ac31 100644 --- a/src/c/examples/template.c +++ b/src/c/examples/template.c @@ -25,7 +25,12 @@ static void dump_protocols (iot_logger_t *lc, const devsdk_protocols *prots) { iot_data_map_iter_t iter; iot_log_debug (lc, " [Other] protocol:"); - iot_data_map_iter (devsdk_protocols_properties (prots, "Other"), &iter); + const iot_data_t *others = devsdk_protocols_properties(prots, "Other"); + if ((!others) || (iot_data_type(others) != IOT_DATA_MAP)) + { + return; + } + iot_data_map_iter (others, &iter); while (iot_data_map_iter_next (&iter)) { iot_log_debug (lc, " %s = %s", iot_data_map_iter_string_key (&iter), iot_data_map_iter_string_value (&iter)); @@ -37,6 +42,10 @@ static void dump_attributes (iot_logger_t *lc, devsdk_resource_attr_t attrs) if (lc && lc->level >= IOT_LOG_DEBUG) { iot_data_map_iter_t iter; + if ((!attrs) || (iot_data_type((iot_data_t *)attrs) != IOT_DATA_MAP)) + { + return; + } iot_data_map_iter ((iot_data_t *)attrs, &iter); while (iot_data_map_iter_next (&iter)) { @@ -60,7 +69,7 @@ static bool template_init { template_driver *driver = (template_driver *) impl; iot_log_debug (lc, "Template Init. Driver Config follows:"); - if (config) + if (config && (iot_data_type(config) == IOT_DATA_MAP)) { iot_data_map_iter_t iter; iot_data_map_iter (config, &iter); @@ -86,10 +95,13 @@ static void template_reconfigure iot_data_map_iter_t iter; template_driver *driver = (template_driver *) impl; iot_log_debug (driver->lc, "Template Reconfiguration. New Config follows:"); - iot_data_map_iter (config, &iter); - while (iot_data_map_iter_next (&iter)) + if (config && (iot_data_type(config) == IOT_DATA_MAP)) { - iot_log_debug (driver->lc, " %s = %s", iot_data_map_iter_string_key (&iter), iot_data_map_iter_string_value (&iter)); + iot_data_map_iter (config, &iter); + while (iot_data_map_iter_next (&iter)) + { + iot_log_debug (driver->lc, " %s = %s", iot_data_map_iter_string_key (&iter), iot_data_map_iter_string_value (&iter)); + } } } diff --git a/src/c/secrets-insecure.c b/src/c/secrets-insecure.c index 12f83e6d..c022b9aa 100644 --- a/src/c/secrets-insecure.c +++ b/src/c/secrets-insecure.c @@ -27,6 +27,10 @@ static iot_data_t *insecure_parse_config (iot_data_t *config) { iot_data_t *result = iot_data_alloc_map (IOT_DATA_STRING); + if ((!config) || (iot_data_type(config) != IOT_DATA_MAP)) + { + return result; + } iot_data_map_iter_t iter; iot_data_map_iter (config, &iter); while (iot_data_map_iter_next (&iter)) diff --git a/src/c/transform.c b/src/c/transform.c index a10bebf5..8732fdd9 100644 --- a/src/c/transform.c +++ b/src/c/transform.c @@ -147,7 +147,7 @@ void edgex_transform_outgoing (devsdk_commandresult *cres, edgex_propertyvalue * break; case IOT_DATA_STRING: { - if (mappings) + if (mappings && (iot_data_type(mappings) == IOT_DATA_MAP)) { const iot_data_t *remap = iot_data_map_get (mappings, cres->value); if (remap) @@ -213,7 +213,7 @@ void edgex_transform_incoming (iot_data_t **cres, edgex_propertyvalue *props, co break; case IOT_DATA_STRING: { - if (mappings) + if (mappings && (iot_data_type(mappings) == IOT_DATA_MAP)) { iot_data_map_iter_t iter; iot_data_map_iter (mappings, &iter); diff --git a/src/c/validate.c b/src/c/validate.c index e4620ed6..4005faf1 100644 --- a/src/c/validate.c +++ b/src/c/validate.c @@ -17,14 +17,17 @@ static devsdk_protocols *protocols_convert (const iot_data_t *obj) devsdk_protocols *result = NULL; iot_data_map_iter_t iter; - iot_data_map_iter (obj, &iter); - while (iot_data_map_iter_has_next (&iter)) + if (obj && (iot_data_type(obj) == IOT_DATA_MAP)) { - devsdk_protocols *prot = malloc (sizeof (devsdk_protocols)); - prot->name = strdup (iot_data_map_iter_string_key (&iter)); - prot->properties = iot_data_add_ref (iot_data_map_iter_value (&iter)); - prot->next = result; - result = prot; + iot_data_map_iter (obj, &iter); + while (iot_data_map_iter_has_next (&iter)) + { + devsdk_protocols *prot = malloc (sizeof (devsdk_protocols)); + prot->name = strdup (iot_data_map_iter_string_key (&iter)); + prot->properties = iot_data_add_ref (iot_data_map_iter_value (&iter)); + prot->next = result; + result = prot; + } } return result; } diff --git a/src/c/watchers.c b/src/c/watchers.c index c1b23237..4fc984d0 100644 --- a/src/c/watchers.c +++ b/src/c/watchers.c @@ -62,6 +62,10 @@ static edgex_watcher **find_locked (edgex_watcher **list, const char *name) static void add_locked (edgex_watchlist_t *wl, const edgex_watcher *w) { + if ((!w) || (!w->identifiers) || (iot_data_type(w->identifiers) != IOT_DATA_MAP)) + { + return; + } edgex_watcher *newelem = edgex_watcher_dup (w); iot_data_map_iter_t iter; iot_data_map_iter (newelem->identifiers, &iter); @@ -155,16 +159,19 @@ static bool matchpw (const edgex_watcher *pw, const iot_data_t *ids) } - iot_data_map_iter_t blocked; - iot_data_map_iter (pw->blocking_identifiers, &blocked); - while (iot_data_map_iter_next (&blocked)) + if ((pw->blocking_identifiers) && (iot_data_type(pw->blocking_identifiers) == IOT_DATA_MAP)) { - const iot_data_t *checkval = iot_data_map_get (ids, iot_data_map_iter_key (&blocked)); - if (checkval) + iot_data_map_iter_t blocked; + iot_data_map_iter (pw->blocking_identifiers, &blocked); + while (iot_data_map_iter_next (&blocked)) { - if (iot_data_vector_find (iot_data_map_iter_value (&blocked), (iot_data_cmp_fn)iot_data_equal, checkval)) + const iot_data_t *checkval = iot_data_map_get (ids, iot_data_map_iter_key (&blocked)); + if (checkval) { - return false; + if (iot_data_vector_find (iot_data_map_iter_value (&blocked), (iot_data_cmp_fn)iot_data_equal, checkval)) + { + return false; + } } } }