lib/ll_map: Choose size of new cache items at run-time

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>
This commit is contained in:
Phil Sutter 2017-08-24 11:51:50 +02:00 committed by Stephen Hemminger
parent 56270e5466
commit 4b9e917822
1 changed files with 2 additions and 2 deletions

View 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;