]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
src: Use snprintf() over strncpy()
authorHarsha Sharma <harshasharmaiitr@gmail.com>
Sun, 8 Oct 2017 19:23:43 +0000 (00:53 +0530)
committerFlorian Westphal <fw@strlen.de>
Sat, 3 Mar 2018 09:37:31 +0000 (10:37 +0100)
Use snprintf() over strncpy() functions as the buffer is not null
terminated in strncpy().

Signed-off-by: Harsha Sharma <harshasharmaiitr@gmail.com>
src/iface.c
src/netlink.c

index 9936388b9b0d61b603c71d0cd18366c5586270be..d0e1834ca82f59c8d3ed5e5656d0d30dadcb2a1d 100644 (file)
@@ -53,7 +53,7 @@ static int data_cb(const struct nlmsghdr *nlh, void *data)
        iface = xmalloc(sizeof(struct iface));
        iface->ifindex = ifm->ifi_index;
        mnl_attr_parse(nlh, sizeof(*ifm), data_attr_cb, tb);
-       strncpy(iface->name, mnl_attr_get_str(tb[IFLA_IFNAME]), IFNAMSIZ);
+       snprintf(iface->name, IFNAMSIZ, "%s", mnl_attr_get_str(tb[IFLA_IFNAME]));
        list_add(&iface->list, &iface_list);
 
        return MNL_CB_OK;
@@ -139,7 +139,7 @@ char *nft_if_indextoname(unsigned int ifindex, char *name)
 
        list_for_each_entry(iface, &iface_list, list) {
                if (iface->ifindex == ifindex) {
-                       strncpy(name, iface->name, IFNAMSIZ);
+                       snprintf(name, IFNAMSIZ, "%s", iface->name);
                        return name;
                }
        }
index 2ff3ce5e7a57388a02f9a99c858e2df27f215ac8..403f93ca58342e4bc1f7687373ff5842ac65fa1d 100644 (file)
@@ -388,7 +388,7 @@ static void netlink_gen_verdict(const struct expr *expr,
        switch (expr->verdict) {
        case NFT_JUMP:
        case NFT_GOTO:
-               strncpy(data->chain, expr->chain, NFT_CHAIN_MAXNAMELEN);
+               snprintf(data->chain, NFT_CHAIN_MAXNAMELEN, "%s", expr->chain);
                data->chain[NFT_CHAIN_MAXNAMELEN-1] = '\0';
                break;
        }
@@ -2648,7 +2648,7 @@ static int netlink_events_newgen_cb(const struct nlmsghdr *nlh, int type,
                case NFTA_GEN_PROC_NAME:
                        if (mnl_attr_validate(attr, MNL_TYPE_NUL_STRING) < 0)
                                break;
-                       strncpy(name, mnl_attr_get_str(attr), sizeof(name));
+                       snprintf(name, sizeof(name), "%s", mnl_attr_get_str(attr));
                        break;
                case NFTA_GEN_PROC_PID:
                        if (mnl_attr_validate(attr, MNL_TYPE_U32) < 0)