]> git.proxmox.com Git - mirror_frr.git/commitdiff
Merge pull request #2545 from pacovn/Coverity_1468413_Explicit_null_dereferenced
authorRuss White <russ@riw.us>
Tue, 26 Jun 2018 15:14:39 +0000 (11:14 -0400)
committerGitHub <noreply@github.com>
Tue, 26 Jun 2018 15:14:39 +0000 (11:14 -0400)
bgpd: null check (Coverity 1468413)

18 files changed:
bgpd/bgp_vty.c
eigrpd/eigrp_topology.c
ldpd/ldp_vty_conf.c
lib/command.c
lib/command.h
lib/libfrr.c
ospf6d/ospf6_intra.c
ospfd/ospf_api.c
ospfd/ospf_vty.c
ospfd/ospf_zebra.c
ospfd/ospfd.c
pimd/mtracebis.c
ripd/ripd.c
vtysh/vtysh.c
zebra/if_netlink.c
zebra/kernel_netlink.c
zebra/rt_netlink.c
zebra/rule_netlink.c

index 041c6953f6d5b49b88b3895669f1329dde29752b..3d1fdfd38de9fd858d07b6733b55b692cfba1c8b 100644 (file)
@@ -2009,27 +2009,19 @@ DEFUN (no_bgp_fast_external_failover,
 CPP_NOTICE("bgpd: remove deprecated '[no] bgp enforce-first-as' commands")
 #endif
 
-DEFUN_DEPRECATED (bgp_enforce_first_as,
-       bgp_enforce_first_as_cmd,
-       "bgp enforce-first-as",
-       BGP_STR
-       "Enforce the first AS for EBGP routes\n")
+DEFUN_HIDDEN (bgp_enforce_first_as,
+             bgp_enforce_first_as_cmd,
+             "[no] bgp enforce-first-as",
+             NO_STR
+             BGP_STR
+             "Enforce the first AS for EBGP routes\n")
 {
        VTY_DECLVAR_CONTEXT(bgp, bgp);
-       bgp_flag_set(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
-
-       return CMD_SUCCESS;
-}
 
-DEFUN_DEPRECATED (no_bgp_enforce_first_as,
-       no_bgp_enforce_first_as_cmd,
-       "no bgp enforce-first-as",
-       NO_STR
-       BGP_STR
-       "Enforce the first AS for EBGP routes\n")
-{
-       VTY_DECLVAR_CONTEXT(bgp, bgp);
-       bgp_flag_unset(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
+       if (strmatch(argv[0]->text, "no"))
+               bgp_flag_unset(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
+       else
+               bgp_flag_set(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
 
        return CMD_SUCCESS;
 }
@@ -12444,7 +12436,6 @@ void bgp_vty_init(void)
 
        /* "bgp enforce-first-as" commands */
        install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
-       install_element(BGP_NODE, &no_bgp_enforce_first_as_cmd);
 
        /* "bgp bestpath compare-routerid" commands */
        install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
index 4e26446ebe10419fdf4741332988142321117583..8ca0e282a8cdfb09814505934e8cd94e46fb3877 100644 (file)
@@ -448,6 +448,8 @@ void eigrp_topology_update_node_flags(struct eigrp_prefix_entry *dest)
        struct eigrp_nexthop_entry *entry;
        struct eigrp *eigrp = eigrp_lookup();
 
+       assert(eigrp);
+
        for (ALL_LIST_ELEMENTS_RO(dest->entries, node, entry)) {
                if (entry->reported_distance < dest->fdistance) {
                        // is feasible successor, can be successor
index e5832c5086db3e06dc8a2043237d60f1ba53c0e5..4ef57f574a75c21b90f09202653a543041926703 100644 (file)
@@ -89,6 +89,9 @@ struct cmd_node ldp_pseudowire_node =
 int
 ldp_get_address(const char *str, int *af, union ldpd_addr *addr)
 {
+       if (!str || !af || !addr)
+               return (-1);
+
        memset(addr, 0, sizeof(*addr));
 
        if (inet_pton(AF_INET, str, &addr->v4) == 1) {
index 4ab47e5fc25d534dcdb8c2b9d277f4182aac3439..4d88f295a3cde1f9106ecd806138246daf537c64 100644 (file)
@@ -515,13 +515,6 @@ static int config_write_host(struct vty *vty)
                                        host.enable);
                }
 
-               if (zlog_default->default_lvl != LOG_DEBUG) {
-                       vty_out(vty,
-                               "! N.B. The 'log trap' command is deprecated.\n");
-                       vty_out(vty, "log trap %s\n",
-                               zlog_priority[zlog_default->default_lvl]);
-               }
-
                if (host.logfile
                    && (zlog_default->maxlvl[ZLOG_DEST_FILE]
                        != ZLOG_DISABLED)) {
@@ -2471,6 +2464,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);
@@ -2583,36 +2579,6 @@ DEFUN (no_config_log_facility,
        return CMD_SUCCESS;
 }
 
-DEFUN_DEPRECATED(
-       config_log_trap, config_log_trap_cmd,
-       "log trap <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>",
-       "Logging control\n"
-       "(Deprecated) Set logging level and default for all destinations\n" LOG_LEVEL_DESC)
-{
-       int new_level;
-       int i;
-
-       if ((new_level = level_match(argv[2]->arg)) == ZLOG_DISABLED)
-               return CMD_ERR_NO_MATCH;
-
-       zlog_default->default_lvl = new_level;
-       for (i = 0; i < ZLOG_NUM_DESTS; i++)
-               if (zlog_default->maxlvl[i] != ZLOG_DISABLED)
-                       zlog_default->maxlvl[i] = new_level;
-       return CMD_SUCCESS;
-}
-
-DEFUN_DEPRECATED(
-       no_config_log_trap, no_config_log_trap_cmd,
-       "no log trap [emergencies|alerts|critical|errors|warnings|notifications|informational|debugging]",
-       NO_STR
-       "Logging control\n"
-       "Permit all logging information\n" LOG_LEVEL_DESC)
-{
-       zlog_default->default_lvl = LOG_DEBUG;
-       return CMD_SUCCESS;
-}
-
 DEFUN (config_log_record_priority,
        config_log_record_priority_cmd,
        "log record-priority",
@@ -2902,8 +2868,6 @@ void cmd_init(int terminal)
                install_element(CONFIG_NODE, &no_config_log_syslog_cmd);
                install_element(CONFIG_NODE, &config_log_facility_cmd);
                install_element(CONFIG_NODE, &no_config_log_facility_cmd);
-               install_element(CONFIG_NODE, &config_log_trap_cmd);
-               install_element(CONFIG_NODE, &no_config_log_trap_cmd);
                install_element(CONFIG_NODE, &config_log_record_priority_cmd);
                install_element(CONFIG_NODE,
                                &no_config_log_record_priority_cmd);
index 395c971c55535e07b0db746af7b87cddc0bd3884..2d333b098a0c39d8f74edb7a221f3a6c3f4adae6 100644 (file)
@@ -240,9 +240,6 @@ struct cmd_node {
 #define DEFUN_HIDDEN(funcname, cmdname, cmdstr, helpstr)                       \
        DEFUN_ATTR(funcname, cmdname, cmdstr, helpstr, CMD_ATTR_HIDDEN)
 
-#define DEFUN_DEPRECATED(funcname, cmdname, cmdstr, helpstr)                   \
-       DEFUN_ATTR(funcname, cmdname, cmdstr, helpstr, CMD_ATTR_DEPRECATED)
-
 /* DEFUN_NOSH for commands that vtysh should ignore */
 #define DEFUN_NOSH(funcname, cmdname, cmdstr, helpstr)                         \
        DEFUN(funcname, cmdname, cmdstr, helpstr)
index 505bea9b18fef91858c2b60de579a0449c4de6f2..9ea5e985cd424ab631362335ef33cdb7da5715c6 100644 (file)
@@ -846,7 +846,9 @@ static int frr_daemon_ctl(struct thread *t)
        switch (buf[0]) {
        case 'S': /* SIGTSTP */
                vty_stdio_suspend();
-               send(daemon_ctl_sock, "s", 1, 0);
+               if (send(daemon_ctl_sock, "s", 1, 0) < 0)
+                       zlog_err("%s send(\"s\") error (SIGTSTP propagation)",
+                                (di && di->name ? di->name : ""));
                break;
        case 'R': /* SIGTCNT [implicit] */
                vty_stdio_resume();
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 4cf38439c658e6efdefdc2de52cdd74d26574db2..f315421843ee1e9df1fd9e0e4c9042de1eaf21b7 100644 (file)
@@ -243,13 +243,14 @@ static struct ospf *ospf_new(unsigned short instance, const char *name)
                        zlog_debug(
                                "%s: Create new ospf instance with vrf_name %s vrf_id %u",
                                __PRETTY_FUNCTION__, name, new->vrf_id);
-               if (vrf)
-                       ospf_vrf_link(new, vrf);
        } else {
                new->vrf_id = VRF_DEFAULT;
                vrf = vrf_lookup_by_id(VRF_DEFAULT);
-               ospf_vrf_link(new, vrf);
        }
+
+       if (vrf)
+               ospf_vrf_link(new, vrf);
+
        ospf_zebra_vrf_register(new);
 
        new->abr_type = OSPF_ABR_DEFAULT;
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;
        }
index 66b49800ddbfd58419b2308bfebd46e727619424..0697cd8b751811ae6568d20260d214edccb9e16c 100644 (file)
@@ -2441,24 +2441,6 @@ DEFUNSH(VTYSH_ALL, no_vtysh_log_facility, no_vtysh_log_facility_cmd,
        return CMD_SUCCESS;
 }
 
-DEFUNSH_DEPRECATED(
-       VTYSH_ALL, vtysh_log_trap, vtysh_log_trap_cmd,
-       "log trap <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>",
-       "Logging control\n"
-       "(Deprecated) Set logging level and default for all destinations\n" LOG_LEVEL_DESC)
-{
-       return CMD_SUCCESS;
-}
-
-DEFUNSH_DEPRECATED(VTYSH_ALL, no_vtysh_log_trap, no_vtysh_log_trap_cmd,
-                  "no log trap [LEVEL]", NO_STR
-                  "Logging control\n"
-                  "Permit all logging information\n"
-                  "Logging level\n")
-{
-       return CMD_SUCCESS;
-}
-
 DEFUNSH(VTYSH_ALL, vtysh_log_record_priority, vtysh_log_record_priority_cmd,
        "log record-priority",
        "Logging control\n"
@@ -3766,8 +3748,6 @@ void vtysh_init_vty(void)
        install_element(CONFIG_NODE, &no_vtysh_log_monitor_cmd);
        install_element(CONFIG_NODE, &vtysh_log_syslog_cmd);
        install_element(CONFIG_NODE, &no_vtysh_log_syslog_cmd);
-       install_element(CONFIG_NODE, &vtysh_log_trap_cmd);
-       install_element(CONFIG_NODE, &no_vtysh_log_trap_cmd);
        install_element(CONFIG_NODE, &vtysh_log_facility_cmd);
        install_element(CONFIG_NODE, &no_vtysh_log_facility_cmd);
        install_element(CONFIG_NODE, &vtysh_log_record_priority_cmd);
index e6d324ab6a64d0697e44943f31c7bdd55e620bcb..5c84219418422842abf7cad504a8da98aa8408dd 100644 (file)
@@ -586,8 +586,13 @@ static int netlink_interface(struct nlmsghdr *h, ns_id_t ns_id, int startup)
                return 0;
 
        len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct ifinfomsg));
-       if (len < 0)
+       if (len < 0) {
+               zlog_err("%s: Message received from netlink is of a broken size: %d %zu",
+                        __PRETTY_FUNCTION__,
+                        h->nlmsg_len,
+                        (size_t)NLMSG_LENGTH(sizeof(struct ifinfomsg)));
                return -1;
+       }
 
        /* We are interested in some AF_BRIDGE notifications. */
        if (ifi->ifi_family == AF_BRIDGE)
@@ -893,8 +898,13 @@ int netlink_interface_addr(struct nlmsghdr *h, ns_id_t ns_id, int startup)
                return 0;
 
        len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct ifaddrmsg));
-       if (len < 0)
+       if (len < 0) {
+               zlog_err("%s: Message received from netlink is of a broken size: %d %zu",
+                        __PRETTY_FUNCTION__,
+                        h->nlmsg_len,
+                        (size_t)NLMSG_LENGTH(sizeof(struct ifaddrmsg)));
                return -1;
+       }
 
        memset(tb, 0, sizeof tb);
        netlink_parse_rtattr(tb, IFA_MAX, IFA_RTA(ifa), len);
@@ -1105,8 +1115,12 @@ int netlink_link_change(struct nlmsghdr *h, ns_id_t ns_id, int startup)
        }
 
        len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct ifinfomsg));
-       if (len < 0)
+       if (len < 0) {
+               zlog_err("%s: Message received from netlink is of a broken size %d %zu",
+                        __PRETTY_FUNCTION__, h->nlmsg_len,
+                        (size_t)NLMSG_LENGTH(sizeof(struct ifinfomsg)));
                return -1;
+       }
 
        /* We are interested in some AF_BRIDGE notifications. */
        if (ifi->ifi_family == AF_BRIDGE)
index 6d164cfdabf700e8a91c801f87f3b1e7c8c5604c..7334c8094a3001c0bf4ccde57cb0ff43842c3b14 100644 (file)
@@ -772,6 +772,7 @@ int netlink_parse_info(int (*filter)(struct nlmsghdr *, ns_id_t, int),
                        error = (*filter)(h, zns->ns_id, startup);
                        if (error < 0) {
                                zlog_err("%s filter function error", nl->name);
+                               zlog_backtrace(LOG_ERR);
                                ret = error;
                        }
                }
index a5f288f54117f155eb1d8b652c0f9dd27e4d4528..90334915491e1c9f69c51314602c78fbf4386b3d 100644 (file)
@@ -295,8 +295,12 @@ static int netlink_route_change_read_unicast(struct nlmsghdr *h, ns_id_t ns_id,
        }
 
        len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct rtmsg));
-       if (len < 0)
+       if (len < 0) {
+               zlog_err("%s: Message received from netlink is of a broken size %d %zu",
+                        __PRETTY_FUNCTION__, h->nlmsg_len,
+                        (size_t)NLMSG_LENGTH(sizeof(struct rtmsg)));
                return -1;
+       }
 
        memset(tb, 0, sizeof tb);
        netlink_parse_rtattr(tb, RTA_MAX, RTM_RTA(rtm), len);
@@ -747,8 +751,13 @@ int netlink_route_change(struct nlmsghdr *h, ns_id_t ns_id, int startup)
                return 0;
 
        len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct rtmsg));
-       if (len < 0)
+       if (len < 0) {
+               zlog_err("%s: Message received from netlink is of a broken size: %d %zu",
+                        __PRETTY_FUNCTION__,
+                        h->nlmsg_len,
+                        (size_t)NLMSG_LENGTH(sizeof(struct rtmsg)));
                return -1;
+       }
 
        if (rtm->rtm_type == RTN_MULTICAST)
                netlink_route_change_read_multicast(h, ns_id, startup);
@@ -2356,8 +2365,12 @@ int netlink_neigh_change(struct nlmsghdr *h, ns_id_t ns_id)
 
        /* Length validity. */
        len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct ndmsg));
-       if (len < 0)
+       if (len < 0) {
+               zlog_err("%s: Message received from netlink is of a broken size %d %zu",
+                        __PRETTY_FUNCTION__, h->nlmsg_len,
+                        (size_t)NLMSG_LENGTH(sizeof(struct ndmsg)));
                return -1;
+       }
 
        /* Is this a notification for the MAC FDB or IP neighbor table? */
        ndm = NLMSG_DATA(h);
index bcffdf47221e9980a4eb7d18f076322112db7d0e..c7a8517e17c73c0ea496db700a5df9db85d24960 100644 (file)
@@ -196,8 +196,12 @@ int netlink_rule_change(struct nlmsghdr *h, ns_id_t ns_id, int startup)
                return 0;
 
        len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct fib_rule_hdr));
-       if (len < 0)
+       if (len < 0) {
+               zlog_err("%s: Message received from netlink is of a broken size: %d %zu",
+                        __PRETTY_FUNCTION__, h->nlmsg_len,
+                        (size_t)NLMSG_LENGTH(sizeof(struct fib_rule_hdr)));
                return -1;
+       }
 
        frh = NLMSG_DATA(h);
        if (frh->family != AF_INET && frh->family != AF_INET6)