summaryrefslogtreecommitdiffstats
path: root/Modules/socketmodule.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2016-03-23 20:35:29 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2016-03-23 20:35:29 (GMT)
commitcc73932125c9e1d6cada036d90873821ddda091a (patch)
treeab7a9ea681e0ec542ccc066710e743a1540aeb91 /Modules/socketmodule.c
parent0069aef51a176ec90fb93f4601636e8763e07c42 (diff)
downloadcpython-cc73932125c9e1d6cada036d90873821ddda091a.zip
cpython-cc73932125c9e1d6cada036d90873821ddda091a.tar.gz
cpython-cc73932125c9e1d6cada036d90873821ddda091a.tar.bz2
socketmodule.c: error if option larger than INT_MAX
On Windows, socket.setsockopt() raises an OverflowError if the socket option is larger than INT_MAX bytes.
Diffstat (limited to 'Modules/socketmodule.c')
-rw-r--r--Modules/socketmodule.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index ba3cefd..8df735d 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -2458,13 +2458,26 @@ sock_setsockopt(PySocketSockObject *s, PyObject *args)
if (!PyArg_ParseTuple(args, "iiy*:setsockopt",
&level, &optname, &optval))
return NULL;
+#ifdef MS_WINDOWS
+ if (optval.len > INT_MAX) {
+ PyBuffer_Release(&optval);
+ PyErr_Format(PyExc_OverflowError,
+ "socket option is larger than %i bytes",
+ INT_MAX);
+ return NULL;
+ }
+ res = setsockopt(s->sock_fd, level, optname,
+ optval.buf, (int)optval.len);
+#else
res = setsockopt(s->sock_fd, level, optname, optval.buf, optval.len);
+#endif
PyBuffer_Release(&optval);
}
- if (res < 0)
+ if (res < 0) {
return s->errorhandler();
- Py_INCREF(Py_None);
- return Py_None;
+ }
+
+ Py_RETURN_NONE;
}
PyDoc_STRVAR(setsockopt_doc,