comparison net/stun.lua @ 14175:721823e085ec 13.0

net.stun: Fix parsing of STUN packets with 0-length attributes Not sure where the '20' came from. RFC 8489 defines attributes as simple TLVs, with the type+length header being always 16 bits (4 bytes). The branch for non-zero lengths already uses the correct header size.
author Matthew Wild <mwild1@gmail.com>
date Mon, 25 May 2026 13:29:28 +0100
parents ba409c67353b
children
comparison
equal deleted inserted replaced
14174:604bed81808e 14175:721823e085ec
183 local attr_hdr = bytes:sub(pos, pos+3); 183 local attr_hdr = bytes:sub(pos, pos+3);
184 assert(#attr_hdr == 4, "packet truncated in attribute header"); 184 assert(#attr_hdr == 4, "packet truncated in attribute header");
185 local attr_type, attr_len = struct.unpack(">I2I2", attr_hdr); --luacheck: ignore 211/attr_type 185 local attr_type, attr_len = struct.unpack(">I2I2", attr_hdr); --luacheck: ignore 211/attr_type
186 if attr_len == 0 then 186 if attr_len == 0 then
187 table.insert(self.attributes, attr_hdr); 187 table.insert(self.attributes, attr_hdr);
188 pos = pos + 20; 188 pos = pos + 4;
189 else 189 else
190 local data = bytes:sub(pos + 4, pos + 3 + attr_len); 190 local data = bytes:sub(pos + 4, pos + 3 + attr_len);
191 assert(#data == attr_len, "packet truncated in attribute value"); 191 assert(#data == attr_len, "packet truncated in attribute value");
192 table.insert(self.attributes, attr_hdr..data); 192 table.insert(self.attributes, attr_hdr..data);
193 local n_padding = (4 - attr_len)%4; 193 local n_padding = (4 - attr_len)%4;