From 62facba19ad645df7fb425ce170bdbda208b303c Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 7 Nov 2018 17:21:41 +0900 Subject: network: ignore multiple assignment of netdev kind Fixes oss-fuzz#11279 and oss-fuzz#11280. --- src/network/netdev/netdev.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/network/netdev/netdev.c b/src/network/netdev/netdev.c index 9ec16579e4..f9a2246d08 100644 --- a/src/network/netdev/netdev.c +++ b/src/network/netdev/netdev.c @@ -97,7 +97,41 @@ static const char* const netdev_kind_table[_NETDEV_KIND_MAX] = { }; DEFINE_STRING_TABLE_LOOKUP(netdev_kind, NetDevKind); -DEFINE_CONFIG_PARSE_ENUM(config_parse_netdev_kind, netdev_kind, NetDevKind, "Failed to parse netdev kind"); + +int config_parse_netdev_kind( + const char *unit, + const char *filename, + unsigned line, + const char *section, + unsigned section_line, + const char *lvalue, + int ltype, + const char *rvalue, + void *data, + void *userdata) { + + NetDevKind k, *kind = data; + + assert(rvalue); + assert(data); + + k = netdev_kind_from_string(rvalue); + if (k < 0) { + log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse netdev kind, ignoring assignment: %s", rvalue); + return 0; + } + + if (*kind != _NETDEV_KIND_INVALID && *kind != k) { + log_syntax(unit, LOG_ERR, filename, line, 0, + "Specified netdev kind is different from the previous value '%s', ignoring assignment: %s", + netdev_kind_to_string(*kind), rvalue); + return 0; + } + + *kind = k; + + return 0; +} static void netdev_callbacks_clear(NetDev *netdev) { netdev_join_callback *callback; -- cgit v1.2.3