diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3fbedb3d9db7676bc5922c77be92afde270bfda8..44264480850cdf8d7c060a0593242b92b2952488 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,7 +1,7 @@ include: - project: 'iopsys/gitlab-ci-pipeline' file: '/static-code-analysis.yml' - ref: '0.32' + ref: '1.2' stages: - static_code_analysis @@ -12,9 +12,9 @@ stages: variables: DEBUG: 'TRUE' SOURCE_FOLDER: "src" - RUN_CPPCHECK: "cppcheck --enable=all --error-exitcode=1 --inline-suppr --suppress=unusedFunction --suppress=unreadVariable --suppress=variableScope --suppress=syntaxError ." - CPPCHECK_OPTIONS: "--enable=all --inline-suppr --error-exitcode=1 --suppress=unmatchedSuppression --suppress=unusedFunction --suppress=unreadVariable --suppress=variableScope --suppress=syntaxError --suppress=missingIncludeSystem --suppress=missingInclude --suppress=constParameter --suppress=redundantAssignment" - RUN_CPD: "/home/user/pmd-bin-6.19.0/bin/run.sh cpd --minimum-tokens 200 --language c --exclude ./test/cmocka --files " + CPPCHECK_OPTIONS: " --enable=all --inline-suppr --error-exitcode=1 --suppress=unusedFunction --suppress=variableScope --suppress=missingInclude --suppress=cert-API01-C" + CPD_OPTIONS: " --minimum-tokens 500 --exclude ./test/cmoka" + COMMON_IMAGE: "dev.iopsys.eu:5050/iopsys/gitlab-ci-pipeline/code-analysis:1.2" run_compile_test: stage: compile_test diff --git a/src/Makefile b/src/Makefile index 0c6861cfa894270488733b5cfcacf2137295a24f..1a99729c39f870d1968f229efd55ea25668dd2a1 100644 --- a/src/Makefile +++ b/src/Makefile @@ -4,6 +4,15 @@ ifdef DEBUG CFLAGS += -O0 -ggdb3 endif +ifeq (,$(findstring EASYMESH_VERSION,$(CFLAGS))) +$(info EASYMESH_VERSION is not set. Build for 6) +EASYMESH_VERSION=6 +CFLAGS+=-DEASYMESH_VERSION=6 +else +EASYMESH_VERSION=$(patsubst -DEASYMESH_VERSION=%,%,$(filter -DEASYMESH_VERSION=%,$(CFLAGS))) +$(info EASYMESH_VERSION passed is $(EASYMESH_VERSION)) +endif + CFLAGS += -I. -I./.. -Wall -Werror -ggdb3 EXECS ?= decollector diff --git a/src/backhaul_topology.c b/src/backhaul_topology.c index 43acfa5854e3fc7f8bf314080152cc78980a2518..dfd3dfc1aa2dc8947f89857c94af2328a04a8577 100644 --- a/src/backhaul_topology.c +++ b/src/backhaul_topology.c @@ -120,7 +120,7 @@ bool has_interface_info_changed(const struct tlv_device_info *tlv_dev_info, tlv_iface_offset = 0; for (i = 0; i < bh_topo_dev->number_of_interfaces; ++i) { const struct local_interface *interface = - (struct local_interface *)(tlv_iface_p + tlv_iface_offset); + (const struct local_interface *)(tlv_iface_p + tlv_iface_offset); if (!hwaddr_equal(bh_topo_dev->ifaces[i].macaddr, interface->macaddr)) return true; @@ -155,7 +155,7 @@ void copy_interface_info_from_tlv(const struct tlv_device_info *tlv_dev_info, tlv_iface_offset = 0; for (i = 0; i < bh_topo_dev->number_of_interfaces; ++i) { const struct local_interface *interface = - (struct local_interface *)(tlv_iface_p + tlv_iface_offset); + (const struct local_interface *)(tlv_iface_p + tlv_iface_offset); memcpy(bh_topo_dev->ifaces[i].macaddr, interface->macaddr, 6); bh_topo_dev->ifaces[i].media_type = diff --git a/src/cmdu.c b/src/cmdu.c index f26026eb1fbdbaa140082d1f0d6b547af41ec364..9d343fb60cc098bcdcfb4a208a3c5c8c0e58b4af 100644 --- a/src/cmdu.c +++ b/src/cmdu.c @@ -2199,7 +2199,7 @@ static void decollector_scanlist_limit(struct wifi_network_device *dev) struct timeval tmo; timeradd_msecs(&sres->tv, WIFI_SCANRESULT_MAX_AGE, &tmo); - if (!timercmp(&tmo, &now, >)) { + if (!timercmp(&tmo, &now, >)) { /* cppcheck-suppress syntaxError */ list_del(&sres->list); radio->num_scanresult--; free_scanresults(sres); diff --git a/src/config.c b/src/config.c index b61f2cd15aac4b830e47d617cf9e589984a6ed49..53af3d011034084e765af10fe3c9e4ca1cb3f7c3 100644 --- a/src/config.c +++ b/src/config.c @@ -8,6 +8,7 @@ #include <libubox/utils.h> #include <uci.h> +#include <error.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -55,17 +56,32 @@ static int cntlr_config_get_ssid(struct uci_section *s, ssid->band = BAND_UNKNOWN; ssid->type = WIFI_BSSTYPE_FBSS; ssid->multi_ap = 2; - ssid->mld_id = -1; + ssid->mld_id = 255; uci_parse_section(s, opts, NUM_SSID_ATTRS, tb); + if (tb[SSID_BAND]) { - if (atoi(tb[SSID_BAND]->v.string) == 6) + char *endptr = NULL; + errno = 0; + int band; + + band = strtol(tb[SSID_BAND]->v.string, &endptr, 10); + if (errno || *endptr != '\0') { + free(ssid); + return -1; + } + + if (band == 6) ssid->band = BAND_6; - else if (atoi(tb[SSID_BAND]->v.string) == 5) + else if (band == 5) ssid->band = BAND_5; - else if (atoi(tb[SSID_BAND]->v.string) == 2) + else if (band == 2) ssid->band = BAND_2; + else { + free(ssid); + return -1; + } } if (tb[SSID_SSID]) { @@ -105,8 +121,15 @@ static int cntlr_config_get_ssid(struct uci_section *s, } } - if (tb[SSID_VLAN]) - ssid->vid = (uint16_t) atoi(tb[SSID_VLAN]->v.string); + if (tb[SSID_VLAN]) { + char *endptr = NULL; + int vid; + + errno = 0; + vid = strtol(tb[SSID_VLAN]->v.string, &endptr, 10); + if (!errno || *endptr == '\0') + ssid->vid = vid; + } if (tb[SSID_TYPE]) { const char *type = tb[SSID_TYPE]->v.string; @@ -126,11 +149,25 @@ static int cntlr_config_get_ssid(struct uci_section *s, } } - if (tb[SSID_ENABLED]) - ssid->enabled = atoi(tb[SSID_ENABLED]->v.string); + if (tb[SSID_ENABLED]) { + char *endptr = NULL; + int enabled; + + errno = 0; + enabled = strtol(tb[SSID_ENABLED]->v.string, &endptr, 10); + if (!errno || *endptr == '\0') + ssid->enabled = enabled; + } + + if (tb[SSID_MLD_ID]) { + char *endptr = NULL; + int mld_id; - if (tb[SSID_MLD_ID]) - ssid->mld_id = atoi(tb[SSID_MLD_ID]->v.string); + errno = 0; + mld_id = strtol(tb[SSID_MLD_ID]->v.string, &endptr, 10); + if (!errno || *endptr == '\0') + ssid->mld_id = mld_id; + } *num += 1; list_add_tail(&ssid->list, ssidlist); @@ -160,6 +197,8 @@ static int cntlr_config_get_mld(struct uci_section *s, }; struct uci_option *tb[NUM_MLD_ATTRS]; struct wifi_network_mld *mld; + char *endptr = NULL; + int mld_id; uci_parse_section(s, opts, NUM_MLD_ATTRS, tb); @@ -174,10 +213,20 @@ static int cntlr_config_get_mld(struct uci_section *s, mld->enabled = true; mld->type = WIFI_BSSTYPE_FBSS; mld->multi_ap = 2; - mld->id = atoi(tb[MLD_ID]->v.string); - if (tb[MLD_ENABLED]) - mld->enabled = atoi(tb[MLD_ENABLED]->v.string); + errno = 0; + mld_id = strtol(tb[MLD_ID]->v.string, &endptr, 10); + if (!errno || *endptr == '\0') + mld->id = mld_id; + + if (tb[MLD_ENABLED]) { + int enabled; + + errno = 0; + enabled = strtol(tb[MLD_ENABLED]->v.string, &endptr, 10); + if (!errno || *endptr == '\0') + mld->enabled = enabled; + } if (tb[MLD_SSID]) { strncpy(mld->ssid, tb[MLD_SSID]->v.string, 32); @@ -257,11 +306,25 @@ static int cntlr_config_get_globals(struct uci_section *s, uci_parse_section(s, opts, NUM_CNTLR_ATTRS, tb); - if (tb[CNTLR_NETWORK_PVID]) - net->primary_vid = atoi(tb[CNTLR_NETWORK_PVID]->v.string); + if (tb[CNTLR_NETWORK_PVID]) { + char *endptr = NULL; + int pvid; + + errno = 0; + pvid = strtol(tb[CNTLR_NETWORK_PVID]->v.string, &endptr, 10); + if (!errno || *endptr == '\0') + net->primary_vid = pvid; + } + + if (tb[CNTLR_NETWORK_PCP]) { + char *endptr = NULL; + int pcp; - if (tb[CNTLR_NETWORK_PCP]) - net->default_pcp = atoi(tb[CNTLR_NETWORK_PCP]->v.string); + errno = 0; + pcp = strtol(tb[CNTLR_NETWORK_PCP]->v.string, &endptr, 10); + if (!errno || *endptr == '\0') + net->default_pcp = pcp; + } if (tb[CNTLR_NETWORK_ID]) uuid_strtob(tb[CNTLR_NETWORK_ID]->v.string, (uint8_t *)net->id); @@ -286,7 +349,13 @@ static int cntlr_config_get_sta_steer(struct uci_section *s, uci_parse_section(s, opts, NUM_STA_STEER_ATTRS, tb); if (tb[STA_STEER_ENABLED]) { - enabled = atoi(tb[STA_STEER_ENABLED]->v.string) == 1 ? true : false; + char *endptr = NULL; + int enbl; + + errno = 0; + enbl = strtol(tb[STA_STEER_ENABLED]->v.string, &endptr, 10); + if (!errno || *endptr == '\0') + enabled = (enbl == 1) ? true : false; } list_for_each_entry(dev, &net->devicelist, list) { @@ -361,23 +430,43 @@ static int cntlr_config_get_agent_node(struct uci_section *s, return 0; if (tb[NODE_RPT_ASSOC_FAILS]) { - dev->report.sta_assocfails = - atoi(tb[NODE_RPT_ASSOC_FAILS]->v.string) == 1 ? true : false; + char *endptr = NULL; + int enbl; + + errno = 0; + enbl = strtol(tb[NODE_RPT_ASSOC_FAILS]->v.string, &endptr, 10); + if (!errno || *endptr == '\0') + dev->report.sta_assocfails = ((enbl == 1) ? true : false); } if (tb[NODE_RPT_ASSOC_FAILS_RATE]) { - dev->report.sta_assocfails_rate = - atoi(tb[NODE_RPT_ASSOC_FAILS_RATE]->v.string); + char *endptr = NULL; + int rate; + + errno = 0; + rate = strtol(tb[NODE_RPT_ASSOC_FAILS_RATE]->v.string, &endptr, 10); + if (!errno || *endptr == '\0') + dev->report.sta_assocfails_rate = rate; } if (tb[NODE_RPT_SCAN]) { - dev->report.independent_scans = - atoi(tb[NODE_RPT_SCAN]->v.string) == 1 ? true : false; + char *endptr = NULL; + int enbl; + + errno = 0; + enbl = strtol(tb[NODE_RPT_SCAN]->v.string, &endptr, 10); + if (!errno || *endptr == '\0') + dev->report.independent_scans = ((enbl == 1) ? true : false); } if (tb[NODE_RPT_METRIC_PERIODIC]) { - dev->report.ap_metrics_int = - atoi(tb[NODE_RPT_METRIC_PERIODIC]->v.string); + char *endptr = NULL; + int metrics; + + errno = 0; + metrics = strtol(tb[NODE_RPT_METRIC_PERIODIC]->v.string, &endptr, 10); + if (!errno || *endptr == '\0') + dev->report.ap_metrics_int = metrics; } if (tb[NODE_STEER_EXCLUDE]) { @@ -408,11 +497,25 @@ static int cntlr_config_get_agent_node(struct uci_section *s, } } - if (tb[NODE_COORDINATED_CAC]) - dev->coordinated_cac_allowed = atoi(tb[NODE_COORDINATED_CAC]->v.string) == 1 ? true : false; + if (tb[NODE_COORDINATED_CAC]) { + char *endptr = NULL; + int enbl; - if (tb[NODE_TRAFFIC_SEPARATION]) - dev->ts_allowed = atoi(tb[NODE_TRAFFIC_SEPARATION]->v.string) == 1 ? true : false; + errno = 0; + enbl = strtol(tb[NODE_COORDINATED_CAC]->v.string, &endptr, 10); + if (!errno || *endptr == '\0') + dev->coordinated_cac_allowed = ((enbl == 1) ? true : false); + } + + if (tb[NODE_TRAFFIC_SEPARATION]) { + char *endptr = NULL; + int enbl; + + errno = 0; + enbl = strtol(tb[NODE_TRAFFIC_SEPARATION]->v.string, &endptr, 10); + if (!errno || *endptr == '\0') + dev->ts_allowed = ((enbl == 1) ? true : false); + } /* TODO: use policy to update per-node steering state (enabled/disabled) */ /* diff --git a/src/dump2.c b/src/dump2.c index 69692f1f1d22d5eb73113bffdb5f7aba6aa62fed..0c617bf5cf1f8b5d11281ff2f82cd0808e944fff 100644 --- a/src/dump2.c +++ b/src/dump2.c @@ -421,7 +421,7 @@ static void dump2_network_device_anticipatedchannelsusage(struct decollector_pri char hexbin_str[2 * MAX_RU_BITMASK_LENGTH + 1] = { 0 }; void *entry_table = blobmsg_open_table(bb, ""); int i; - const uint8_t *time = (uint8_t *)&entry->burst_start_time; + const uint8_t *time = (const uint8_t *)&entry->burst_start_time; // todo: hexBinary(4), what byte order? snprintf(hexbin_str, 2 * 4 + 1, "%02x%02x%02x%02x", time[0], time[1], time[2], time[3]); @@ -1668,7 +1668,7 @@ static void dump2_network_ssid(struct blob_buf *bb, struct wifi_network_ssid *ss void *t; /* Only show non-affiliated SSIDs in this list */ - if ((int8_t)ssid->mld_id != -1) + if (ssid->mld_id != 255) return; /* Device.WiFi.DataElements.Network.SSID.{i}. */ diff --git a/src/main.c b/src/main.c index 557a2f28fc5d55083c2c38d57dcb10b554148538..60ef299b8a517a950982b31d08762b10e148c9d9 100644 --- a/src/main.c +++ b/src/main.c @@ -21,6 +21,7 @@ #include <libubox/uloop.h> #include <libubox/utils.h> +#include <errno.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> @@ -76,6 +77,7 @@ int main(int argc, char **argv) void *decollector_handle; int ret; int ch; + char *endptr = NULL; while ((ch = getopt(argc, argv, "hvDt:dlp:s:r:o:f")) != -1) { @@ -90,9 +92,13 @@ int main(int argc, char **argv) opts.ubus_sockpath = optarg; break; case 't': - opts.refresh_int = atoi(optarg); - if (opts.refresh_int < DECOLLECTOR_REFRESH_INT) + errno = 0; + opts.refresh_int = strtol(optarg, &endptr, 10); + if (errno || *endptr != '\0' || + opts.refresh_int < DECOLLECTOR_REFRESH_INT) { + fprintf(stderr, "Invalid refresh interval: %s, using default\n", optarg); opts.refresh_int = DECOLLECTOR_REFRESH_INT; + } break; case 'C': @@ -110,7 +116,12 @@ int main(int argc, char **argv) opts.pidfile = optarg; break; case 'r': - opts.em_profile = atoi(optarg); + errno = 0; + opts.em_profile = strtol(optarg, &endptr, 10); + if (errno || *endptr != '\0') { + fprintf(stderr, "Invalid Multi-AP profile: %s\n", optarg); + opts.em_profile = 0; + } break; case 'o': opts.logfile = optarg; diff --git a/src/utils.c b/src/utils.c index 2a81b4f7a586e917a24e0d4158580512fa05386f..642dd203db2acbec8081ce2ba1f37515a294165f 100644 --- a/src/utils.c +++ b/src/utils.c @@ -20,21 +20,28 @@ #include <sys/types.h> #include <sys/time.h> - +/* Get UTC date in ISO 8601 format */ char *get_date(time_t *t, char *tbuf) { char tmpbuf[32] = {0}; const time_t now = time(t); + struct tm timeinfo; if (!tbuf) return NULL; - snprintf(tmpbuf, sizeof(tmpbuf), "%s", ctime(&now)); - tmpbuf[strlen(tmpbuf) - 1] = '\0'; + gmtime_r(&now, &timeinfo); + strftime(tmpbuf, sizeof(tmpbuf), "%Y-%m-%dT%H:%M:%SZ", &timeinfo); snprintf(tbuf, 32, "%s", tmpbuf); + if (tbuf[0] == '\0') { + fprintf(stderr, "Error: get_date() failed\n"); + return NULL; + } + tbuf[31] = '\0'; return tbuf; } + char *get_timestamp(const time_t *t, char *timestamp_str, size_t size) { struct tm res;