diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2013-06-24 21:47:41 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2013-06-24 21:47:41 (GMT) |
commit | 9a644b23cc5ab83fc56ea18dceb4c3b34e653f73 (patch) | |
tree | 8ac095fa8b221b16a8641b5133cffbdb10919b38 /Modules/socketmodule.c | |
parent | 7b2513589f0456ce02ee0dda51da6baa281b3f59 (diff) | |
download | cpython-9a644b23cc5ab83fc56ea18dceb4c3b34e653f73.zip cpython-9a644b23cc5ab83fc56ea18dceb4c3b34e653f73.tar.gz cpython-9a644b23cc5ab83fc56ea18dceb4c3b34e653f73.tar.bz2 |
Issue #9566: recv(), recvfrom(), send(), sendall() and sendto() methods
of socket.socket objects now truncate the input buffer to INT_MAX bytes on
Windows to avoid an integer overflow.
(sendall() still send the whole buffer.)
Diffstat (limited to 'Modules/socketmodule.c')
-rw-r--r-- | Modules/socketmodule.c | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 8bd098f..bd0a20a 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -2552,8 +2552,15 @@ sock_recv_guts(PySocketSockObject *s, char* cbuf, Py_ssize_t len, int flags) BEGIN_SELECT_LOOP(s) Py_BEGIN_ALLOW_THREADS timeout = internal_select_ex(s, 0, interval); - if (!timeout) + if (!timeout) { +#if defined(MS_WIN64) || defined(MS_WINDOWS) + if (len > INT_MAX) + len = INT_MAX; + outlen = recv(s->sock_fd, cbuf, (int)len, flags); +#else outlen = recv(s->sock_fd, cbuf, len, flags); +#endif + } Py_END_ALLOW_THREADS if (timeout == 1) { @@ -2760,7 +2767,9 @@ sock_recvfrom_guts(PySocketSockObject *s, char* cbuf, Py_ssize_t len, int flags, timeout = internal_select_ex(s, 0, interval); if (!timeout) { #ifndef MS_WINDOWS - n = recvfrom(s->sock_fd, cbuf, len, flags, + if (len > INT_MAX) + len = INT_MAX; + n = recvfrom(s->sock_fd, cbuf, (int)len, flags, (void *) &addrbuf, &addrlen); #else n = recvfrom(s->sock_fd, cbuf, len, flags, @@ -3239,12 +3248,17 @@ sock_send(PySocketSockObject *s, PyObject *args) BEGIN_SELECT_LOOP(s) Py_BEGIN_ALLOW_THREADS timeout = internal_select_ex(s, 1, interval); - if (!timeout) + if (!timeout) { #ifdef __VMS n = sendsegmented(s->sock_fd, buf, len, flags); +#elif defined(MS_WIN64) || defined(MS_WINDOWS) + if (len > INT_MAX) + len = INT_MAX; + n = send(s->sock_fd, buf, (int)len, flags); #else n = send(s->sock_fd, buf, len, flags); #endif + } Py_END_ALLOW_THREADS if (timeout == 1) { PyBuffer_Release(&pbuf); @@ -3294,6 +3308,10 @@ sock_sendall(PySocketSockObject *s, PyObject *args) if (!timeout) { #ifdef __VMS n = sendsegmented(s->sock_fd, buf, len, flags); +#elif defined(MS_WIN64) || defined(MS_WINDOWS) + if (len > INT_MAX) + len = INT_MAX; + n = send(s->sock_fd, buf, (int)len, flags); #else n = send(s->sock_fd, buf, len, flags); #endif @@ -3388,8 +3406,17 @@ sock_sendto(PySocketSockObject *s, PyObject *args) BEGIN_SELECT_LOOP(s) Py_BEGIN_ALLOW_THREADS timeout = internal_select_ex(s, 1, interval); - if (!timeout) - n = sendto(s->sock_fd, buf, len, flags, SAS2SA(&addrbuf), addrlen); + if (!timeout) { +#if defined(MS_WIN64) || defined(MS_WINDOWS) + if (len > INT_MAX) + len = INT_MAX; + n = sendto(s->sock_fd, buf, (int)len, flags, + SAS2SA(&addrbuf), addrlen); +#else + n = sendto(s->sock_fd, buf, len, flags, + SAS2SA(&addrbuf), addrlen); +#endif + } Py_END_ALLOW_THREADS if (timeout == 1) { |