summaryrefslogtreecommitdiff
path: root/src/libsystemd/sd-netlink/netlink-message.c
diff options
context:
space:
mode:
authorDavid Herrmann <dh.herrmann@gmail.com>2015-06-23 10:51:25 +0200
committerDavid Herrmann <dh.herrmann@gmail.com>2015-06-24 13:45:47 +0200
commitc658008f50fdbc617e6f7ad321c058f3a6f175f5 (patch)
treec2fb5229335daa4dadbbd0c8faf541e862418934 /src/libsystemd/sd-netlink/netlink-message.c
parentcafbc790d1affec2c9524c5ee1915485a1ac6879 (diff)
sd-netlink: don't access type->type_system[_union] directly
Make sure we never access type->type_system or type->type_system_union directly. This is an implementation detail of the type-system and we should always use the accessors. Right now, they only exist for 2-level accesses (type-system to type-system). This patch introduces the 1-level accessors (type to type-system) and makes use of it. This patch makes sure the proper assertions are in place, so we never accidentally access sub-type-systems for non-nested/union types. Note that this places hard-asserts on the accessors. This should be fine, as we expect callers to only access sub type-systems if they *know* they're dealing with nested types.
Diffstat (limited to 'src/libsystemd/sd-netlink/netlink-message.c')
-rw-r--r--src/libsystemd/sd-netlink/netlink-message.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/libsystemd/sd-netlink/netlink-message.c b/src/libsystemd/sd-netlink/netlink-message.c
index 601124cc05..887327c9ae 100644
--- a/src/libsystemd/sd-netlink/netlink-message.c
+++ b/src/libsystemd/sd-netlink/netlink-message.c
@@ -85,7 +85,8 @@ int message_new(sd_netlink *rtnl, sd_netlink_message **ret, uint16_t type) {
m->hdr->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
- m->container_type_system[0] = nl_type->type_system;
+ if (nl_type->type == NETLINK_TYPE_NESTED)
+ type_get_type_system(nl_type, &m->container_type_system[0]);
m->hdr->nlmsg_len = size;
m->hdr->nlmsg_type = type;
@@ -872,9 +873,9 @@ int sd_netlink_message_rewind(sd_netlink_message *m) {
return r;
if (type->type == NETLINK_TYPE_NESTED) {
- const NLTypeSystem *type_system = type->type_system;
+ const NLTypeSystem *type_system;
- assert(type_system);
+ type_get_type_system(type, &type_system);
m->container_type_system[0] = type_system;