Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
7386268f
Commit
7386268f
authored
Jul 11, 2016
by
Martin Panter
Browse files
Options
Browse Files
Download
Plain Diff
Issue #23804: Merge SSL recv() fix from 3.5
parents
4bf9c51f
bed7f1a5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
8 deletions
+32
-8
Lib/test/test_ssl.py
Lib/test/test_ssl.py
+21
-8
Misc/NEWS
Misc/NEWS
+3
-0
Modules/_ssl.c
Modules/_ssl.c
+8
-0
No files found.
Lib/test/test_ssl.py
View file @
7386268f
...
@@ -2788,20 +2788,13 @@ if _have_threads:
...
@@ -2788,20 +2788,13 @@ if _have_threads:
# consume data
# consume data
s
.
read
()
s
.
read
()
data
=
b"data"
# read(-1, buffer) is supported, even though read(-1) is not
# read(-1, buffer) is supported, even though read(-1) is not
data
=
b"data"
s
.
send
(
data
)
s
.
send
(
data
)
buffer
=
bytearray
(
len
(
data
))
buffer
=
bytearray
(
len
(
data
))
self
.
assertEqual
(
s
.
read
(
-
1
,
buffer
),
len
(
data
))
self
.
assertEqual
(
s
.
read
(
-
1
,
buffer
),
len
(
data
))
self
.
assertEqual
(
buffer
,
data
)
self
.
assertEqual
(
buffer
,
data
)
# recv/read(0) should return no data
s
.
send
(
data
)
self
.
assertEqual
(
s
.
recv
(
0
),
b""
)
self
.
assertEqual
(
s
.
read
(
0
),
b""
)
self
.
assertEqual
(
s
.
read
(),
data
)
# Make sure sendmsg et al are disallowed to avoid
# Make sure sendmsg et al are disallowed to avoid
# inadvertent disclosure of data and/or corruption
# inadvertent disclosure of data and/or corruption
# of the encrypted data stream
# of the encrypted data stream
...
@@ -2817,6 +2810,26 @@ if _have_threads:
...
@@ -2817,6 +2810,26 @@ if _have_threads:
s
.
close
()
s
.
close
()
def
test_recv_zero
(
self
):
server
=
ThreadedEchoServer
(
CERTFILE
)
server
.
__enter__
()
self
.
addCleanup
(
server
.
__exit__
,
None
,
None
)
s
=
socket
.
create_connection
((
HOST
,
server
.
port
))
self
.
addCleanup
(
s
.
close
)
s
=
ssl
.
wrap_socket
(
s
,
suppress_ragged_eofs
=
False
)
self
.
addCleanup
(
s
.
close
)
# recv/read(0) should return no data
s
.
send
(
b"data"
)
self
.
assertEqual
(
s
.
recv
(
0
),
b""
)
self
.
assertEqual
(
s
.
read
(
0
),
b""
)
self
.
assertEqual
(
s
.
read
(),
b"data"
)
# Should not block if the other end sends no data
s
.
setblocking
(
False
)
self
.
assertEqual
(
s
.
recv
(
0
),
b""
)
self
.
assertEqual
(
s
.
recv_into
(
bytearray
()),
0
)
def
test_nonblocking_send
(
self
):
def
test_nonblocking_send
(
self
):
server
=
ThreadedEchoServer
(
CERTFILE
,
server
=
ThreadedEchoServer
(
CERTFILE
,
certreqs
=
ssl
.
CERT_NONE
,
certreqs
=
ssl
.
CERT_NONE
,
...
...
Misc/NEWS
View file @
7386268f
...
@@ -27,6 +27,9 @@ Core and Builtins
...
@@ -27,6 +27,9 @@ Core and Builtins
Library
Library
-------
-------
- Issue #23804: Fix SSL zero-length recv() calls to not block and not raise
an error about unclean EOF.
- Issue #27466: Change time format returned by http.cookie.time2netscape,
- Issue #27466: Change time format returned by http.cookie.time2netscape,
confirming the netscape cookie format and making it consistent with
confirming the netscape cookie format and making it consistent with
documentation.
documentation.
...
...
Modules/_ssl.c
View file @
7386268f
...
@@ -1913,6 +1913,10 @@ _ssl__SSLSocket_read_impl(PySSLSocket *self, int len, int group_right_1,
...
@@ -1913,6 +1913,10 @@ _ssl__SSLSocket_read_impl(PySSLSocket *self, int len, int group_right_1,
dest
=
PyBytes_FromStringAndSize
(
NULL
,
len
);
dest
=
PyBytes_FromStringAndSize
(
NULL
,
len
);
if
(
dest
==
NULL
)
if
(
dest
==
NULL
)
goto
error
;
goto
error
;
if
(
len
==
0
)
{
Py_XDECREF
(
sock
);
return
dest
;
}
mem
=
PyBytes_AS_STRING
(
dest
);
mem
=
PyBytes_AS_STRING
(
dest
);
}
}
else
{
else
{
...
@@ -1924,6 +1928,10 @@ _ssl__SSLSocket_read_impl(PySSLSocket *self, int len, int group_right_1,
...
@@ -1924,6 +1928,10 @@ _ssl__SSLSocket_read_impl(PySSLSocket *self, int len, int group_right_1,
"maximum length can't fit in a C 'int'"
);
"maximum length can't fit in a C 'int'"
);
goto
error
;
goto
error
;
}
}
if
(
len
==
0
)
{
count
=
0
;
goto
done
;
}
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment