Tarantool development patches archive
 help / color / mirror / Atom feed
* [tarantool-patches] [PATCH] socket: throw error when size is negative in read()/sysread()
@ 2019-02-22 19:26 Roman Khabibov
  2019-02-25 12:24 ` Vladimir Davydov
  0 siblings, 1 reply; 2+ messages in thread
From: Roman Khabibov @ 2019-02-22 19:26 UTC (permalink / raw)
  To: tarantool-patches; +Cc: alexander.turenko

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

Closes #3979
---

Branch: https://github.com/tarantool/tarantool/tree/romanhabibov/gh-3979-sock-read
Issue: https://github.com/tarantool/tarantool/issues/3979

 src/lua/socket.lua       | 10 +++++++++-
 test/app/socket.result   | 17 +++++++++++++++++
 test/app/socket.test.lua |  7 +++++++
 3 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/src/lua/socket.lua b/src/lua/socket.lua
index 7f9b40fb1..2a3ed355b 100644
--- a/src/lua/socket.lua
+++ b/src/lua/socket.lua
@@ -287,6 +287,11 @@ local function socket_sysread(self, arg1, arg2)
 
     local buf = buffer.IBUF_SHARED
     buf:reset()
+
+    if size < 0 then
+        error('socket:sysread(): size can not be negative')
+    end
+
     local p = buf:alloc(size)
 
     local res = sysread(self, p, size)
@@ -655,7 +660,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
diff --git a/test/app/socket.result b/test/app/socket.result
index 1209ec218..4c92f157e 100644
--- a/test/app/socket.result
+++ b/test/app/socket.result
@@ -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
diff --git a/test/app/socket.test.lua b/test/app/socket.test.lua
index 9901352b1..462eacf4b 100644
--- a/test/app/socket.test.lua
+++ b/test/app/socket.test.lua
@@ -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)
 
-- 
2.17.2 (Apple Git-113)

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [tarantool-patches] [PATCH] socket: throw error when size is negative in read()/sysread()
  2019-02-22 19:26 [tarantool-patches] [PATCH] socket: throw error when size is negative in read()/sysread() Roman Khabibov
@ 2019-02-25 12:24 ` Vladimir Davydov
  0 siblings, 0 replies; 2+ messages in thread
From: Vladimir Davydov @ 2019-02-25 12:24 UTC (permalink / raw)
  To: Roman Khabibov; +Cc: tarantool-patches, alexander.turenko

On Fri, Feb 22, 2019 at 10:26:06PM +0300, Roman Khabibov wrote:
> Replace assert in socket:read() and add a check in socket:sysread()
> when the size is negative.
> 
> Closes #3979

Pushed to 2.1 and 1.10.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-02-25 12:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-22 19:26 [tarantool-patches] [PATCH] socket: throw error when size is negative in read()/sysread() Roman Khabibov
2019-02-25 12:24 ` Vladimir Davydov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox