[Python-checkins] cpython (2.7): Issue #9975: socket: Fix incorrect use of flowinfo and scope_id. Patch by

charles-francois.natali python-checkins at python.org
Mon Jan 2 15:58:01 CET 2012


http://hg.python.org/cpython/rev/0c10061df711
changeset: 74232:0c10061df711
branch: 2.7
parent: 74230:b2b7104691c9
user: Charles-François Natali <neologix at free.fr>
date: Mon Jan 02 15:38:27 2012 +0100
summary:
 Issue #9975: socket: Fix incorrect use of flowinfo and scope_id. Patch by
Vilmos Nebehaj.
files:
 Lib/test/test_socket.py | 10 ++++++++++
 Misc/ACKS | 1 +
 Misc/NEWS | 3 +++
 Modules/socketmodule.c | 29 +++++++++++++++++++++--------
 4 files changed, 35 insertions(+), 8 deletions(-)
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -706,6 +706,16 @@
 srv.listen(0)
 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.')
 class BasicTCPTest(SocketConnectedTest):
diff --git a/Misc/ACKS b/Misc/ACKS
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -590,6 +590,7 @@
 Takahiro Nakayama
 Travers Naran
 Charles-François Natali
+Vilmos Nebehaj
 Fredrik Nehr
 Trent Nelson
 Tony Nelson
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -368,6 +368,9 @@
 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
 linear-time buffer growth strategy instead of a quadratic one.
 
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -1028,10 +1028,10 @@
 PyObject *ret = NULL;
 if (addrobj) {
 a = (struct sockaddr_in6 *)addr;
- ret = Py_BuildValue("Oiii",
+ ret = Py_BuildValue("OiII",
 addrobj,
 ntohs(a->sin6_port),
- a->sin6_flowinfo,
+ ntohl(a->sin6_flowinfo),
 a->sin6_scope_id);
 Py_DECREF(addrobj);
 }
@@ -1282,7 +1282,8 @@
 {
 struct sockaddr_in6* addr;
 char *host;
- int port, flowinfo, scope_id, result;
+ int port, result;
+ unsigned int flowinfo, scope_id;
 flowinfo = scope_id = 0;
 if (!PyTuple_Check(args)) {
 PyErr_Format(
@@ -1292,7 +1293,7 @@
 Py_TYPE(args)->tp_name);
 return 0;
 }
- if (!PyArg_ParseTuple(args, "eti|ii",
+ if (!PyArg_ParseTuple(args, "eti|II",
 "idna", &host, &port, &flowinfo,
 &scope_id)) {
 return 0;
@@ -1309,9 +1310,15 @@
 "getsockaddrarg: port must be 0-65535.");
 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_port = htons((short)port);
- addr->sin6_flowinfo = flowinfo;
+ addr->sin6_flowinfo = htonl(flowinfo);
 addr->sin6_scope_id = scope_id;
 *len_ret = sizeof *addr;
 return 1;
@@ -4156,7 +4163,8 @@
 PyObject *sa = (PyObject *)NULL;
 int flags;
 char *hostp;
- int port, flowinfo, scope_id;
+ int port;
+ unsigned int flowinfo, scope_id;
 char hbuf[NI_MAXHOST], pbuf[NI_MAXSERV];
 struct addrinfo hints, *res = NULL;
 int error;
@@ -4170,9 +4178,14 @@
 "getnameinfo() argument 1 must be a tuple");
 return NULL;
 }
- if (!PyArg_ParseTuple(sa, "si|ii",
+ if (!PyArg_ParseTuple(sa, "si|II",
 &hostp, &port, &flowinfo, &scope_id))
 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);
 memset(&hints, 0, sizeof(hints));
 hints.ai_family = AF_UNSPEC;
@@ -4206,7 +4219,7 @@
 {
 struct sockaddr_in6 *sin6;
 sin6 = (struct sockaddr_in6 *)res->ai_addr;
- sin6->sin6_flowinfo = flowinfo;
+ sin6->sin6_flowinfo = htonl(flowinfo);
 sin6->sin6_scope_id = scope_id;
 break;
 }
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /