Skip to content

Commit 3b69a48

Browse files
committed
feat(ip): Check the mac address format in link.set
Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>
1 parent a5ccf46 commit 3b69a48

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

ip.lua

+10
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ local function rtnl_send(msg)
5454
return nil, err
5555
end
5656

57+
local function is_valid_mac(mac)
58+
if type(mac) ~= 'string' then
59+
return false
60+
end
61+
62+
return not not mac:match('^%x%x:%x%x:%x%x:%x%x:%x%x:%x%x$')
63+
end
64+
5765
local link = {}
5866

5967
--[[
@@ -157,10 +165,12 @@ function link.set(dev, attrs)
157165
end
158166

159167
if attrs.address then
168+
assert(is_valid_mac(attrs.address), 'not a valid address')
160169
msg:put_attr(rtnl.IFLA_ADDRESS, hex.decode(attrs.address:gsub(':', '')))
161170
end
162171

163172
if attrs.broadcast then
173+
assert(is_valid_mac(attrs.broadcast), 'not a valid broadcast')
164174
msg:put_attr(rtnl.IFLA_BROADCAST, hex.decode(attrs.broadcast:gsub(':', '')))
165175
end
166176

0 commit comments

Comments
 (0)