From 83ec4592760db3dc35f0843b9f1e03624a792e9e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 27 Feb 2019 14:15:29 +0100 Subject: [PATCH] networkd: fix memleak when the same NetDev is specified twice hashmap_put() returns 0 if the (key, value) pair is already present in the hashmap, and -EEXIST if the key exists, but the value is different. https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=13433 --- src/network/networkd-network.c | 13 +++++++------ test/fuzz/fuzz-network-parser/oss-fuzz-13433 | Bin 0 -> 29 bytes 2 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 test/fuzz/fuzz-network-parser/oss-fuzz-13433 diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c index b413abacff7..2d42f0d742e 100644 --- a/src/network/networkd-network.c +++ b/src/network/networkd-network.c @@ -728,13 +728,14 @@ int config_parse_stacked_netdev(const char *unit, return log_oom(); r = hashmap_put(*h, name, INT_TO_PTR(kind)); - if (r < 0) { + if (r < 0) log_syntax(unit, LOG_ERR, filename, line, r, - "Cannot add NetDev '%s' to network, ignoring assignment: %m", rvalue); - return 0; - } - - name = NULL; + "Cannot add NetDev '%s' to network, ignoring assignment: %m", name); + else if (r == 0) + log_syntax(unit, LOG_DEBUG, filename, line, r, + "NetDev '%s' specified twice, ignoring.", name); + else + name = NULL; return 0; } diff --git a/test/fuzz/fuzz-network-parser/oss-fuzz-13433 b/test/fuzz/fuzz-network-parser/oss-fuzz-13433 new file mode 100644 index 0000000000000000000000000000000000000000..1aef8b7d83bd93df5dcc191efabeee598eb8ec7a GIT binary patch literal 29 cc-o8hOD!qSFUpSP3XAY@^s_Ci$YFr90GG1~?EnA( literal 0 Hc-jL100001 -- 2.47.3