From 4941ccbc7b096e8898226d715a698023202b0a09 Mon Sep 17 00:00:00 2001 From: hyunuktak Date: Fri, 1 Feb 2019 10:34:11 +0900 Subject: [PATCH] Fix some coverity issues 1020742 : Unchecked return value 1037124 : Logically dead code Change-Id: I60af7ca69b055884bd41047435b2bfff8213f3a7 Signed-off-by: hyunuktak --- plugin/pcap/stc-plugin-pcap.c | 2 -- src/helper/helper-nfacct-rule.c | 36 ++++++++++++++++++++++++++++-------- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/plugin/pcap/stc-plugin-pcap.c b/plugin/pcap/stc-plugin-pcap.c index 6c53ef3..17fe73e 100755 --- a/plugin/pcap/stc-plugin-pcap.c +++ b/plugin/pcap/stc-plugin-pcap.c @@ -541,8 +541,6 @@ static void __pcap_dns_data_info(const u_char **packet, dns_t *dns_h, uint32_t * break; case DNS_QTYPE_CNAME: __pcap_dns_name_info((uint8_t *)dns_h, &data[10], cname); - if (data == NULL) - return; if (STC_PCAP_LOG) STC_LOGD("Name[%s] Type[%u:%s] Class[0x%04x:%s] " "TTL[%u] Data length[%u] CName[%s]", diff --git a/src/helper/helper-nfacct-rule.c b/src/helper/helper-nfacct-rule.c index 24376f3..070052b 100755 --- a/src/helper/helper-nfacct-rule.c +++ b/src/helper/helper-nfacct-rule.c @@ -511,14 +511,33 @@ static stc_error_e exec_iptables_cmd(nfacct_rule_s *rule) iptables_rule.d_iprange_type = rule->dst_iprange_type; /* specify source and destination ip address if any */ - if (rule->src_ip1) - inet_aton(rule->src_ip1, &iptables_rule.s_ip1); - if (rule->src_ip2) - inet_aton(rule->src_ip2, &iptables_rule.s_ip2); - if (rule->dst_ip1) - inet_aton(rule->dst_ip1, &iptables_rule.d_ip1); - if (rule->dst_ip2) - inet_aton(rule->dst_ip2, &iptables_rule.d_ip2); + if (rule->src_ip1) { + if (!inet_aton(rule->src_ip1, &iptables_rule.s_ip1)) { + ret = STC_ERROR_INVALID_PARAMETER; + goto free; + } + } + + if (rule->src_ip2) { + if (!inet_aton(rule->src_ip2, &iptables_rule.s_ip2)) { + ret = STC_ERROR_INVALID_PARAMETER; + goto free; + } + } + + if (rule->dst_ip1) { + if (!inet_aton(rule->dst_ip1, &iptables_rule.d_ip1)) { + ret = STC_ERROR_INVALID_PARAMETER; + goto free; + } + } + + if (rule->dst_ip2) { + if (!inet_aton(rule->dst_ip2, &iptables_rule.d_ip2)) { + ret = STC_ERROR_INVALID_PARAMETER; + goto free; + } + } if (rule->action == NFACCT_ACTION_DELETE) { /* delete interface rule */ @@ -528,6 +547,7 @@ static stc_error_e exec_iptables_cmd(nfacct_rule_s *rule) ret = iptables_add(&iptables_rule, iptype); } +free: g_free(iptables_rule.nfacct_name); g_free(iptables_rule.ifname); g_free(iptables_rule.target); -- 2.7.4