diff options
author | David S. Miller <davem@davemloft.net> | 2012-04-01 20:45:25 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2012-04-02 04:33:43 -0400 |
commit | be51da0f3e346eb520c4ffdaecb8ba6fb4337a76 (patch) | |
tree | f24394d7d8703e03c2b893eb6a60efe6bda5eaad /net/ieee802154 | |
parent | d317e4f68f5445e536dbd45381e7c900a33413db (diff) |
ieee802154: Stop using NLA_PUT*().
These macros contain a hidden goto, and are thus extremely error
prone and make code hard to audit.
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ieee802154')
-rw-r--r-- | net/ieee802154/nl-mac.c | 146 | ||||
-rw-r--r-- | net/ieee802154/nl-phy.c | 29 |
2 files changed, 85 insertions, 90 deletions
diff --git a/net/ieee802154/nl-mac.c b/net/ieee802154/nl-mac.c index adaf46214905..ca92587720f4 100644 --- a/net/ieee802154/nl-mac.c +++ b/net/ieee802154/nl-mac.c | |||
@@ -63,15 +63,14 @@ int ieee802154_nl_assoc_indic(struct net_device *dev, | |||
63 | if (!msg) | 63 | if (!msg) |
64 | return -ENOBUFS; | 64 | return -ENOBUFS; |
65 | 65 | ||
66 | NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name); | 66 | if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) || |
67 | NLA_PUT_U32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex); | 67 | nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) || |
68 | NLA_PUT(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN, | 68 | nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN, |
69 | dev->dev_addr); | 69 | dev->dev_addr) || |
70 | 70 | nla_put(msg, IEEE802154_ATTR_SRC_HW_ADDR, IEEE802154_ADDR_LEN, | |
71 | NLA_PUT(msg, IEEE802154_ATTR_SRC_HW_ADDR, IEEE802154_ADDR_LEN, | 71 | addr->hwaddr) || |
72 | addr->hwaddr); | 72 | nla_put_u8(msg, IEEE802154_ATTR_CAPABILITY, cap)) |
73 | 73 | goto nla_put_failure; | |
74 | NLA_PUT_U8(msg, IEEE802154_ATTR_CAPABILITY, cap); | ||
75 | 74 | ||
76 | return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id); | 75 | return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id); |
77 | 76 | ||
@@ -92,14 +91,13 @@ int ieee802154_nl_assoc_confirm(struct net_device *dev, u16 short_addr, | |||
92 | if (!msg) | 91 | if (!msg) |
93 | return -ENOBUFS; | 92 | return -ENOBUFS; |
94 | 93 | ||
95 | NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name); | 94 | if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) || |
96 | NLA_PUT_U32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex); | 95 | nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) || |
97 | NLA_PUT(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN, | 96 | nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN, |
98 | dev->dev_addr); | 97 | dev->dev_addr) || |
99 | 98 | nla_put_u16(msg, IEEE802154_ATTR_SHORT_ADDR, short_addr) || | |
100 | NLA_PUT_U16(msg, IEEE802154_ATTR_SHORT_ADDR, short_addr); | 99 | nla_put_u8(msg, IEEE802154_ATTR_STATUS, status)) |
101 | NLA_PUT_U8(msg, IEEE802154_ATTR_STATUS, status); | 100 | goto nla_put_failure; |
102 | |||
103 | return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id); | 101 | return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id); |
104 | 102 | ||
105 | nla_put_failure: | 103 | nla_put_failure: |
@@ -119,20 +117,22 @@ int ieee802154_nl_disassoc_indic(struct net_device *dev, | |||
119 | if (!msg) | 117 | if (!msg) |
120 | return -ENOBUFS; | 118 | return -ENOBUFS; |
121 | 119 | ||
122 | NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name); | 120 | if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) || |
123 | NLA_PUT_U32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex); | 121 | nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) || |
124 | NLA_PUT(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN, | 122 | nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN, |
125 | dev->dev_addr); | 123 | dev->dev_addr)) |
126 | 124 | goto nla_put_failure; | |
127 | if (addr->addr_type == IEEE802154_ADDR_LONG) | 125 | if (addr->addr_type == IEEE802154_ADDR_LONG) { |
128 | NLA_PUT(msg, IEEE802154_ATTR_SRC_HW_ADDR, IEEE802154_ADDR_LEN, | 126 | if (nla_put(msg, IEEE802154_ATTR_SRC_HW_ADDR, IEEE802154_ADDR_LEN, |
129 | addr->hwaddr); | 127 | addr->hwaddr)) |
130 | else | 128 | goto nla_put_failure; |
131 | NLA_PUT_U16(msg, IEEE802154_ATTR_SRC_SHORT_ADDR, | 129 | } else { |
132 | addr->short_addr); | 130 | if (nla_put_u16(msg, IEEE802154_ATTR_SRC_SHORT_ADDR, |
133 | 131 | addr->short_addr)) | |
134 | NLA_PUT_U8(msg, IEEE802154_ATTR_REASON, reason); | 132 | goto nla_put_failure; |
135 | 133 | } | |
134 | if (nla_put_u8(msg, IEEE802154_ATTR_REASON, reason)) | ||
135 | goto nla_put_failure; | ||
136 | return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id); | 136 | return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id); |
137 | 137 | ||
138 | nla_put_failure: | 138 | nla_put_failure: |
@@ -151,13 +151,12 @@ int ieee802154_nl_disassoc_confirm(struct net_device *dev, u8 status) | |||
151 | if (!msg) | 151 | if (!msg) |
152 | return -ENOBUFS; | 152 | return -ENOBUFS; |
153 | 153 | ||
154 | NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name); | 154 | if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) || |
155 | NLA_PUT_U32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex); | 155 | nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) || |
156 | NLA_PUT(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN, | 156 | nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN, |
157 | dev->dev_addr); | 157 | dev->dev_addr) || |
158 | 158 | nla_put_u8(msg, IEEE802154_ATTR_STATUS, status)) | |
159 | NLA_PUT_U8(msg, IEEE802154_ATTR_STATUS, status); | 159 | goto nla_put_failure; |
160 | |||
161 | return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id); | 160 | return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id); |
162 | 161 | ||
163 | nla_put_failure: | 162 | nla_put_failure: |
@@ -177,13 +176,13 @@ int ieee802154_nl_beacon_indic(struct net_device *dev, | |||
177 | if (!msg) | 176 | if (!msg) |
178 | return -ENOBUFS; | 177 | return -ENOBUFS; |
179 | 178 | ||
180 | NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name); | 179 | if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) || |
181 | NLA_PUT_U32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex); | 180 | nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) || |
182 | NLA_PUT(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN, | 181 | nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN, |
183 | dev->dev_addr); | 182 | dev->dev_addr) || |
184 | NLA_PUT_U16(msg, IEEE802154_ATTR_COORD_SHORT_ADDR, coord_addr); | 183 | nla_put_u16(msg, IEEE802154_ATTR_COORD_SHORT_ADDR, coord_addr) || |
185 | NLA_PUT_U16(msg, IEEE802154_ATTR_COORD_PAN_ID, panid); | 184 | nla_put_u16(msg, IEEE802154_ATTR_COORD_PAN_ID, panid)) |
186 | 185 | goto nla_put_failure; | |
187 | return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id); | 186 | return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id); |
188 | 187 | ||
189 | nla_put_failure: | 188 | nla_put_failure: |
@@ -204,19 +203,17 @@ int ieee802154_nl_scan_confirm(struct net_device *dev, | |||
204 | if (!msg) | 203 | if (!msg) |
205 | return -ENOBUFS; | 204 | return -ENOBUFS; |
206 | 205 | ||
207 | NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name); | 206 | if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) || |
208 | NLA_PUT_U32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex); | 207 | nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) || |
209 | NLA_PUT(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN, | 208 | nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN, |
210 | dev->dev_addr); | 209 | dev->dev_addr) || |
211 | 210 | nla_put_u8(msg, IEEE802154_ATTR_STATUS, status) || | |
212 | NLA_PUT_U8(msg, IEEE802154_ATTR_STATUS, status); | 211 | nla_put_u8(msg, IEEE802154_ATTR_SCAN_TYPE, scan_type) || |
213 | NLA_PUT_U8(msg, IEEE802154_ATTR_SCAN_TYPE, scan_type); | 212 | nla_put_u32(msg, IEEE802154_ATTR_CHANNELS, unscanned) || |
214 | NLA_PUT_U32(msg, IEEE802154_ATTR_CHANNELS, unscanned); | 213 | nla_put_u8(msg, IEEE802154_ATTR_PAGE, page) || |
215 | NLA_PUT_U8(msg, IEEE802154_ATTR_PAGE, page); | 214 | (edl && |
216 | 215 | nla_put(msg, IEEE802154_ATTR_ED_LIST, 27, edl))) | |
217 | if (edl) | 216 | goto nla_put_failure; |
218 | NLA_PUT(msg, IEEE802154_ATTR_ED_LIST, 27, edl); | ||
219 | |||
220 | return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id); | 217 | return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id); |
221 | 218 | ||
222 | nla_put_failure: | 219 | nla_put_failure: |
@@ -235,13 +232,12 @@ int ieee802154_nl_start_confirm(struct net_device *dev, u8 status) | |||
235 | if (!msg) | 232 | if (!msg) |
236 | return -ENOBUFS; | 233 | return -ENOBUFS; |
237 | 234 | ||
238 | NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name); | 235 | if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) || |
239 | NLA_PUT_U32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex); | 236 | nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) || |
240 | NLA_PUT(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN, | 237 | nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN, |
241 | dev->dev_addr); | 238 | dev->dev_addr) || |
242 | 239 | nla_put_u8(msg, IEEE802154_ATTR_STATUS, status)) | |
243 | NLA_PUT_U8(msg, IEEE802154_ATTR_STATUS, status); | 240 | goto nla_put_failure; |
244 | |||
245 | return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id); | 241 | return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id); |
246 | 242 | ||
247 | nla_put_failure: | 243 | nla_put_failure: |
@@ -266,16 +262,16 @@ static int ieee802154_nl_fill_iface(struct sk_buff *msg, u32 pid, | |||
266 | phy = ieee802154_mlme_ops(dev)->get_phy(dev); | 262 | phy = ieee802154_mlme_ops(dev)->get_phy(dev); |
267 | BUG_ON(!phy); | 263 | BUG_ON(!phy); |
268 | 264 | ||
269 | NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name); | 265 | if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) || |
270 | NLA_PUT_STRING(msg, IEEE802154_ATTR_PHY_NAME, wpan_phy_name(phy)); | 266 | nla_put_string(msg, IEEE802154_ATTR_PHY_NAME, wpan_phy_name(phy)) || |
271 | NLA_PUT_U32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex); | 267 | nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) || |
272 | 268 | nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN, | |
273 | NLA_PUT(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN, | 269 | dev->dev_addr) || |
274 | dev->dev_addr); | 270 | nla_put_u16(msg, IEEE802154_ATTR_SHORT_ADDR, |
275 | NLA_PUT_U16(msg, IEEE802154_ATTR_SHORT_ADDR, | 271 | ieee802154_mlme_ops(dev)->get_short_addr(dev)) || |
276 | ieee802154_mlme_ops(dev)->get_short_addr(dev)); | 272 | nla_put_u16(msg, IEEE802154_ATTR_PAN_ID, |
277 | NLA_PUT_U16(msg, IEEE802154_ATTR_PAN_ID, | 273 | ieee802154_mlme_ops(dev)->get_pan_id(dev))) |
278 | ieee802154_mlme_ops(dev)->get_pan_id(dev)); | 274 | goto nla_put_failure; |
279 | wpan_phy_put(phy); | 275 | wpan_phy_put(phy); |
280 | return genlmsg_end(msg, hdr); | 276 | return genlmsg_end(msg, hdr); |
281 | 277 | ||
diff --git a/net/ieee802154/nl-phy.c b/net/ieee802154/nl-phy.c index c64a38d57aa3..3bdc4303c339 100644 --- a/net/ieee802154/nl-phy.c +++ b/net/ieee802154/nl-phy.c | |||
@@ -53,18 +53,18 @@ static int ieee802154_nl_fill_phy(struct sk_buff *msg, u32 pid, | |||
53 | goto out; | 53 | goto out; |
54 | 54 | ||
55 | mutex_lock(&phy->pib_lock); | 55 | mutex_lock(&phy->pib_lock); |
56 | NLA_PUT_STRING(msg, IEEE802154_ATTR_PHY_NAME, wpan_phy_name(phy)); | 56 | if (nla_put_string(msg, IEEE802154_ATTR_PHY_NAME, wpan_phy_name(phy)) || |
57 | 57 | nla_put_u8(msg, IEEE802154_ATTR_PAGE, phy->current_page) || | |
58 | NLA_PUT_U8(msg, IEEE802154_ATTR_PAGE, phy->current_page); | 58 | nla_put_u8(msg, IEEE802154_ATTR_CHANNEL, phy->current_channel)) |
59 | NLA_PUT_U8(msg, IEEE802154_ATTR_CHANNEL, phy->current_channel); | 59 | goto nla_put_failure; |
60 | for (i = 0; i < 32; i++) { | 60 | for (i = 0; i < 32; i++) { |
61 | if (phy->channels_supported[i]) | 61 | if (phy->channels_supported[i]) |
62 | buf[pages++] = phy->channels_supported[i] | (i << 27); | 62 | buf[pages++] = phy->channels_supported[i] | (i << 27); |
63 | } | 63 | } |
64 | if (pages) | 64 | if (pages && |
65 | NLA_PUT(msg, IEEE802154_ATTR_CHANNEL_PAGE_LIST, | 65 | nla_put(msg, IEEE802154_ATTR_CHANNEL_PAGE_LIST, |
66 | pages * sizeof(uint32_t), buf); | 66 | pages * sizeof(uint32_t), buf)) |
67 | 67 | goto nla_put_failure; | |
68 | mutex_unlock(&phy->pib_lock); | 68 | mutex_unlock(&phy->pib_lock); |
69 | kfree(buf); | 69 | kfree(buf); |
70 | return genlmsg_end(msg, hdr); | 70 | return genlmsg_end(msg, hdr); |
@@ -245,9 +245,9 @@ static int ieee802154_add_iface(struct sk_buff *skb, | |||
245 | goto dev_unregister; | 245 | goto dev_unregister; |
246 | } | 246 | } |
247 | 247 | ||
248 | NLA_PUT_STRING(msg, IEEE802154_ATTR_PHY_NAME, wpan_phy_name(phy)); | 248 | if (nla_put_string(msg, IEEE802154_ATTR_PHY_NAME, wpan_phy_name(phy)) || |
249 | NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name); | 249 | nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name)) |
250 | 250 | goto nla_put_failure; | |
251 | dev_put(dev); | 251 | dev_put(dev); |
252 | 252 | ||
253 | wpan_phy_put(phy); | 253 | wpan_phy_put(phy); |
@@ -333,10 +333,9 @@ static int ieee802154_del_iface(struct sk_buff *skb, | |||
333 | 333 | ||
334 | rtnl_unlock(); | 334 | rtnl_unlock(); |
335 | 335 | ||
336 | 336 | if (nla_put_string(msg, IEEE802154_ATTR_PHY_NAME, wpan_phy_name(phy)) || | |
337 | NLA_PUT_STRING(msg, IEEE802154_ATTR_PHY_NAME, wpan_phy_name(phy)); | 337 | nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, name)) |
338 | NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, name); | 338 | goto nla_put_failure; |
339 | |||
340 | wpan_phy_put(phy); | 339 | wpan_phy_put(phy); |
341 | 340 | ||
342 | return ieee802154_nl_reply(msg, info); | 341 | return ieee802154_nl_reply(msg, info); |