Skip to content
Snippets Groups Projects
Commit d6b42fd9 authored by Roman Khabibov's avatar Roman Khabibov Committed by Vladimir Davydov
Browse files

socket: throw error when size is negative in read()/sysread()

Replace assert in socket:read() and add a check in socket:sysread()
when the size is negative.

Closes #3979
parent 9844102a
No related branches found
No related tags found
No related merge requests found
......@@ -284,6 +284,9 @@ local function socket_sysread(self, arg1, arg2)
end
local size = arg1 or buffer.READAHEAD
if size < 0 then
error('socket:sysread(): size can not be negative')
end
local buf = buffer.IBUF_SHARED
buf:reset()
......@@ -655,7 +658,10 @@ local function check_delimiter(self, limit, eols)
end
local function read(self, limit, timeout, check, ...)
assert(limit >= 0)
if limit < 0 then
error('socket:read(): limit can not be negative')
end
limit = math.min(limit, LIMIT_INFINITY)
local rbuf = self.rbuf
if rbuf == nil then
......
......@@ -517,6 +517,23 @@ sc:writable()
---
- true
...
-- gh-3979 Check for errors when argument is negative.
sc:read(-1)
---
- error: 'builtin/socket.lua: socket:read(): limit can not be negative'
...
sc:sysread(-1)
---
- error: 'builtin/socket.lua: socket:sysread(): size can not be negative'
...
sc:read(-100)
---
- error: 'builtin/socket.lua: socket:read(): limit can not be negative'
...
sc:sysread(-100)
---
- error: 'builtin/socket.lua: socket:sysread(): size can not be negative'
...
sc:send('abc')
---
- 3
......
......@@ -159,6 +159,13 @@ type(sa:read(0))
sa:read(1, .01)
sc:writable()
-- gh-3979 Check for errors when argument is negative.
sc:read(-1)
sc:sysread(-1)
sc:read(-100)
sc:sysread(-100)
sc:send('abc')
sa:read(3)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment