diff options
author | Phil Sutter <phil@nwl.cc> | 2019-12-02 23:08:07 +0100 |
---|---|---|
committer | Phil Sutter <phil@nwl.cc> | 2019-12-03 18:34:39 +0100 |
commit | 835d645f4052551c5c1829c37a07c882f2260f65 (patch) | |
tree | 106ea948c1f34238d1786605ed14b6071ecb2b6c | |
parent | 32a8c5f52355ef69bf74c28e27345b2e03d948e7 (diff) |
flowtable: Correctly check realloc() call
If realloc() fails, it returns NULL but the original pointer is
untouchted and therefore still has to be freed. Unconditionally
overwriting the old pointer is therefore a bad idea, use a temporary
variable instead.
Fixes: 7f99639dd9217 ("flowtable: device array dynamic allocation")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r-- | src/flowtable.c | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/src/flowtable.c b/src/flowtable.c index db31943..9ba3b6d 100644 --- a/src/flowtable.c +++ b/src/flowtable.c @@ -388,7 +388,7 @@ static int nftnl_flowtable_parse_hook_cb(const struct nlattr *attr, void *data) static int nftnl_flowtable_parse_devs(struct nlattr *nest, struct nftnl_flowtable *c) { - const char **dev_array; + const char **dev_array, **tmp; int len = 0, size = 8; struct nlattr *attr; @@ -401,14 +401,13 @@ static int nftnl_flowtable_parse_devs(struct nlattr *nest, goto err; dev_array[len++] = strdup(mnl_attr_get_str(attr)); if (len >= size) { - dev_array = realloc(dev_array, - size * 2 * sizeof(char *)); - if (!dev_array) + tmp = realloc(dev_array, size * 2 * sizeof(char *)); + if (!tmp) goto err; size *= 2; - memset(&dev_array[len], 0, - (size - len) * sizeof(char *)); + memset(&tmp[len], 0, (size - len) * sizeof(char *)); + dev_array = tmp; } } |