Skip to content

Commit

Permalink
unum: misc code cleanup from coverity (#49)
Browse files Browse the repository at this point in the history
MIN-10478
  • Loading branch information
Tom-Keddie authored Dec 21, 2021
1 parent 8668206 commit 076a537
Show file tree
Hide file tree
Showing 17 changed files with 21 additions and 31 deletions.
3 changes: 2 additions & 1 deletion src/unum/cmdproc/pingflood.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ static int do_flood(unsigned char *mac,
return -3;
}
if((W_COUNTERS_MIF & wc_after.flags) != 0) {
log("%s: warning, " MAC_PRINTF_FMT_TPL " \n",
log("%s: warning, " MAC_PRINTF_FMT_TPL
" mac was seen on multiple intefaces %s/%s\n",
__func__, MAC_PRINTF_ARG_TPL(mac),
wc_before.ifname, wc_after.ifname);
}
Expand Down
5 changes: 0 additions & 5 deletions src/unum/config/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,6 @@ static void config(THRD_PARAM_t *p)
"Accept: application/json\0",
cstr, cstr_len);

// No longer need the JSON string
platform_cfg_free(cstr);
cstr = NULL;
cstr_len = 0;

if(rsp == NULL || (rsp->code / 100) != 2) {
log("%s: request error, code %d%s\n",
__func__, rsp ? rsp->code : 0, rsp ? "" : "(none)");
Expand Down
8 changes: 4 additions & 4 deletions src/unum/conncheck/conncheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,13 @@ static void conncheck_mk_info_file(void)
char *no_dns = cc_st.no_dns ? "1" : NULL;
char *no_servers = cc_st.no_servers ? "1" : NULL;
char *slist_ready = cc_st.slist_ready ? "1" : NULL;
char *luci_rpc_supported = platform_luci_rpc_supported
char *luci_rpc_supported = platform_luci_rpc_supported != NULL
&& platform_luci_rpc_supported() ? "1" : "0";
char *luci_rpc_wan_dhcpv4_supported = platform_luci_rpc_wan_dhcpv4_supported
char *luci_rpc_wan_dhcpv4_supported = platform_luci_rpc_wan_dhcpv4_supported != NULL
&& platform_luci_rpc_wan_dhcpv4_supported() ? "1" : NULL;
char *luci_rpc_wan_pppoe_supported = platform_luci_rpc_wan_pppoe_supported
char *luci_rpc_wan_pppoe_supported = platform_luci_rpc_wan_pppoe_supported != NULL
&& platform_luci_rpc_wan_pppoe_supported() ? "1" : NULL;
char *luci_rpc_wan_static_supported = platform_luci_rpc_wan_static_supported
char *luci_rpc_wan_static_supported = platform_luci_rpc_wan_static_supported != NULL
&& platform_luci_rpc_wan_static_supported() ? "1" : NULL;

unsigned long *p_connect_uptime = NULL;
Expand Down
4 changes: 0 additions & 4 deletions src/unum/devtelemetry/dt_sender.c
Original file line number Diff line number Diff line change
Expand Up @@ -585,10 +585,6 @@ static void dt_sender(THRD_PARAM_t *p)
"Accept: application/json\0",
jstr, strlen(jstr));

// No longer need the JSON string
util_free_json_str(jstr);
jstr = NULL;

if(rsp == NULL || (rsp->code / 100) != 2) {
log("%s: request error, code %d%s\n",
__func__, rsp ? rsp->code : 0, rsp ? "" : "(none)");
Expand Down
2 changes: 1 addition & 1 deletion src/unum/fw_update/fw_update.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ static void fw_update(void)
if(!have_fw_storage_addr && conncheck_no_dns())
{
log("%s: no IP for %s during DNS outage, restarting...\n",
__func__);
__func__, download_url);
// In updater mode the agent runs under monitor and
// util_restart() works
util_restart(UNUM_START_REASON_FW_CONN_FAIL);
Expand Down
4 changes: 0 additions & 4 deletions src/unum/iptables/iptables.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@ static void iptables_telemetry(THRD_PARAM_t *p)
"Accept: application/json\0",
jstr, strlen(jstr));

// No longer need the JSON string
util_free_json_str(jstr);
jstr = NULL;

if(rsp == NULL || (rsp->code / 100) != 2) {
log("%s: request error, code %d%s\n",
__func__, rsp ? rsp->code : 0, rsp ? "" : "(none)");
Expand Down
2 changes: 1 addition & 1 deletion src/unum/security/port_scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ static int report_device_scan(json_t *device, const char *mac,
}
#endif // DEBUG

http_rsp *rsp = http_post(url, NULL, json, strlen(json));
rsp = http_post(url, NULL, json, strlen(json));
if(rsp == NULL) {
ret = -2;
} else {
Expand Down
4 changes: 0 additions & 4 deletions src/unum/telemetry/telemetry.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,6 @@ static void telemetry(THRD_PARAM_t *p)
"Accept: application/json\0",
jstr, strlen(jstr));

// No longer need the JSON string
util_free_json_str(jstr);
jstr = NULL;

// While the sequence number is 0 we will not bump it up until
// know that the request is processed by the server. After that
// bump it up after each attempt to send the router telemetry.
Expand Down
2 changes: 1 addition & 1 deletion src/unum/unum.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ static void do_daemon(void)
// Change the working directory to the root
int res = chdir("/");
if(res != 0) {
log("%s: chdir() failed: %s\n", __func__, strerror(res));
log("%s: chdir() failed: %s\n", __func__, strerror(errno));
}

// Close all open file descriptors
Expand Down
2 changes: 1 addition & 1 deletion src/unum/util/jobs.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ int util_set_main_thrd()
thrd_ptr = (UTIL_THRD_t *)pthread_getspecific(thrd_key);
if(thrd_ptr != NULL) {
log("%s: error, pointer for key %p is not NULL (%p)\n",
__func__, thrd_key, thrd_ptr);
__func__, (void*) thrd_key, thrd_ptr);
ret = -1;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/unum/util/lede_generic/util_platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ char *platform_fw_version(void)
*end = 0;
}
}
if(val && strlen(val) > 0) {
if(strlen(val) > 0) {
strncpy(owrt_version, val, sizeof(owrt_version) - 1);
ret = owrt_version;
}
Expand Down
4 changes: 3 additions & 1 deletion src/unum/util/util_crashinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ static int crashinfo_maps(char *buf, int buf_len,
if(r_start <= pr->ip && pr->ip < r_end) {
pr->ip_r_start = r_start;
pr->ip_r_end = r_end;
strncpy(pr->ip_r_name, name, sizeof(pr->ip_r_name));
if (name) {
strncpy(pr->ip_r_name, name, sizeof(pr->ip_r_name));
}
pr->ip_r_name[sizeof(pr->ip_r_name) - 1] = 0;
PRNBUF(" ip@%p+%p", r_start, (void *)(pr->ip - r_start));
pr->flags |= UTIL_REGINFO_IP_MAPS;
Expand Down
2 changes: 1 addition & 1 deletion src/unum/util/util_dns.c
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ void util_build_url(char *proto, int type, char *url, unsigned int length,
if(unum_config.url_prefix) {
// Unum Config Contains Custom URL Prefix
count = snprintf(url, length, "%s", unum_config.url_prefix);
} else if(servers[type]) {
} else if(servers[type][0] != '\0') {
// Use URL Mapping
count = snprintf(url, length, "%s://%s", proto, servers[type]);
} else {
Expand Down
3 changes: 3 additions & 0 deletions src/unum/util/util_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ void util_event_init(UTIL_EVENT_t *e)
{
pthread_mutex_init(&e->m, 0);
pthread_cond_init(&e->c, 0);

pthread_mutex_lock(&e->m);
e->is_set = FALSE;
pthread_mutex_unlock(&e->m);
}

// Signal an event (unblocks one or all threads waiting,
Expand Down
2 changes: 1 addition & 1 deletion src/unum/util/util_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ TIMER_HANDLE_t util_timer_set(unsigned int msecs, const char *name,
{
TIMER_HANDLE_t th = 0;

if(msecs < 0 || !f || !name) {
if(!f || !name) {
log("%s: invalid parameters\n", __func__);
return th;
}
Expand Down
1 change: 1 addition & 0 deletions src/unum/wireless/iwinfo_platform/radios_platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ int wt_tpl_fill_radio_info(WT_JSON_TPL_RADIO_STATE_t *rinfo)
extras_obj[0].val.s = NULL;
} else {
strncpy(mode, hw_mode, sizeof(mode));
mode[sizeof(mode)-1] = '\0';
extras_obj[0].val.s = mode;
}

Expand Down
2 changes: 1 addition & 1 deletion src/unum/wireless/wireless_nl80211.c
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ void wt_get_ies(unsigned char *ie, int ielen,

while (ielen >= 2 && ielen >= ie[1]) {
// A value of 0 ie[0] (type) is SSID
if (ie[0] == 0 && ie[1] >= 0 && ie[1] <= 32) {
if (ie[0] == 0 && ie[1] <= 32) {
len = ie[1];
data = ie + 2;
if (len > 64) {
Expand Down

0 comments on commit 076a537

Please sign in to comment.