Skip to content

Commit 84e97c0

Browse files
yuwatabluca
authored andcommitted
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; }; ``` (cherry picked from commit 4194478) (cherry picked from commit 7ed7b07) (cherry picked from commit 96d8cec)
1 parent e5f0a52 commit 84e97c0

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/network/netdev/vlan.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ int config_parse_vlan_qos_maps(
145145
for (const char *p = rvalue;;) {
146146
_cleanup_free_ struct ifla_vlan_qos_mapping *m = NULL;
147147
_cleanup_free_ char *w = NULL;
148+
unsigned from, to;
148149

149150
r = extract_first_word(&p, &w, NULL, EXTRACT_CUNESCAPE|EXTRACT_UNQUOTE);
150151
if (r == -ENOMEM)
@@ -156,16 +157,21 @@ int config_parse_vlan_qos_maps(
156157
if (r == 0)
157158
return 0;
158159

159-
m = new0(struct ifla_vlan_qos_mapping, 1);
160-
if (!m)
161-
return log_oom();
162-
163-
r = parse_range(w, &m->from, &m->to);
160+
r = parse_range(w, &from, &to);
164161
if (r < 0) {
165162
log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse %s, ignoring: %s", lvalue, w);
166163
continue;
167164
}
168165

166+
m = new(struct ifla_vlan_qos_mapping, 1);
167+
if (!m)
168+
return log_oom();
169+
170+
*m = (struct ifla_vlan_qos_mapping) {
171+
.from = from,
172+
.to = to,
173+
};
174+
169175
r = set_ensure_consume(s, &vlan_qos_maps_hash_ops, TAKE_PTR(m));
170176
if (r < 0) {
171177
log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to store %s, ignoring: %s", lvalue, w);

0 commit comments

Comments
 (0)