Skip to content

Commit 7ed7b07

Browse files
yuwatakeszybz
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)
1 parent b20bc7c commit 7ed7b07

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
@@ -144,6 +144,7 @@ int config_parse_vlan_qos_maps(
144144
for (const char *p = rvalue;;) {
145145
_cleanup_free_ struct ifla_vlan_qos_mapping *m = NULL;
146146
_cleanup_free_ char *w = NULL;
147+
unsigned from, to;
147148

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

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

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

0 commit comments

Comments
 (0)