mirror of
https://github.com/python/cpython.git
synced 2025-08-18 07:41:05 +00:00
Issue #9975: socket: Fix incorrect use of flowinfo and scope_id. Patch by
Vilmos Nebehaj.
This commit is contained in:
parent
8448dfa17d
commit
3aa59e327c
4 changed files with 35 additions and 8 deletions
|
@ -706,6 +706,16 @@ class GeneralModuleTests(unittest.TestCase):
|
||||||
srv.listen(0)
|
srv.listen(0)
|
||||||
srv.close()
|
srv.close()
|
||||||
|
|
||||||
|
@unittest.skipUnless(SUPPORTS_IPV6, 'IPv6 required for this test.')
|
||||||
|
def test_flowinfo(self):
|
||||||
|
self.assertRaises(OverflowError, socket.getnameinfo,
|
||||||
|
('::1',0, 0xffffffff), 0)
|
||||||
|
s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
|
||||||
|
try:
|
||||||
|
self.assertRaises(OverflowError, s.bind, ('::1', 0, -10))
|
||||||
|
finally:
|
||||||
|
s.close()
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(thread, 'Threading required for this test.')
|
@unittest.skipUnless(thread, 'Threading required for this test.')
|
||||||
class BasicTCPTest(SocketConnectedTest):
|
class BasicTCPTest(SocketConnectedTest):
|
||||||
|
|
|
@ -590,6 +590,7 @@ John Nagle
|
||||||
Takahiro Nakayama
|
Takahiro Nakayama
|
||||||
Travers Naran
|
Travers Naran
|
||||||
Charles-François Natali
|
Charles-François Natali
|
||||||
|
Vilmos Nebehaj
|
||||||
Fredrik Nehr
|
Fredrik Nehr
|
||||||
Trent Nelson
|
Trent Nelson
|
||||||
Tony Nelson
|
Tony Nelson
|
||||||
|
|
|
@ -368,6 +368,9 @@ Library
|
||||||
Extension Modules
|
Extension Modules
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
- Issue #9975: socket: Fix incorrect use of flowinfo and scope_id. Patch by
|
||||||
|
Vilmos Nebehaj.
|
||||||
|
|
||||||
- Issue #13159: FileIO, BZ2File, and the built-in file class now use a
|
- Issue #13159: FileIO, BZ2File, and the built-in file class now use a
|
||||||
linear-time buffer growth strategy instead of a quadratic one.
|
linear-time buffer growth strategy instead of a quadratic one.
|
||||||
|
|
||||||
|
|
|
@ -1028,10 +1028,10 @@ makesockaddr(int sockfd, struct sockaddr *addr, int addrlen, int proto)
|
||||||
PyObject *ret = NULL;
|
PyObject *ret = NULL;
|
||||||
if (addrobj) {
|
if (addrobj) {
|
||||||
a = (struct sockaddr_in6 *)addr;
|
a = (struct sockaddr_in6 *)addr;
|
||||||
ret = Py_BuildValue("Oiii",
|
ret = Py_BuildValue("OiII",
|
||||||
addrobj,
|
addrobj,
|
||||||
ntohs(a->sin6_port),
|
ntohs(a->sin6_port),
|
||||||
a->sin6_flowinfo,
|
ntohl(a->sin6_flowinfo),
|
||||||
a->sin6_scope_id);
|
a->sin6_scope_id);
|
||||||
Py_DECREF(addrobj);
|
Py_DECREF(addrobj);
|
||||||
}
|
}
|
||||||
|
@ -1282,7 +1282,8 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
|
||||||
{
|
{
|
||||||
struct sockaddr_in6* addr;
|
struct sockaddr_in6* addr;
|
||||||
char *host;
|
char *host;
|
||||||
int port, flowinfo, scope_id, result;
|
int port, result;
|
||||||
|
unsigned int flowinfo, scope_id;
|
||||||
flowinfo = scope_id = 0;
|
flowinfo = scope_id = 0;
|
||||||
if (!PyTuple_Check(args)) {
|
if (!PyTuple_Check(args)) {
|
||||||
PyErr_Format(
|
PyErr_Format(
|
||||||
|
@ -1292,7 +1293,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
|
||||||
Py_TYPE(args)->tp_name);
|
Py_TYPE(args)->tp_name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (!PyArg_ParseTuple(args, "eti|ii",
|
if (!PyArg_ParseTuple(args, "eti|II",
|
||||||
"idna", &host, &port, &flowinfo,
|
"idna", &host, &port, &flowinfo,
|
||||||
&scope_id)) {
|
&scope_id)) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1309,9 +1310,15 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
|
||||||
"getsockaddrarg: port must be 0-65535.");
|
"getsockaddrarg: port must be 0-65535.");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
if (flowinfo < 0 || flowinfo > 0xfffff) {
|
||||||
|
PyErr_SetString(
|
||||||
|
PyExc_OverflowError,
|
||||||
|
"getsockaddrarg: flowinfo must be 0-1048575.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
addr->sin6_family = s->sock_family;
|
addr->sin6_family = s->sock_family;
|
||||||
addr->sin6_port = htons((short)port);
|
addr->sin6_port = htons((short)port);
|
||||||
addr->sin6_flowinfo = flowinfo;
|
addr->sin6_flowinfo = htonl(flowinfo);
|
||||||
addr->sin6_scope_id = scope_id;
|
addr->sin6_scope_id = scope_id;
|
||||||
*len_ret = sizeof *addr;
|
*len_ret = sizeof *addr;
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -4156,7 +4163,8 @@ socket_getnameinfo(PyObject *self, PyObject *args)
|
||||||
PyObject *sa = (PyObject *)NULL;
|
PyObject *sa = (PyObject *)NULL;
|
||||||
int flags;
|
int flags;
|
||||||
char *hostp;
|
char *hostp;
|
||||||
int port, flowinfo, scope_id;
|
int port;
|
||||||
|
unsigned int flowinfo, scope_id;
|
||||||
char hbuf[NI_MAXHOST], pbuf[NI_MAXSERV];
|
char hbuf[NI_MAXHOST], pbuf[NI_MAXSERV];
|
||||||
struct addrinfo hints, *res = NULL;
|
struct addrinfo hints, *res = NULL;
|
||||||
int error;
|
int error;
|
||||||
|
@ -4170,9 +4178,14 @@ socket_getnameinfo(PyObject *self, PyObject *args)
|
||||||
"getnameinfo() argument 1 must be a tuple");
|
"getnameinfo() argument 1 must be a tuple");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (!PyArg_ParseTuple(sa, "si|ii",
|
if (!PyArg_ParseTuple(sa, "si|II",
|
||||||
&hostp, &port, &flowinfo, &scope_id))
|
&hostp, &port, &flowinfo, &scope_id))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
if (flowinfo < 0 || flowinfo > 0xfffff) {
|
||||||
|
PyErr_SetString(PyExc_OverflowError,
|
||||||
|
"getsockaddrarg: flowinfo must be 0-1048575.");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
PyOS_snprintf(pbuf, sizeof(pbuf), "%d", port);
|
PyOS_snprintf(pbuf, sizeof(pbuf), "%d", port);
|
||||||
memset(&hints, 0, sizeof(hints));
|
memset(&hints, 0, sizeof(hints));
|
||||||
hints.ai_family = AF_UNSPEC;
|
hints.ai_family = AF_UNSPEC;
|
||||||
|
@ -4206,7 +4219,7 @@ socket_getnameinfo(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
struct sockaddr_in6 *sin6;
|
struct sockaddr_in6 *sin6;
|
||||||
sin6 = (struct sockaddr_in6 *)res->ai_addr;
|
sin6 = (struct sockaddr_in6 *)res->ai_addr;
|
||||||
sin6->sin6_flowinfo = flowinfo;
|
sin6->sin6_flowinfo = htonl(flowinfo);
|
||||||
sin6->sin6_scope_id = scope_id;
|
sin6->sin6_scope_id = scope_id;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue