From: Mytnyk, VolodymyrX Date: Mon, 6 Mar 2017 16:52:10 +0000 (+0000) Subject: ovs_events: fix scan-build warnings #2205 X-Git-Tag: collectd-5.8.0~208^2 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=4256753373b8f61dc1928dfc7b0564f2fbc32289;p=collectd.git ovs_events: fix scan-build warnings #2205 src/utils_ovs.c:366:20: warning: Access to field 'type' results in a dereference of a null pointer (loaded from variable 'jval') (int)(jval)->type); ^~~~~~~~~~~~ ... Change-Id: Ic856d21f2121f920bdd2043c69620555bb3d1cb8 Signed-off-by: Mytnyk, VolodymyrX --- diff --git a/src/ovs_stats.c b/src/ovs_stats.c index 1641e875..23b7533c 100644 --- a/src/ovs_stats.c +++ b/src/ovs_stats.c @@ -349,13 +349,15 @@ static int ovs_stats_update_bridge(yajl_val bridge) { if (br_ports && YAJL_IS_ARRAY(br_ports)) { char *tmp = YAJL_GET_STRING(br_ports->u.array.values[0]); if (tmp != NULL && strcmp("set", tmp) == 0) { - yajl_val *ports_arr = - YAJL_GET_ARRAY(br_ports->u.array.values[1])->values; - size_t ports_num = YAJL_GET_ARRAY(br_ports->u.array.values[1])->len; - - for (size_t i = 0; i < ports_num; i++) - ovs_stats_new_port( - br, YAJL_GET_STRING(ports_arr[i]->u.array.values[1])); + yajl_val *array = YAJL_GET_ARRAY(br_ports)->values; + size_t array_len = YAJL_GET_ARRAY(br_ports)->len; + if (array != NULL && array_len > 0 && YAJL_IS_ARRAY(array[1])) { + yajl_val *ports_arr = YAJL_GET_ARRAY(array[1])->values; + size_t ports_num = YAJL_GET_ARRAY(array[1])->len; + for (size_t i = 0; i < ports_num && ports_arr != NULL; i++) + ovs_stats_new_port( + br, YAJL_GET_STRING(ports_arr[i]->u.array.values[1])); + } } else ovs_stats_new_port(br, YAJL_GET_STRING(br_ports->u.array.values[1])); } @@ -537,6 +539,8 @@ static int ovs_stats_update_iface_stats(port_list_t *port, yajl_val stats) { if (stats && YAJL_IS_ARRAY(stats)) for (size_t i = 0; i < YAJL_GET_ARRAY(stats)->len; i++) { stat = YAJL_GET_ARRAY(stats)->values[i]; + if (!YAJL_IS_ARRAY(stat)) + return (-1); counter_name = YAJL_GET_STRING(YAJL_GET_ARRAY(stat)->values[0]); counter_index = ovs_stats_counter_name_to_type(counter_name); counter_value = YAJL_GET_INTEGER(YAJL_GET_ARRAY(stat)->values[1]); @@ -557,6 +561,8 @@ static int ovs_stats_update_iface_ext_ids(port_list_t *port, yajl_val ext_ids) { if (ext_ids && YAJL_IS_ARRAY(ext_ids)) for (size_t i = 0; i < YAJL_GET_ARRAY(ext_ids)->len; i++) { ext_id = YAJL_GET_ARRAY(ext_ids)->values[i]; + if (!YAJL_IS_ARRAY(ext_id)) + return (-1); key = YAJL_GET_STRING(YAJL_GET_ARRAY(ext_id)->values[0]); value = YAJL_GET_STRING(YAJL_GET_ARRAY(ext_id)->values[1]); if (key && value) { diff --git a/src/utils_ovs.c b/src/utils_ovs.c index 57da628e..65e66795 100644 --- a/src/utils_ovs.c +++ b/src/utils_ovs.c @@ -330,6 +330,9 @@ static yajl_gen_status ovs_yajl_gen_val(yajl_gen jgen, yajl_val jval) { size_t obj_len = 0; yajl_gen_status yajl_gen_ret = yajl_gen_status_ok; + if (jval == NULL) + return yajl_gen_generation_complete; + if (YAJL_IS_STRING(jval)) OVS_YAJL_CALL(ovs_yajl_gen_tstring, jgen, YAJL_GET_STRING(jval)); else if (YAJL_IS_DOUBLE(jval)) @@ -566,7 +569,11 @@ static int ovs_db_json_data_process(ovs_db_t *pdb, const char *data, /* get method name */ if ((jval = yajl_tree_get(jnode, method_path, yajl_t_string)) != NULL) { - method = YAJL_GET_STRING(jval); + if ((method = YAJL_GET_STRING(jval)) == NULL) { + yajl_tree_free(jnode); + sfree(sjson); + return (-1); + } if (strcmp("echo", method) == 0) { /* echo request from the server */ if (ovs_db_table_echo_cb(pdb, jnode) < 0)