]> git.proxmox.com Git - mirror_frr.git/commitdiff
Merge pull request #2548 from pacovn/Coverity_1453456_Unchecked_return_value_from_library
authorJafar Al-Gharaibeh <Jafaral@users.noreply.github.com>
Mon, 25 Jun 2018 21:30:31 +0000 (17:30 -0400)
committerGitHub <noreply@github.com>
Mon, 25 Jun 2018 21:30:31 +0000 (17:30 -0400)
lib: check return value (Coverity 1453456)

lib/command.c
ospf6d/ospf6_intra.c
ospfd/ospf_api.c
ospfd/ospf_vty.c
ospfd/ospf_zebra.c
pimd/mtracebis.c
ripd/ripd.c

index 4ab47e5fc25d534dcdb8c2b9d277f4182aac3439..d666e8c593df9372e71214ed9d5111882faa6484 100644 (file)
@@ -2471,6 +2471,9 @@ void command_setup_early_logging(const char *dest, const char *level)
        }
 
        token = strstr(dest, ":");
+       if (token == NULL)
+               return;
+
        token++;
 
        set_log_file(NULL, token, zlog_default->default_lvl);
index d99541ebaddfa8c28ae9a1423546b551921d3430..7898b109050ee506cf5706f7fc0de091b4630590 100644 (file)
@@ -1323,6 +1323,8 @@ static void ospf6_intra_prefix_update_route_origin(struct ospf6_route *oa_route)
        g_route = ospf6_route_lookup(&oa_route->prefix,
                                     ospf6->route_table);
 
+       assert(g_route);
+
        for (ospf6_route_lock(g_route); g_route &&
             ospf6_route_is_prefix(&oa_route->prefix, g_route);
             g_route = nroute) {
index 8369dde82215ad67cbe64511a14f7cda623554c3..b1175a2f68cc3f7e080fff2048a7a3945b439c49 100644 (file)
@@ -510,17 +510,18 @@ struct msg *new_msg_originate_request(uint32_t seqnum, struct in_addr ifaddr,
        struct msg_originate_request *omsg;
        unsigned int omsglen;
        char buf[OSPF_API_MAX_MSG_SIZE];
+       size_t off_data = offsetof(struct msg_originate_request, data);
+       size_t data_maxs = sizeof(buf) - off_data;
+       struct lsa_header *omsg_data = (struct lsa_header *)&buf[off_data];
 
        omsg = (struct msg_originate_request *)buf;
        omsg->ifaddr = ifaddr;
        omsg->area_id = area_id;
 
        omsglen = ntohs(data->length);
-       if (omsglen
-           > sizeof(buf) - offsetof(struct msg_originate_request, data))
-               omsglen = sizeof(buf)
-                         - offsetof(struct msg_originate_request, data);
-       memcpy(&omsg->data, data, omsglen);
+       if (omsglen > data_maxs)
+               omsglen = data_maxs;
+       memcpy(omsg_data, data, omsglen);
        omsglen += sizeof(struct msg_originate_request)
                   - sizeof(struct lsa_header);
 
@@ -630,6 +631,9 @@ struct msg *new_msg_lsa_change_notify(uint8_t msgtype, uint32_t seqnum,
        uint8_t buf[OSPF_API_MAX_MSG_SIZE];
        struct msg_lsa_change_notify *nmsg;
        unsigned int len;
+       size_t off_data = offsetof(struct msg_lsa_change_notify, data);
+       size_t data_maxs = sizeof(buf) - off_data;
+       struct lsa_header *nmsg_data = (struct lsa_header *)&buf[off_data];
 
        assert(data);
 
@@ -640,10 +644,9 @@ struct msg *new_msg_lsa_change_notify(uint8_t msgtype, uint32_t seqnum,
        memset(&nmsg->pad, 0, sizeof(nmsg->pad));
 
        len = ntohs(data->length);
-       if (len > sizeof(buf) - offsetof(struct msg_lsa_change_notify, data))
-               len = sizeof(buf)
-                     - offsetof(struct msg_lsa_change_notify, data);
-       memcpy(&nmsg->data, data, len);
+       if (len > data_maxs)
+               len = data_maxs;
+       memcpy(nmsg_data, data, len);
        len += sizeof(struct msg_lsa_change_notify) - sizeof(struct lsa_header);
 
        return msg_new(msgtype, nmsg, seqnum, len);
index 7d748419faceb8ae6fe6ee2f37d58c3b4d54a264..ddf9133ed96ff30ae1dc3c50e6af8990904a18e3 100644 (file)
@@ -8166,6 +8166,11 @@ DEFUN (ospf_redistribute_instance_source,
 
        source = proto_redistnum(AFI_IP, argv[idx_ospf_table]->text);
 
+       if (source < 0) {
+               vty_out(vty, "Unknown instance redistribution\n");
+               return CMD_WARNING_CONFIG_FAILED;
+       }
+
        instance = strtoul(argv[idx_number]->arg, NULL, 10);
 
        if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) {
index 141ece9c7a74b228c6f075dff134d233d8943742..0a7776cced054c5dac2eb563530f0e3c80c46b7f 100644 (file)
@@ -670,6 +670,16 @@ int ospf_redistribute_set(struct ospf *ospf, int type, unsigned short instance,
        struct ospf_redist *red;
 
        red = ospf_redist_lookup(ospf, type, instance);
+
+       if (red == NULL) {
+               zlog_err(
+                        "Redistribute[%s][%d]: Lookup failed  Type[%d] , Metric[%d]",
+                        ospf_redist_string(type), instance,
+                        metric_type(ospf, type, instance),
+                        metric_value(ospf, type, instance));
+               return CMD_WARNING_CONFIG_FAILED;
+       }
+
        if (ospf_is_type_redistributed(ospf, type, instance)) {
                if (mtype != red->dmetric.type) {
                        red->dmetric.type = mtype;
index c63a6eeca983fa8fbe1b31d3c9fb9060b7d921b2..a0e8fd127030152a0fbff9bd9053bda8d09c0ad9 100644 (file)
@@ -303,6 +303,9 @@ static int recv_response(int fd, int *hops, struct igmp_mtrace *mtracer)
        if (mtrace_len < (int)MTRACE_HDR_SIZE)
                return -1;
 
+       if (mtrace_len > (int)MTRACE_BUF_LEN)
+               return -1;
+
        sum = mtrace->checksum;
        mtrace->checksum = 0;
        if (sum != in_cksum(mtrace, mtrace_len)) {
index 92c27106d583be85b09f9ba645e354e5b9408026..90dc7808ebb802be538ff46dcada1e10a4185cec 100644 (file)
@@ -799,11 +799,11 @@ static int rip_auth_simple_password(struct rte *rte, struct sockaddr_in *from,
                                    struct interface *ifp)
 {
        struct rip_interface *ri;
-       char *auth_str = (char *)&rte->prefix;
+       char *auth_str = (char *)rte + offsetof(struct rte, prefix);
        int i;
 
        /* reject passwords with zeros in the middle of the string */
-       for (i = strlen(auth_str); i < 16; i++) {
+       for (i = strnlen(auth_str, 16); i < 16; i++) {
                if (auth_str[i] != '\0')
                        return 0;
        }