From: Yu Watanabe Date: Wed, 24 May 2023 02:06:35 +0000 (+0900) Subject: network/vlan: paranoia about type safety X-Git-Tag: v254-rc1~398^2~1 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=4194478af861f80a73905d1f9e570a09862f91a7;p=thirdparty%2Fsystemd.git network/vlan: paranoia about type safety No functional change, as the struct is defined as the following: ``` struct ifla_vlan_qos_mapping { __u32 from; __u32 to; }; ``` --- diff --git a/src/network/netdev/vlan.c b/src/network/netdev/vlan.c index d61e9486abc..5eb36ef6801 100644 --- a/src/network/netdev/vlan.c +++ b/src/network/netdev/vlan.c @@ -144,6 +144,7 @@ int config_parse_vlan_qos_maps( for (const char *p = rvalue;;) { _cleanup_free_ struct ifla_vlan_qos_mapping *m = NULL; _cleanup_free_ char *w = NULL; + unsigned from, to; r = extract_first_word(&p, &w, NULL, EXTRACT_CUNESCAPE|EXTRACT_UNQUOTE); if (r == -ENOMEM) @@ -155,16 +156,21 @@ int config_parse_vlan_qos_maps( if (r == 0) return 0; - m = new0(struct ifla_vlan_qos_mapping, 1); - if (!m) - return log_oom(); - - r = parse_range(w, &m->from, &m->to); + r = parse_range(w, &from, &to); if (r < 0) { log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse %s, ignoring: %s", lvalue, w); continue; } + m = new(struct ifla_vlan_qos_mapping, 1); + if (!m) + return log_oom(); + + *m = (struct ifla_vlan_qos_mapping) { + .from = from, + .to = to, + }; + r = set_ensure_consume(s, &vlan_qos_maps_hash_ops, TAKE_PTR(m)); if (r < 0) { log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to store %s, ignoring: %s", lvalue, w);