diff options
author | Kim Alvefur <zash@zash.se> | 2020-10-12 20:21:18 +0200 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2020-10-12 20:21:18 +0200 |
commit | fb63187afceb8339b6142cc0b96162eb1c9af3b8 (patch) | |
tree | e3fa96e3e085462d6056340bf2defc0b8775ee0e /net/websocket/frames.lua | |
parent | d3b3e21720094ca5d4c0c4cf659d6aee4f1b578e (diff) | |
download | prosody-fb63187afceb8339b6142cc0b96162eb1c9af3b8.tar.gz prosody-fb63187afceb8339b6142cc0b96162eb1c9af3b8.zip |
net.websocket.frames: Read buffer length correctly in Lua 5.1 (fix #1598)
COMPAT: The __len metamethod does not work with tables in Lua 5.1.
Both strings and util.dbuffer now expose their length as a :len()
method.
Diffstat (limited to 'net/websocket/frames.lua')
-rw-r--r-- | net/websocket/frames.lua | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/net/websocket/frames.lua b/net/websocket/frames.lua index a0c0d4cd..9cb5f4fe 100644 --- a/net/websocket/frames.lua +++ b/net/websocket/frames.lua @@ -76,7 +76,7 @@ if s_unpack then end local function parse_frame_header(frame) - if #frame < 2 then return; end + if frame:len() < 2 then return; end local byte1, byte2 = frame:byte(1, 2); local result = { @@ -98,7 +98,7 @@ local function parse_frame_header(frame) end local header_length = 2 + length_bytes + (result.MASK and 4 or 0); - if #frame < header_length then return; end + if frame:len() < header_length then return; end if length_bytes == 2 then result.length = read_uint16be(frame, 3); @@ -141,7 +141,7 @@ end local function parse_frame(frame) local result, pos = parse_frame_header(frame); - if result == nil or #frame < (pos + result.length) then return nil, nil, result; end + if result == nil or frame:len() < (pos + result.length) then return nil, nil, result; end result.data = parse_frame_body(frame, result, pos+1); return result, pos + result.length; end |