diff --git a/dmentryjson.c b/dmentryjson.c index 33de285a..45afe181 100644 --- a/dmentryjson.c +++ b/dmentryjson.c @@ -125,7 +125,7 @@ int check_stats_json_folder(char *json_folder_path) { int file_count = 0; unsigned long size = 0, date = 0; - char str[64] = ""; + char str[128] = ""; if (!get_stats_json_folder(json_folder_path, &file_count, &size, &date)) return 0; @@ -140,7 +140,7 @@ int check_stats_json_folder(char *json_folder_path) static void generate_prefixobj_and_obj_full_obj(char *full_obj, char **prefix_obj, char **obj) { - char *pch, *pchr, *tmp_obj = NULL, *str = NULL; + char *pch = NULL, *pchr = NULL, *tmp_obj = NULL, *str = NULL; str = dmstrdupjson(full_obj); for (pch = strtok_r(str, ".", &pchr); pch != NULL; pch = strtok_r(NULL, ".", &pchr)) { @@ -162,7 +162,7 @@ static void generate_prefixobj_and_obj_full_obj(char *full_obj, char **prefix_ob static char *generate_obj_without_instance(char *full_obj, bool is_obj) { - char *pch, *pchr, *tmp_obj = NULL, *str = NULL, *obj = NULL; + char *pch = NULL, *pchr = NULL, *tmp_obj = NULL, *str = NULL, *obj = NULL; str = dmstrdupjson(full_obj); for (pch = strtok_r(str, ".", &pchr); pch != NULL; pch = strtok_r(NULL, ".", &pchr)) { diff --git a/dmentrylibrary.c b/dmentrylibrary.c index 043de858..178da637 100644 --- a/dmentrylibrary.c +++ b/dmentrylibrary.c @@ -49,7 +49,7 @@ int check_stats_library_folder(char *library_folder_path) { int file_count = 0; unsigned long size = 0, date = 0; - char str[64] = ""; + char str[128] = ""; if (!get_stats_library_folder(library_folder_path, &file_count, &size, &date)) return 0; diff --git a/dmtree/tr104/voice_services.c b/dmtree/tr104/voice_services.c index 693272c9..a51c8fa0 100644 --- a/dmtree/tr104/voice_services.c +++ b/dmtree/tr104/voice_services.c @@ -285,7 +285,7 @@ static int get_cfg_sipidx(void) static int add_profile_object(char *refparam, struct dmctx *ctx, void *data, char **instancepara) { struct uci_section *dmmap_voice_section = NULL; - char sname[8], account[16], *instance, *v; + char sname[16], account[32], *instance, *v; check_create_dmmap_package("dmmap_voice_client"); int sipidx = get_cfg_sipidx(); @@ -418,7 +418,7 @@ static char *update_vp_line_instance(struct uci_section *tel_s, char *sipx) { struct uci_section *s = NULL, *dmmap_section = NULL, *dmmap_dup = NULL; int last_instance = 0, i_instance; - char *instance, buf[8]; + char *instance, buf[16]; get_dmmap_section_of_config_section("dmmap_voice_client", "tel_line", section_name(tel_s), &dmmap_section); if (dmmap_section) @@ -1748,7 +1748,7 @@ static int get_line_sip_uri(char *refparam, struct dmctx *ctx, void *data, char static int set_line_sip_uri(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - char *pch, *spch, *str1; + char *pch, *spch = NULL, *str1; struct tel_args *telargs = (struct tel_args *)data; switch (action) { diff --git a/dmtree/tr157/softwaremodules.c b/dmtree/tr157/softwaremodules.c index a39752d6..69366daf 100644 --- a/dmtree/tr157/softwaremodules.c +++ b/dmtree/tr157/softwaremodules.c @@ -60,7 +60,7 @@ static int browseSoftwareModulesExecEnvInst(struct dmctx *dmctx, DMNODE *parent_ static int browseSoftwareModulesDeploymentUnitInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { json_object *res = NULL, *du_obj = NULL, *arrobj = NULL; - char *idx, *idx_last = NULL, buf[5]; + char *idx, *idx_last = NULL, buf[16]; int id = 0, j = 0, i, incr; for (i = 0;; i += 100) { @@ -118,7 +118,7 @@ static int get_SoftwareModules_DeploymentUnitNumberOfEntries(char *refparam, str { json_object *res = NULL, *deployment_unit = NULL; size_t nbre_du = 0, total_du = 0; - char buf[5]; + char buf[16]; int i; for (i = 0;; i += 100) { @@ -651,7 +651,7 @@ static int get_SoftwareModulesExecutionUnit_MemoryInUse(char *refparam, struct d static int get_SoftwareModulesExecutionUnit_References(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res = NULL, *du_obj = NULL, *arrobj = NULL; - char *environment, *name, *curr_environment, *curr_name, buf[5]; + char *environment, *name, *curr_environment, *curr_name, buf[16]; int j = 0, env = 0, i, incr; curr_name = dmjson_get_value((json_object *)data, 1, "name"); @@ -752,7 +752,7 @@ void get_deployment_unit_name_version(char *uuid, char **name, char **version, c { json_object *res = NULL, *du_obj = NULL, *arrobj = NULL; int j = 0, i, incr; - char *cur_uuid, buf[5]; + char *cur_uuid, buf[16]; for (i = 0;; i += 100) { snprintf(buf, sizeof(buf), "%d", i); @@ -779,7 +779,7 @@ char *get_softwaremodules_uuid(char *url) { json_object *res = NULL, *du_obj = NULL, *arrobj = NULL; int j = 0, i, incr; - char *cur_url, *uuid = "", buf[5]; + char *cur_url, *uuid = "", buf[16]; for (i = 0;; i += 100) { snprintf(buf, sizeof(buf), "%d", i); @@ -805,7 +805,7 @@ char *get_softwaremodules_url(char *uuid) { json_object *res = NULL, *du_obj = NULL, *arrobj = NULL; int j = 0, i, incr; - char *cur_uuid, *url = "", buf[5]; + char *cur_uuid, *url = "", buf[16]; for (i = 0;; i += 100) { snprintf(buf, sizeof(buf), "%d", i); diff --git a/dmtree/tr181/bridging.c b/dmtree/tr181/bridging.c index b1ac09a3..e5a0d2a0 100644 --- a/dmtree/tr181/bridging.c +++ b/dmtree/tr181/bridging.c @@ -1175,7 +1175,7 @@ static int add_br_vlanport(char *refparam, struct dmctx *ctx, void *data, char * /* To add Bridge.VLANPort object from the management methods. */ struct bridging_args *br_args = (struct bridging_args *)data; - char *br_ifname_list, *br_ifname_dup, *pch, *spch; + char *br_ifname_list, *br_ifname_dup, *pch = NULL, *spch = NULL; /* Check if the section name has tagged ifname or not. */ dmuci_get_value_by_section_string(br_args->bridge_sec, "ifname", &br_ifname_list); @@ -2050,7 +2050,7 @@ static int browseBridgeInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev static int browseBridgePortInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance){ struct uci_section *new_port = NULL, *ss_atm = NULL, *ss_ptm = NULL; - char *port = NULL, *port_last = NULL, *ifname_dup = NULL, *pch, *spch, *is_dmmap, *deviceatm, *deviceptm, *atm_device, *ptm_device; + char *port = NULL, *port_last = NULL, *ifname_dup = NULL, *pch = NULL, *spch = NULL, *is_dmmap, *deviceatm, *deviceptm, *atm_device, *ptm_device; bool find_max = true, found = false; struct bridging_port_args curr_bridging_port_args = {0}; struct dmmap_dup *p = NULL; @@ -2060,7 +2060,7 @@ static int browseBridgePortInst(struct dmctx *dmctx, DMNODE *parent_node, void * update_section_list_bbfdm("dmmap_bridge_port","bridge_port", "bridge_key", 1, ((struct bridging_args *)prev_data)->br_key, "mg_port", "true", "bridge_port_instance", "1"); uci_path_foreach_option_eq(bbfdm, "dmmap_bridge_port", "bridge_port", "bridge_key", ((struct bridging_args *)prev_data)->br_key, new_port) { dmuci_get_value_by_section_string(new_port, "is_dmmap", &is_dmmap); - if(strcmp(is_dmmap, "false") !=0 ) { + if (strcmp(is_dmmap, "false") != 0) { init_bridging_port_args(&curr_bridging_port_args, new_port, ((struct bridging_args *)prev_data)->bridge_sec, false, ""); port = handle_update_instance(2, dmctx, &port_last, update_instance_alias_bbfdm, 5, new_port, "bridge_port_instance", "bridge_port_alias", &find_max, ((struct bridging_args *)prev_data)->br_key); if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_bridging_port_args, port) == DM_STOP) @@ -2198,7 +2198,7 @@ static int browseBridgeVlanPortInst(struct dmctx *dmctx, DMNODE *parent_node, vo { int cnt = 1; char *vlan; - char *br_ifname_list, *br_ifname_dup, *pch, *spch; + char *br_ifname_list, *br_ifname_dup, *pch = NULL, *spch = NULL; struct bridging_vlan_args curr_bridging_vlan_args = {0}; struct bridging_args *br_args = (struct bridging_args *)prev_data; struct uci_section *sec = NULL; diff --git a/dmtree/tr181/deviceinfo.c b/dmtree/tr181/deviceinfo.c index d7fa84b6..23a26a58 100644 --- a/dmtree/tr181/deviceinfo.c +++ b/dmtree/tr181/deviceinfo.c @@ -89,11 +89,11 @@ static int get_device_info_uptime(char *refparam, struct dmctx *ctx, void *data, *value = "0"; fp = fopen(UPTIME, "r"); - if (fp != NULL) { - fgets(buf, 64, fp); - pch = strtok_r(buf, ".", &spch); - if (pch) - *value = dmstrdup(pch); // MEM WILL BE FREED IN DMMEMCLEAN + if (fp != NULL) { + if (fgets(buf, 64, fp) != NULL) { + pch = strtok_r(buf, ".", &spch); + *value = (pch) ? dmstrdup(pch) : "0"; + } fclose(fp); } return 0; diff --git a/dmtree/tr181/dhcpv4.c b/dmtree/tr181/dhcpv4.c index ecf708a5..abed98f8 100644 --- a/dmtree/tr181/dhcpv4.c +++ b/dmtree/tr181/dhcpv4.c @@ -945,7 +945,7 @@ static int get_dhcp_reserved_addresses(char *refparam, struct dmctx *ctx, void * static int set_dhcp_reserved_addresses(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { struct uci_section *s = NULL, *dhcp_section = NULL; - char *min, *max, *val, *local_value, *pch, *spch; + char *min, *max, *val, *local_value, *pch, *spch = NULL; unsigned int n_min, n_max, n_ip, ipexist= 0; switch (action) { @@ -1057,7 +1057,7 @@ static int set_dhcp_iprouters(char *refparam, struct dmctx *ctx, void *data, cha static int get_dhcp_leasetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { int mtime = 0; - char *ltime = "", *pch, *spch, *ltime_ini, *tmp, *tmp_ini; + char *ltime = "", *pch, *spch = NULL, *ltime_ini, *tmp, *tmp_ini; struct uci_section *s = NULL; uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcp_args *)data)->interface, s) { @@ -1722,7 +1722,7 @@ static int get_DHCPv4ClientSentOption_Tag(char *refparam, struct dmctx *ctx, voi static int set_DHCPv4ClientSentOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - char *pch, *spch, *list, *v, *opttagvalue, **sendopts, *oldopttagvalue; + char *pch, *spch = NULL, *list, *v, *opttagvalue, **sendopts, *oldopttagvalue; size_t length; switch (action) { diff --git a/dmtree/tr181/dynamicdns.c b/dmtree/tr181/dynamicdns.c index 9e481c63..79c3f710 100644 --- a/dmtree/tr181/dynamicdns.c +++ b/dmtree/tr181/dynamicdns.c @@ -663,19 +663,21 @@ static int get_DynamicDNSClientHostname_LastUpdate(char *refparam, struct dmctx fp = fopen(path, "r"); if (fp != NULL) { - fgets(buf, 16, fp); - pch = strtok_r(buf, "\n", &spch); + if (fgets(buf, 16, fp) != NULL) { + pch = strtok_r(buf, "\n", &spch); + last_time = (pch) ? dmstrdup(pch) : "0"; + } fclose(fp); - last_time = dmstrdup(pch); } else last_time = "0"; fp = fopen("/proc/uptime", "r"); if (fp != NULL) { - fgets(buf, 16, fp); - pch = strtok_r(buf, ".", &spch); + if (fgets(buf, 16, fp) != NULL) { + pch = strtok_r(buf, ".", &spch); + uptime = (pch) ? dmstrdup(pch) : "0"; + } fclose(fp); - uptime = dmstrdup(pch); } else uptime = "0"; diff --git a/dmtree/tr181/ip.c b/dmtree/tr181/ip.c index df3f7ee1..8878286f 100644 --- a/dmtree/tr181/ip.c +++ b/dmtree/tr181/ip.c @@ -1780,7 +1780,7 @@ static struct uci_section *update_dmmap_network_ipv6(char *curr_inst, char *sect static int browseIfaceIPv6Inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { struct uci_section *s; - char *ipv6_int = NULL, *ipv6_int_last = NULL, *ipv6addr = "", *ipv6mask = "", *ipv6_preferred = "", *ipv6_valid = "", buf[4]=""; + char *ipv6_int = NULL, *ipv6_int_last = NULL, *ipv6addr = "", *ipv6mask = "", *ipv6_preferred = "", *ipv6_valid = "", buf[16]=""; struct ipv6_args curr_ipv6_args = {0}; json_object *res, *jobj, *jobj1; int entries = 0; @@ -1853,7 +1853,7 @@ static struct uci_section *update_dmmap_network_ipv6prefix(char *curr_inst, char static int browseIfaceIPv6PrefixInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { struct uci_section *s; - char *ipv6prefix_int = NULL, *ipv6prefix_int_last = NULL, *ipv6prefixaddr = "", *ipv6prefixmask = "", *ipv6prefix_preferred = "", *ipv6prefix_valid = "", buf[4] = ""; + char *ipv6prefix_int = NULL, *ipv6prefix_int_last = NULL, *ipv6prefixaddr = "", *ipv6prefixmask = "", *ipv6prefix_preferred = "", *ipv6prefix_valid = "", buf[16] = ""; struct ipv6prefix_args curr_ipv6prefix_args = {0}; json_object *res, *jobj; int entries = 0; diff --git a/dmtree/tr181/routing.c b/dmtree/tr181/routing.c index ad728407..cd880ec4 100644 --- a/dmtree/tr181/routing.c +++ b/dmtree/tr181/routing.c @@ -105,16 +105,18 @@ static bool is_cfg_route_active(struct uci_section *s) char line[MAX_PROC_ROUTING]; struct proc_routing proute; char *dest, *mask; + int lines = 0; dmuci_get_value_by_section_string(s, "target", &dest); dmuci_get_value_by_section_string(s, "netmask", &mask); fp = fopen(ROUTING_FILE, "r"); if (fp != NULL) { - fgets(line, MAX_PROC_ROUTING, fp); while (fgets(line, MAX_PROC_ROUTING, fp) != NULL) { - if (line[0] == '\n') + if (line[0] == '\n' || lines == 0) { /* skip the first line or skip the line if it's empty */ + lines++; continue; + } parse_proc_route_line(line, &proute); if (strcmp(dest, proute.destination) == 0 && (mask[0] == '\0' || strcmp(mask, proute.mask) == 0)) { @@ -261,7 +263,7 @@ static int dmmap_synchronizeRoutingRouterIPv4Forwarding(struct dmctx *dmctx, DMN json_object *jobj; FILE* fp = NULL; char *target, *iface, *name, *instance, *str, line[MAX_PROC_ROUTING]; - int found, last_inst; + int found, last_inst, lines; check_create_dmmap_package("dmmap_route_forwarding"); uci_path_foreach_sections_safe(bbfdm, "dmmap_route_forwarding", "route_dynamic", stmp, s) { @@ -270,10 +272,12 @@ static int dmmap_synchronizeRoutingRouterIPv4Forwarding(struct dmctx *dmctx, DMN found = 0; fp = fopen(ROUTING_FILE, "r"); if ( fp != NULL) { - fgets(line, MAX_PROC_ROUTING, fp); + lines = 0; while (fgets(line, MAX_PROC_ROUTING, fp) != NULL) { - if (line[0] == '\n') + if (line[0] == '\n' || lines == 0) { /* skip the first line or skip the line if it's empty */ + lines++; continue; + } parse_proc_route_line(line, &proute); if ((strcmp(iface, proute.iface) == 0) && strcmp(target, proute.destination) == 0) { found = 1; @@ -288,10 +292,12 @@ static int dmmap_synchronizeRoutingRouterIPv4Forwarding(struct dmctx *dmctx, DMN fp = fopen(ROUTING_FILE, "r"); if ( fp != NULL) { - fgets(line, MAX_PROC_ROUTING, fp); + lines = 0; while (fgets(line, MAX_PROC_ROUTING, fp) != NULL) { - if (line[0] == '\n') + if (line[0] == '\n' || lines == 0) { /* skip the first line or skip the line if it's empty */ + lines++; continue; + } parse_proc_route_line(line, &proute); if (is_proc_route_in_config(&proute)) continue; diff --git a/libbbf_api/dmcommon.c b/libbbf_api/dmcommon.c index b2a5d786..ae2c45d2 100644 --- a/libbbf_api/dmcommon.c +++ b/libbbf_api/dmcommon.c @@ -588,7 +588,7 @@ void update_section_list(char *config, char *section, char *option, int number, int wan_remove_dev_interface(struct uci_section *interface_setion, char *dev) { - char *ifname, new_ifname[64], *p, *pch, *spch; + char *ifname, new_ifname[64], *p, *pch = NULL, *spch = NULL; new_ifname[0] = '\0'; p = new_ifname; dmuci_get_value_by_section_string(interface_setion, "ifname", &ifname); @@ -1563,7 +1563,7 @@ void add_elt_to_str_list(char **str_list, char *elt) void remove_elt_from_str_list(char **iface_list, char *ifname) { - char *list = NULL, *tmp = NULL, *pch, *spch; + char *list = NULL, *tmp = NULL, *pch = NULL, *spch = NULL; if (*iface_list == NULL || strlen(*iface_list) == 0) return; diff --git a/libbbf_api/dmcommon.h b/libbbf_api/dmcommon.h index daef29ef..2dcb989c 100644 --- a/libbbf_api/dmcommon.h +++ b/libbbf_api/dmcommon.h @@ -13,6 +13,10 @@ #ifndef __DM_COMMON_H #define __DM_COMMON_H +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + #include #include #include diff --git a/libbbf_api/dmuci.c b/libbbf_api/dmuci.c index c49b273f..7fbefc33 100644 --- a/libbbf_api/dmuci.c +++ b/libbbf_api/dmuci.c @@ -187,7 +187,7 @@ int dmuci_get_option_value_list(char *package, char *section, char *option, stru struct uci_element *e; struct uci_ptr ptr = {0}; struct uci_list *list; - char *pch, *spch, *dup; + char *pch = NULL, *spch = NULL, *dup; *value = NULL; if (dmuci_lookup_ptr(uci_ctx, &ptr, package, section, option, NULL)) { @@ -601,7 +601,7 @@ int dmuci_get_value_by_section_list(struct uci_section *s, char *option, struct struct uci_element *e; struct uci_option *o; struct uci_list *list; - char *pch, *spch, *dup; + char *pch = NULL, *spch = NULL, *dup; *value = NULL; uci_foreach_element(&s->options, e) {