diff -r e6358103fe4f Modules/socketmodule.c --- a/Modules/socketmodule.c Wed Jan 08 20:44:37 2014 -0800 +++ b/Modules/socketmodule.c Sun Jan 12 13:21:19 2014 -0800 @@ -2877,6 +2877,14 @@ recvlen = buflen; } + /* Check if the buffer is large enough */ + if (buflen < recvlen) { + PyBuffer_Release(&pbuf); + PyErr_SetString(PyExc_ValueError, + "buffer too small for requested bytes"); + return NULL; + } + readlen = sock_recvfrom_guts(s, buf, recvlen, flags, &addr); if (readlen < 0) { PyBuffer_Release(&pbuf);