Skip to content

Commit ac29b28

Browse files
committed
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.
1 parent fa94842 commit ac29b28

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

Modules/socketmodule.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2458,13 +2458,26 @@ sock_setsockopt(PySocketSockObject *s, PyObject *args)
24582458
if (!PyArg_ParseTuple(args, "iiy*:setsockopt",
24592459
&level, &optname, &optval))
24602460
return NULL;
2461+
#ifdef MS_WINDOWS
2462+
if (optval.len > INT_MAX) {
2463+
PyBuffer_Release(&optval);
2464+
PyErr_Format(PyExc_OverflowError,
2465+
"socket option is larger than %i bytes",
2466+
INT_MAX);
2467+
return NULL;
2468+
}
2469+
res = setsockopt(s->sock_fd, level, optname,
2470+
optval.buf, (int)optval.len);
2471+
#else
24612472
res = setsockopt(s->sock_fd, level, optname, optval.buf, optval.len);
2473+
#endif
24622474
PyBuffer_Release(&optval);
24632475
}
2464-
if (res < 0)
2476+
if (res < 0) {
24652477
return s->errorhandler();
2466-
Py_INCREF(Py_None);
2467-
return Py_None;
2478+
}
2479+
2480+
Py_RETURN_NONE;
24682481
}
24692482

24702483
PyDoc_STRVAR(setsockopt_doc,

0 commit comments

Comments
 (0)