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
0639be65
Commit
0639be65
authored
May 07, 2011
by
Ezio Melotti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#10169: Fix argument parsing in socket.sendto() to avoid error masking.
parent
cec46495
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
5 deletions
+56
-5
Lib/test/test_socket.py
Lib/test/test_socket.py
+39
-0
Misc/NEWS
Misc/NEWS
+2
-0
Modules/socketmodule.c
Modules/socketmodule.c
+15
-5
No files found.
Lib/test/test_socket.py
View file @
0639be65
...
...
@@ -274,6 +274,45 @@ class GeneralModuleTests(unittest.TestCase):
self
.
assertRaises
(
socket
.
error
,
raise_gaierror
,
"Error raising socket exception."
)
def
testSendtoErrors
(
self
):
# Testing that sendto doens't masks failures. See #10169.
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_DGRAM
)
self
.
addCleanup
(
s
.
close
)
s
.
bind
((
''
,
0
))
sockname
=
s
.
getsockname
()
# 2 args
with
self
.
assertRaises
(
UnicodeEncodeError
):
s
.
sendto
(
u'
\
u2620
'
,
sockname
)
with
self
.
assertRaises
(
TypeError
)
as
cm
:
s
.
sendto
(
5j
,
sockname
)
self
.
assertIn
(
'not complex'
,
str
(
cm
.
exception
))
with
self
.
assertRaises
(
TypeError
)
as
cm
:
s
.
sendto
(
'foo'
,
None
)
self
.
assertIn
(
'not NoneType'
,
str
(
cm
.
exception
))
# 3 args
with
self
.
assertRaises
(
UnicodeEncodeError
):
s
.
sendto
(
u'
\
u2620
'
,
0
,
sockname
)
with
self
.
assertRaises
(
TypeError
)
as
cm
:
s
.
sendto
(
5j
,
0
,
sockname
)
self
.
assertIn
(
'not complex'
,
str
(
cm
.
exception
))
with
self
.
assertRaises
(
TypeError
)
as
cm
:
s
.
sendto
(
'foo'
,
0
,
None
)
self
.
assertIn
(
'not NoneType'
,
str
(
cm
.
exception
))
with
self
.
assertRaises
(
TypeError
)
as
cm
:
s
.
sendto
(
'foo'
,
'bar'
,
sockname
)
self
.
assertIn
(
'an integer is required'
,
str
(
cm
.
exception
))
with
self
.
assertRaises
(
TypeError
)
as
cm
:
s
.
sendto
(
'foo'
,
None
,
None
)
self
.
assertIn
(
'an integer is required'
,
str
(
cm
.
exception
))
# wrong number of args
with
self
.
assertRaises
(
TypeError
)
as
cm
:
s
.
sendto
(
'foo'
)
self
.
assertIn
(
'(1 given)'
,
str
(
cm
.
exception
))
with
self
.
assertRaises
(
TypeError
)
as
cm
:
s
.
sendto
(
'foo'
,
0
,
sockname
,
4
)
self
.
assertIn
(
'(4 given)'
,
str
(
cm
.
exception
))
def
testCrucialConstants
(
self
):
# Testing for mission critical constants
socket
.
AF_INET
...
...
Misc/NEWS
View file @
0639be65
...
...
@@ -358,6 +358,8 @@ Library
Extension
Modules
-----------------
-
Issue
#
10169
:
Fix
argument
parsing
in
socket
.
sendto
()
to
avoid
error
masking
.
-
Issue
#
12017
:
Fix
segfault
in
json
.
loads
()
while
decoding
highly
-
nested
objects
using
the
C
accelerations
.
...
...
Modules/socketmodule.c
View file @
0639be65
...
...
@@ -2826,14 +2826,24 @@ sock_sendto(PySocketSockObject *s, PyObject *args)
Py_ssize_t
len
;
sock_addr_t
addrbuf
;
int
addrlen
,
n
=
-
1
,
flags
,
timeout
;
int
arglen
;
flags
=
0
;
if
(
!
PyArg_ParseTuple
(
args
,
"s*O:sendto"
,
&
pbuf
,
&
addro
))
{
PyErr_Clear
();
if
(
!
PyArg_ParseTuple
(
args
,
"s*iO:sendto"
,
&
pbuf
,
&
flags
,
&
addro
))
return
NULL
;
arglen
=
PyTuple_Size
(
args
);
switch
(
arglen
)
{
case
2
:
PyArg_ParseTuple
(
args
,
"s*O:sendto"
,
&
pbuf
,
&
addro
);
break
;
case
3
:
PyArg_ParseTuple
(
args
,
"s*iO:sendto"
,
&
pbuf
,
&
flags
,
&
addro
);
break
;
default:
PyErr_Format
(
PyExc_TypeError
,
"sendto() takes 2 or 3"
" arguments (%d given)"
,
arglen
);
}
if
(
PyErr_Occurred
())
return
NULL
;
buf
=
pbuf
.
buf
;
len
=
pbuf
.
len
;
...
...
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