Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
tarantool
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
core
tarantool
Commits
23295a35
Commit
23295a35
authored
10 years ago
by
Roman Tsisyk
Browse files
Options
Downloads
Patches
Plain Diff
Fix #658: socket:read() incorrectly handles size and delimiter together
parent
8d7a7a25
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/lua/bsdsocket.lua
+16
-15
16 additions, 15 deletions
src/lua/bsdsocket.lua
test/box/bsdsocket.result
+68
-0
68 additions, 0 deletions
test/box/bsdsocket.result
test/box/bsdsocket.test
+22
-0
22 additions, 0 deletions
test/box/bsdsocket.test
with
106 additions
and
15 deletions
src/lua/bsdsocket.lua
+
16
−
15
View file @
23295a35
...
...
@@ -565,29 +565,27 @@ end
local
function
readline_check
(
self
,
eols
,
limit
)
local
rbuf
=
self
.
rbuf
if
rbuf
==
nil
then
return
nil
end
if
string.len
(
rbuf
)
==
0
then
return
nil
end
local
shortest
for
i
,
eol
in
pairs
(
eols
)
do
if
string.len
(
rbuf
)
>=
string.len
(
eol
)
then
local
data
=
string.match
(
rbuf
,
"^(.-"
..
eol
..
")"
)
if
data
~=
nil
then
if
string.len
(
data
)
>
limit
then
data
=
string.sub
(
data
,
1
,
limit
)
end
if
shortest
==
nil
then
shortest
=
data
elseif
#
shortest
>
#
data
then
shortest
=
data
end
for
i
,
eol
in
ipairs
(
eols
)
do
local
data
=
string.match
(
rbuf
,
"^(.-"
..
eol
..
")"
)
if
data
~=
nil
then
if
string.len
(
data
)
>
limit
then
data
=
string.sub
(
data
,
1
,
limit
)
end
if
shortest
==
nil
then
shortest
=
data
elseif
#
shortest
>
#
data
then
shortest
=
data
end
end
end
if
shortest
==
nil
and
#
rbuf
>=
limit
then
return
string.sub
(
rbuf
,
limit
)
end
return
shortest
end
...
...
@@ -597,6 +595,9 @@ local function readline(self, limit, eol, timeout)
end
self
.
_errno
=
nil
if
limit
==
0
then
return
''
end
local
data
=
readline_check
(
self
,
eol
,
limit
)
if
data
~=
nil
then
self
.
rbuf
=
string.sub
(
self
.
rbuf
,
string.len
(
data
)
+
1
)
...
...
This diff is collapsed.
Click to expand it.
test/box/bsdsocket.result
+
68
−
0
View file @
23295a35
...
...
@@ -1120,6 +1120,74 @@ lua server:close()
---
- true
...
lua body = "a 10\nb 15\nx"
---
...
lua remaining = #body
---
...
lua server = box.socket.tcp_server("unix/", "%s", function(s) s:write(body) s:read() end)
---
...
lua client = box.socket.tcp_connect("unix/", "%s")
---
...
lua buf = client:read({ size = remaining, delimiter = "[\r\n]+"})
---
...
lua buf == "a 10\n"
---
- true
...
lua remaining = remaining - #buf
---
...
lua buf = client:read({ size = remaining, delimiter = "[\r\n]+"})
---
...
lua buf == "b 15\n"
---
- true
...
lua remaining = remaining - #buf
---
...
lua buf = client:read({ size = remaining, delimiter = "[\r\n]+"})
---
...
lua buf == "x"
---
- true
...
lua remaining = remaining - #buf
---
...
lua remaining == 0
---
- true
...
lua buf = client:read({ size = remaining, delimiter = "[\r\n]+"})
---
...
lua buf == ""
---
- true
...
lua buf = client:read({ size = remaining, delimiter = "[\r\n]+"})
---
...
lua buf == ""
---
- true
...
lua client:close()
---
- true
...
lua server:close()
---
- true
...
lua s = box.socket('AF_UNIX', 'SOCK_STREAM', 'ip')
---
...
...
...
This diff is collapsed.
Click to expand it.
test/box/bsdsocket.test
+
22
−
0
View file @
23295a35
...
...
@@ -360,6 +360,28 @@ exec admin "lua client:read(123)"
exec
admin
"lua client:close()"
exec
admin
"lua server:close()"
## gh-658: socket:read() incorrectly handles size and delimiter together
exec
admin
'lua body = "a 10\\nb 15\\nx"'
exec
admin
'lua remaining = #body'
exec
admin
'lua server = box.socket.tcp_server("unix/", "%s", function(s) s:write(body) s:read() end)'
.
format
(
path
)
exec
admin
'lua client = box.socket.tcp_connect("unix/", "%s")'
.
format
(
path
)
exec
admin
'lua buf = client:read({ size = remaining, delimiter = "[\\r\\n]+"})'
exec
admin
'lua buf == "a 10\\n"'
exec
admin
'lua remaining = remaining - #buf'
exec
admin
'lua buf = client:read({ size = remaining, delimiter = "[\\r\\n]+"})'
exec
admin
'lua buf == "b 15\\n"'
exec
admin
'lua remaining = remaining - #buf'
exec
admin
'lua buf = client:read({ size = remaining, delimiter = "[\\r\\n]+"})'
exec
admin
'lua buf == "x"'
exec
admin
'lua remaining = remaining - #buf'
exec
admin
'lua remaining == 0'
exec
admin
'lua buf = client:read({ size = remaining, delimiter = "[\\r\\n]+"})'
exec
admin
'lua buf == ""'
exec
admin
'lua buf = client:read({ size = remaining, delimiter = "[\\r\\n]+"})'
exec
admin
'lua buf == ""'
exec
admin
'lua client:close()'
exec
admin
'lua server:close()'
# Test that socket is closed on GC
exec
admin
"lua s = box.socket('AF_UNIX', 'SOCK_STREAM', 'ip')"
exec
admin
"lua s:bind('unix/', '{}')"
.
format
(
path
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment