From 12b7dff45b0e2442355008a1e53f1211bd227147 Mon Sep 17 00:00:00 2001 From: David Herrmann Date: Tue, 23 Jun 2015 10:47:44 +0200 Subject: sd-netlink: make sure the root-level type is nested In sd-netlink-message, we always guarantee that the currently selected type-system is non-NULL. Otherwise, we would be unable to parse any types in the current container level. Hence, this assertion must be true: message->container_type_system[m->n_containers] != NULL During message_new() we currently do not verify that this assertion is true. Instead, we blindly access nl_type->type_system and use it (which might be NULL for basic types and unions). Fix this, by explicitly checking that the root-level type is nested. Note that this is *not* a strict requirement of netlink, but it's a strict requirement for all message types we currently support. Furthermore, all the callers of message_new() already verify that only supported types are passed, therefore, this is a pure cosmetic check. However, it might be needed on the future, so make sure we don't trap into this once we change the type-system. --- src/libsystemd/sd-netlink/netlink-message.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/libsystemd/sd-netlink') diff --git a/src/libsystemd/sd-netlink/netlink-message.c b/src/libsystemd/sd-netlink/netlink-message.c index bfbc0e6c95..e39e4c646c 100644 --- a/src/libsystemd/sd-netlink/netlink-message.c +++ b/src/libsystemd/sd-netlink/netlink-message.c @@ -72,6 +72,9 @@ int message_new(sd_netlink *rtnl, sd_netlink_message **ret, uint16_t type) { if (r < 0) return r; + if (type_get_type(nl_type) != NETLINK_TYPE_NESTED) + return -EINVAL; + r = message_new_empty(rtnl, &m); if (r < 0) return r; @@ -85,8 +88,7 @@ int message_new(sd_netlink *rtnl, sd_netlink_message **ret, uint16_t type) { m->hdr->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK; - if (type_get_type(nl_type) == NETLINK_TYPE_NESTED) - type_get_type_system(nl_type, &m->container_type_system[0]); + type_get_type_system(nl_type, &m->container_type_system[0]); m->hdr->nlmsg_len = size; m->hdr->nlmsg_type = type; -- cgit v1.2.3-54-g00ecf