Mercurial > cpython-lru_cache-weakref
comparison Modules/socketmodule.c @ 41343:c2bf3d646eff 2.5
Backport 54594:
Fix SF #1688393, sock.recvfrom(-24) crashes
Also fix some method names that were copied incorrectly (trunk fixed).
| author | Neal Norwitz <nnorwitz@gmail.com> |
|---|---|
| date | Sat, 31 Mar 2007 18:56:11 +0000 |
| parents | 885a77fd5c01 |
| children | 787b969d37f0 |
comparison
equal
deleted
inserted
replaced
| 41333:58427e1e51bd | 41343:c2bf3d646eff |
|---|---|
| 2354 ssize_t readlen; | 2354 ssize_t readlen; |
| 2355 char *buf; | 2355 char *buf; |
| 2356 int buflen; | 2356 int buflen; |
| 2357 | 2357 |
| 2358 /* Get the buffer's memory */ | 2358 /* Get the buffer's memory */ |
| 2359 if (!PyArg_ParseTupleAndKeywords(args, kwds, "w#|ii:recv", kwlist, | 2359 if (!PyArg_ParseTupleAndKeywords(args, kwds, "w#|ii:recv_into", kwlist, |
| 2360 &buf, &buflen, &recvlen, &flags)) | 2360 &buf, &buflen, &recvlen, &flags)) |
| 2361 return NULL; | 2361 return NULL; |
| 2362 assert(buf != 0 && buflen > 0); | 2362 assert(buf != 0 && buflen > 0); |
| 2363 | 2363 |
| 2364 if (recvlen < 0) { | 2364 if (recvlen < 0) { |
| 2365 PyErr_SetString(PyExc_ValueError, | 2365 PyErr_SetString(PyExc_ValueError, |
| 2366 "negative buffersize in recv"); | 2366 "negative buffersize in recv_into"); |
| 2367 return NULL; | 2367 return NULL; |
| 2368 } | 2368 } |
| 2369 if (recvlen == 0) { | 2369 if (recvlen == 0) { |
| 2370 /* If nbytes was not specified, use the buffer's length */ | 2370 /* If nbytes was not specified, use the buffer's length */ |
| 2371 recvlen = buflen; | 2371 recvlen = buflen; |
| 2477 ssize_t outlen; | 2477 ssize_t outlen; |
| 2478 | 2478 |
| 2479 if (!PyArg_ParseTuple(args, "i|i:recvfrom", &recvlen, &flags)) | 2479 if (!PyArg_ParseTuple(args, "i|i:recvfrom", &recvlen, &flags)) |
| 2480 return NULL; | 2480 return NULL; |
| 2481 | 2481 |
| 2482 if (recvlen < 0) { | |
| 2483 PyErr_SetString(PyExc_ValueError, | |
| 2484 "negative buffersize in recvfrom"); | |
| 2485 return NULL; | |
| 2486 } | |
| 2487 | |
| 2482 buf = PyString_FromStringAndSize((char *) 0, recvlen); | 2488 buf = PyString_FromStringAndSize((char *) 0, recvlen); |
| 2483 if (buf == NULL) | 2489 if (buf == NULL) |
| 2484 return NULL; | 2490 return NULL; |
| 2485 | 2491 |
| 2486 outlen = sock_recvfrom_guts(s, PyString_AS_STRING(buf), | 2492 outlen = sock_recvfrom_guts(s, PyString_AS_STRING(buf), |
| 2523 char *buf; | 2529 char *buf; |
| 2524 int buflen; | 2530 int buflen; |
| 2525 | 2531 |
| 2526 PyObject *addr = NULL; | 2532 PyObject *addr = NULL; |
| 2527 | 2533 |
| 2528 if (!PyArg_ParseTupleAndKeywords(args, kwds, "w#|ii:recvfrom", kwlist, | 2534 if (!PyArg_ParseTupleAndKeywords(args, kwds, "w#|ii:recvfrom_into", |
| 2529 &buf, &buflen, &recvlen, &flags)) | 2535 kwlist, &buf, &buflen, |
| 2536 &recvlen, &flags)) | |
| 2530 return NULL; | 2537 return NULL; |
| 2531 assert(buf != 0 && buflen > 0); | 2538 assert(buf != 0 && buflen > 0); |
| 2532 | 2539 |
| 2533 if (recvlen < 0) { | 2540 if (recvlen < 0) { |
| 2534 PyErr_SetString(PyExc_ValueError, | 2541 PyErr_SetString(PyExc_ValueError, |
| 2535 "negative buffersize in recv"); | 2542 "negative buffersize in recvfrom_into"); |
| 2536 return NULL; | 2543 return NULL; |
| 2537 } | 2544 } |
| 2538 if (recvlen == 0) { | 2545 if (recvlen == 0) { |
| 2539 /* If nbytes was not specified, use the buffer's length */ | 2546 /* If nbytes was not specified, use the buffer's length */ |
| 2540 recvlen = buflen; | 2547 recvlen = buflen; |
