]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
lib/ll_map: Choose size of new cache items at run-time
authorPhil Sutter <phil@nwl.cc>
Thu, 24 Aug 2017 09:51:50 +0000 (11:51 +0200)
committerStephen Hemminger <stephen@networkplumber.org>
Thu, 24 Aug 2017 21:53:14 +0000 (14:53 -0700)
Instead of having a fixed buffer of 16 bytes for the interface name,
tailor size of new ll_cache entry using the interface name's actual
length. This also makes sure the following call to strcpy() is safe.

Signed-off-by: Phil Sutter <phil@nwl.cc>
lib/ll_map.c

index 4e4556c9ac80ba64a0892a49b6cc19d1f4df4c2f..70684b02042b6b50225104980a07ad9f3031bed2 100644 (file)
@@ -30,7 +30,7 @@ struct ll_cache {
        unsigned        flags;
        unsigned        index;
        unsigned short  type;
-       char            name[IFNAMSIZ];
+       char            name[];
 };
 
 #define IDXMAP_SIZE    1024
@@ -120,7 +120,7 @@ int ll_remember_index(const struct sockaddr_nl *who,
                return 0;
        }
 
-       im = malloc(sizeof(*im));
+       im = malloc(sizeof(*im) + strlen(ifname) + 1);
        if (im == NULL)
                return 0;
        im->index = ifi->ifi_index;