aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python/src/Modules
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.com>2024-06-13 19:29:50 +0300
committershadchin <shadchin@yandex-team.com>2024-06-13 19:51:47 +0300
commit9051e2318afc1bfbd88a103f7392e622aa8c9527 (patch)
tree5c63ea23ebd5e7b7b9864903a9312aa853193ca5 /contrib/tools/python/src/Modules
parent224da250178b9250c7577a167d44f94f732d3627 (diff)
downloadydb-9051e2318afc1bfbd88a103f7392e622aa8c9527.tar.gz
Update Python from 2.7.16 to 2.7.18
2a151e9cf2ebdfa59d250c1bbb800e908703a6f0
Diffstat (limited to 'contrib/tools/python/src/Modules')
-rw-r--r--contrib/tools/python/src/Modules/_csv.c2
-rw-r--r--contrib/tools/python/src/Modules/_ctypes/_ctypes.c25
-rw-r--r--contrib/tools/python/src/Modules/_ctypes/callproc.c5
-rw-r--r--contrib/tools/python/src/Modules/_ctypes/cfield.c26
-rw-r--r--contrib/tools/python/src/Modules/_hashopenssl.c16
-rw-r--r--contrib/tools/python/src/Modules/_hotshot.c5
-rw-r--r--contrib/tools/python/src/Modules/_io/bufferedio.c1
-rw-r--r--contrib/tools/python/src/Modules/_json.c4
-rw-r--r--contrib/tools/python/src/Modules/_multiprocessing/multiprocessing.c2
-rw-r--r--contrib/tools/python/src/Modules/_sqlite/row.c12
-rw-r--r--contrib/tools/python/src/Modules/_ssl.c4
-rw-r--r--contrib/tools/python/src/Modules/cPickle.c13
-rw-r--r--contrib/tools/python/src/Modules/getpath.c2
-rw-r--r--contrib/tools/python/src/Modules/itertoolsmodule.c10
-rw-r--r--contrib/tools/python/src/Modules/mathmodule.c8
-rw-r--r--contrib/tools/python/src/Modules/mmapmodule.c3
-rw-r--r--contrib/tools/python/src/Modules/parsermodule.c11
-rw-r--r--contrib/tools/python/src/Modules/signalmodule.c6
-rw-r--r--contrib/tools/python/src/Modules/socketmodule.c29
-rw-r--r--contrib/tools/python/src/Modules/zipimport.c6
20 files changed, 117 insertions, 73 deletions
diff --git a/contrib/tools/python/src/Modules/_csv.c b/contrib/tools/python/src/Modules/_csv.c
index 88e3e90658..a54e74ecc3 100644
--- a/contrib/tools/python/src/Modules/_csv.c
+++ b/contrib/tools/python/src/Modules/_csv.c
@@ -818,7 +818,7 @@ Reader_iternext(ReaderObj *self)
if (c == '\0') {
Py_DECREF(lineobj);
PyErr_Format(error_obj,
- "line contains NULL byte");
+ "line contains NUL");
goto err;
}
if (parse_process_char(self, c) < 0) {
diff --git a/contrib/tools/python/src/Modules/_ctypes/_ctypes.c b/contrib/tools/python/src/Modules/_ctypes/_ctypes.c
index 8abcd30753..bef251ef04 100644
--- a/contrib/tools/python/src/Modules/_ctypes/_ctypes.c
+++ b/contrib/tools/python/src/Modules/_ctypes/_ctypes.c
@@ -1534,9 +1534,10 @@ PyCArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
}
itemsize = itemdict->size;
- if (length * itemsize < 0) {
+ if (itemsize != 0 && length > PY_SSIZE_T_MAX / itemsize) {
PyErr_SetString(PyExc_OverflowError,
"array too large");
+ Py_DECREF(stgdict);
return NULL;
}
@@ -1559,8 +1560,10 @@ PyCArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
/* create the new instance (which is a class,
since we are a metatype!) */
result = (PyTypeObject *)PyType_Type.tp_new(type, args, kwds);
- if (result == NULL)
+ if (result == NULL) {
+ Py_DECREF(stgdict);
return NULL;
+ }
/* replace the class dict by our updated spam dict */
if (-1 == PyDict_Update((PyObject *)stgdict, result->tp_dict)) {
@@ -1574,12 +1577,16 @@ PyCArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
A permanent annoyance: char arrays are also strings!
*/
if (itemdict->getfunc == _ctypes_get_fielddesc("c")->getfunc) {
- if (-1 == add_getset(result, CharArray_getsets))
+ if (-1 == add_getset(result, CharArray_getsets)) {
+ Py_DECREF(result);
return NULL;
+ }
#ifdef CTYPES_UNICODE
} else if (itemdict->getfunc == _ctypes_get_fielddesc("u")->getfunc) {
- if (-1 == add_getset(result, WCharArray_getsets))
+ if (-1 == add_getset(result, WCharArray_getsets)) {
+ Py_DECREF(result);
return NULL;
+ }
#endif
}
@@ -2788,16 +2795,18 @@ static PyObject *
PyCData_reduce(PyObject *_self, PyObject *args)
{
CDataObject *self = (CDataObject *)_self;
+ PyObject *dict;
if (PyObject_stgdict(_self)->flags & (TYPEFLAG_ISPOINTER|TYPEFLAG_HASPOINTER)) {
PyErr_SetString(PyExc_ValueError,
"ctypes objects containing pointers cannot be pickled");
return NULL;
}
- return Py_BuildValue("O(O(NN))",
- _unpickle,
- Py_TYPE(_self),
- PyObject_GetAttrString(_self, "__dict__"),
+ dict = PyObject_GetAttrString(_self, "__dict__");
+ if (dict == NULL) {
+ return NULL;
+ }
+ return Py_BuildValue("O(O(NN))", _unpickle, Py_TYPE(_self), dict,
PyString_FromStringAndSize(self->b_ptr, self->b_size));
}
diff --git a/contrib/tools/python/src/Modules/_ctypes/callproc.c b/contrib/tools/python/src/Modules/_ctypes/callproc.c
index e7bff9cae1..661271a3a6 100644
--- a/contrib/tools/python/src/Modules/_ctypes/callproc.c
+++ b/contrib/tools/python/src/Modules/_ctypes/callproc.c
@@ -242,7 +242,9 @@ static TCHAR *FormatError(DWORD code)
{
TCHAR *lpMsgBuf;
DWORD n;
- n = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
+ n = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
code,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
@@ -1846,6 +1848,7 @@ POINTER(PyObject *self, PyObject *cls)
"s(O){}",
buf,
&PyCPointer_Type);
+ PyMem_Free(buf);
if (result == NULL)
return result;
key = PyLong_FromVoidPtr(result);
diff --git a/contrib/tools/python/src/Modules/_ctypes/cfield.c b/contrib/tools/python/src/Modules/_ctypes/cfield.c
index 8088da13c2..2dc0198cf1 100644
--- a/contrib/tools/python/src/Modules/_ctypes/cfield.c
+++ b/contrib/tools/python/src/Modules/_ctypes/cfield.c
@@ -1291,24 +1291,16 @@ U_set(void *ptr, PyObject *value, Py_ssize_t length)
static PyObject *
s_get(void *ptr, Py_ssize_t size)
{
- PyObject *result;
- size_t slen;
+ Py_ssize_t i;
+ char *p;
- result = PyString_FromString((char *)ptr);
- if (!result)
- return NULL;
- /* chop off at the first NUL character, if any.
- * On error, result will be deallocated and set to NULL.
- */
- slen = strlen(PyString_AS_STRING(result));
- size = min(size, (Py_ssize_t)slen);
- if (result->ob_refcnt == 1) {
- /* shorten the result */
- _PyString_Resize(&result, size);
- return result;
- } else
- /* cannot shorten the result */
- return PyString_FromStringAndSize(ptr, size);
+ p = (char *)ptr;
+ for (i = 0; i < size; ++i) {
+ if (*p++ == '\0')
+ break;
+ }
+
+ return PyBytes_FromStringAndSize((char *)ptr, (Py_ssize_t)i);
}
static PyObject *
diff --git a/contrib/tools/python/src/Modules/_hashopenssl.c b/contrib/tools/python/src/Modules/_hashopenssl.c
index de69f6fcd0..5df08e54b2 100644
--- a/contrib/tools/python/src/Modules/_hashopenssl.c
+++ b/contrib/tools/python/src/Modules/_hashopenssl.c
@@ -133,12 +133,6 @@ newEVPobject(PyObject *name)
if (retval == NULL)
return NULL;
- retval->ctx = EVP_MD_CTX_new();
- if (retval->ctx == NULL) {
- PyErr_NoMemory();
- return NULL;
- }
-
/* save the name for .name to return */
Py_INCREF(name);
retval->name = name;
@@ -146,6 +140,13 @@ newEVPobject(PyObject *name)
retval->lock = NULL;
#endif
+ retval->ctx = EVP_MD_CTX_new();
+ if (retval->ctx == NULL) {
+ Py_DECREF(retval);
+ PyErr_NoMemory();
+ return NULL;
+ }
+
return retval;
}
@@ -205,6 +206,7 @@ EVP_copy(EVPobject *self, PyObject *unused)
return NULL;
if (!locked_EVP_MD_CTX_copy(newobj->ctx, self)) {
+ Py_DECREF(newobj);
return _setException(PyExc_ValueError);
}
return (PyObject *)newobj;
@@ -899,7 +901,7 @@ init_hashlib(void)
{
PyObject *m, *openssl_md_meth_names;
-#ifndef OPENSSL_VERSION_1_1
+#if (OPENSSL_VERSION_NUMBER < 0x10100000L) || defined(LIBRESSL_VERSION_NUMBER)
/* Load all digest algorithms and initialize cpuid */
OPENSSL_add_all_algorithms_noconf();
ERR_load_crypto_strings();
diff --git a/contrib/tools/python/src/Modules/_hotshot.c b/contrib/tools/python/src/Modules/_hotshot.c
index 33cd38da2f..4fc5cee479 100644
--- a/contrib/tools/python/src/Modules/_hotshot.c
+++ b/contrib/tools/python/src/Modules/_hotshot.c
@@ -482,8 +482,11 @@ restart:
}
else if (!err) {
result = PyTuple_New(4);
- if (result == NULL)
+ if (result == NULL) {
+ Py_XDECREF(s1);
+ Py_XDECREF(s2);
return NULL;
+ }
PyTuple_SET_ITEM(result, 0, PyInt_FromLong(what));
PyTuple_SET_ITEM(result, 2, PyInt_FromLong(fileno));
if (s1 == NULL)
diff --git a/contrib/tools/python/src/Modules/_io/bufferedio.c b/contrib/tools/python/src/Modules/_io/bufferedio.c
index b8c98a4d0d..d68f7d85b0 100644
--- a/contrib/tools/python/src/Modules/_io/bufferedio.c
+++ b/contrib/tools/python/src/Modules/_io/bufferedio.c
@@ -1363,6 +1363,7 @@ _bufferedreader_read_all(buffered *self)
res = buffered_flush_and_rewind_unlocked(self);
if (res == NULL) {
Py_DECREF(chunks);
+ Py_XDECREF(data);
return NULL;
}
Py_CLEAR(res);
diff --git a/contrib/tools/python/src/Modules/_json.c b/contrib/tools/python/src/Modules/_json.c
index 3a88882f0c..050d37daa4 100644
--- a/contrib/tools/python/src/Modules/_json.c
+++ b/contrib/tools/python/src/Modules/_json.c
@@ -1375,8 +1375,10 @@ _match_number_str(PyScannerObject *s, PyObject *pystr, Py_ssize_t start, Py_ssiz
else {
double d = PyOS_string_to_double(PyString_AS_STRING(numstr),
NULL, NULL);
- if (d == -1.0 && PyErr_Occurred())
+ if (d == -1.0 && PyErr_Occurred()) {
+ Py_DECREF(numstr);
return NULL;
+ }
rval = PyFloat_FromDouble(d);
}
}
diff --git a/contrib/tools/python/src/Modules/_multiprocessing/multiprocessing.c b/contrib/tools/python/src/Modules/_multiprocessing/multiprocessing.c
index d192a074ba..eecace887e 100644
--- a/contrib/tools/python/src/Modules/_multiprocessing/multiprocessing.c
+++ b/contrib/tools/python/src/Modules/_multiprocessing/multiprocessing.c
@@ -167,7 +167,7 @@ multiprocessing_recvfd(PyObject *self, PyObject *args)
cmsg = CMSG_FIRSTHDR(&msg);
cmsg->cmsg_level = SOL_SOCKET;
cmsg->cmsg_type = SCM_RIGHTS;
- cmsg->cmsg_len = CMSG_LEN(sizeof(int));
+ cmsg->cmsg_len = CMSG_SPACE(sizeof(int));
msg.msg_controllen = cmsg->cmsg_len;
Py_BEGIN_ALLOW_THREADS
diff --git a/contrib/tools/python/src/Modules/_sqlite/row.c b/contrib/tools/python/src/Modules/_sqlite/row.c
index 9ebe7b7b81..c0da329c13 100644
--- a/contrib/tools/python/src/Modules/_sqlite/row.c
+++ b/contrib/tools/python/src/Modules/_sqlite/row.c
@@ -199,14 +199,16 @@ static PyObject* pysqlite_row_richcompare(pysqlite_Row *self, PyObject *_other,
Py_INCREF(Py_NotImplemented);
return Py_NotImplemented;
}
- if (PyType_IsSubtype(Py_TYPE(_other), &pysqlite_RowType)) {
+ if (PyObject_TypeCheck(_other, &pysqlite_RowType)) {
pysqlite_Row *other = (pysqlite_Row *)_other;
- PyObject *res = PyObject_RichCompare(self->description, other->description, opid);
- if ((opid == Py_EQ && res == Py_True)
- || (opid == Py_NE && res == Py_False)) {
- Py_DECREF(res);
+ int eq = PyObject_RichCompareBool(self->description, other->description, Py_EQ);
+ if (eq < 0) {
+ return NULL;
+ }
+ if (eq) {
return PyObject_RichCompare(self->data, other->data, opid);
}
+ return PyBool_FromLong(opid != Py_EQ);
}
Py_INCREF(Py_NotImplemented);
return Py_NotImplemented;
diff --git a/contrib/tools/python/src/Modules/_ssl.c b/contrib/tools/python/src/Modules/_ssl.c
index dc3c3dfcba..b5e88eba5a 100644
--- a/contrib/tools/python/src/Modules/_ssl.c
+++ b/contrib/tools/python/src/Modules/_ssl.c
@@ -1589,7 +1589,7 @@ static PyObject *PySSL_version(PySSLSocket *self)
return PyUnicode_FromString(version);
}
-#if defined(OPENSSL_NPN_NEGOTIATED) && !defined(OPENSSL_NO_NEXTPROTONEG)
+#if HAVE_NPN
static PyObject *PySSL_selected_npn_protocol(PySSLSocket *self) {
const unsigned char *out;
unsigned int outlen;
@@ -2117,7 +2117,7 @@ static PyMethodDef PySSLMethods[] = {
PySSL_peercert_doc},
{"cipher", (PyCFunction)PySSL_cipher, METH_NOARGS},
{"version", (PyCFunction)PySSL_version, METH_NOARGS},
-#ifdef OPENSSL_NPN_NEGOTIATED
+#if HAVE_NPN
{"selected_npn_protocol", (PyCFunction)PySSL_selected_npn_protocol, METH_NOARGS},
#endif
#if HAVE_ALPN
diff --git a/contrib/tools/python/src/Modules/cPickle.c b/contrib/tools/python/src/Modules/cPickle.c
index 914ebb3eeb..f7c6feccaf 100644
--- a/contrib/tools/python/src/Modules/cPickle.c
+++ b/contrib/tools/python/src/Modules/cPickle.c
@@ -586,12 +586,15 @@ readline_file(Unpicklerobject *self, char **s)
while (1) {
Py_ssize_t bigger;
char *newbuf;
- for (; i < (self->buf_size - 1); i++) {
- if (feof(self->fp) ||
- (self->buf[i] = getc(self->fp)) == '\n') {
- self->buf[i + 1] = '\0';
+ while (i < (self->buf_size - 1)) {
+ int newchar = getc(self->fp);
+ if (newchar != EOF) {
+ self->buf[i++] = newchar;
+ }
+ if (newchar == EOF || newchar == '\n') {
+ self->buf[i] = '\0';
*s = self->buf;
- return i + 1;
+ return i;
}
}
if (self->buf_size > (PY_SSIZE_T_MAX >> 1)) {
diff --git a/contrib/tools/python/src/Modules/getpath.c b/contrib/tools/python/src/Modules/getpath.c
index 83ce2da9b8..9506821e29 100644
--- a/contrib/tools/python/src/Modules/getpath.c
+++ b/contrib/tools/python/src/Modules/getpath.c
@@ -496,7 +496,7 @@ calculate_path(void)
if (tmpbuffer[0] == SEP)
/* tmpbuffer should never be longer than MAXPATHLEN,
but extra check does not hurt */
- strncpy(argv0_path, tmpbuffer, MAXPATHLEN);
+ strncpy(argv0_path, tmpbuffer, MAXPATHLEN + 1);
else {
/* Interpret relative to progpath */
reduce(argv0_path);
diff --git a/contrib/tools/python/src/Modules/itertoolsmodule.c b/contrib/tools/python/src/Modules/itertoolsmodule.c
index 47db7affb0..edd21be337 100644
--- a/contrib/tools/python/src/Modules/itertoolsmodule.c
+++ b/contrib/tools/python/src/Modules/itertoolsmodule.c
@@ -314,6 +314,7 @@ typedef struct {
PyObject_HEAD
PyObject *it;
int numread;
+ int running;
PyObject *nextlink;
PyObject *(values[LINKCELLS]);
} teedataobject;
@@ -336,6 +337,7 @@ teedataobject_new(PyObject *it)
if (tdo == NULL)
return NULL;
+ tdo->running = 0;
tdo->numread = 0;
tdo->nextlink = NULL;
Py_INCREF(it);
@@ -364,7 +366,14 @@ teedataobject_getitem(teedataobject *tdo, int i)
else {
/* this is the lead iterator, so fetch more data */
assert(i == tdo->numread);
+ if (tdo->running) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "cannot re-enter the tee iterator");
+ return NULL;
+ }
+ tdo->running = 1;
value = PyIter_Next(tdo->it);
+ tdo->running = 0;
if (value == NULL)
return NULL;
tdo->numread++;
@@ -3321,6 +3330,7 @@ count_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
lz = (countobject *)type->tp_alloc(type, 0);
if (lz == NULL) {
Py_XDECREF(long_cnt);
+ Py_DECREF(long_step);
return NULL;
}
lz->cnt = cnt;
diff --git a/contrib/tools/python/src/Modules/mathmodule.c b/contrib/tools/python/src/Modules/mathmodule.c
index 67354a7594..e2ad281e12 100644
--- a/contrib/tools/python/src/Modules/mathmodule.c
+++ b/contrib/tools/python/src/Modules/mathmodule.c
@@ -71,7 +71,7 @@ static const double pi = 3.141592653589793238462643383279502884197;
static const double sqrtpi = 1.772453850905516027298167483341145182798;
static double
-sinpi(double x)
+m_sinpi(double x)
{
double y, r;
int n;
@@ -270,7 +270,7 @@ m_tgamma(double x)
integer. */
if (absx > 200.0) {
if (x < 0.0) {
- return 0.0/sinpi(x);
+ return 0.0/m_sinpi(x);
}
else {
errno = ERANGE;
@@ -294,7 +294,7 @@ m_tgamma(double x)
}
z = z * lanczos_g / y;
if (x < 0.0) {
- r = -pi / sinpi(absx) / absx * exp(y) / lanczos_sum(absx);
+ r = -pi / m_sinpi(absx) / absx * exp(y) / lanczos_sum(absx);
r -= z * r;
if (absx < 140.0) {
r /= pow(y, absx - 0.5);
@@ -366,7 +366,7 @@ m_lgamma(double x)
(x-0.5)*(log(x+lanczos_g-0.5)-1);
}
else {
- r = log(pi) - log(fabs(sinpi(absx))) - log(absx) -
+ r = log(pi) - log(fabs(m_sinpi(absx))) - log(absx) -
(log(lanczos_sum(absx)) - lanczos_g +
(absx-0.5)*(log(absx+lanczos_g-0.5)-1));
}
diff --git a/contrib/tools/python/src/Modules/mmapmodule.c b/contrib/tools/python/src/Modules/mmapmodule.c
index 02b31ca438..57cc40c53f 100644
--- a/contrib/tools/python/src/Modules/mmapmodule.c
+++ b/contrib/tools/python/src/Modules/mmapmodule.c
@@ -1436,7 +1436,8 @@ static void
setint(PyObject *d, const char *name, long value)
{
PyObject *o = PyInt_FromLong(value);
- if (o && PyDict_SetItemString(d, name, o) == 0) {
+ if (o) {
+ PyDict_SetItemString(d, name, o);
Py_DECREF(o);
}
}
diff --git a/contrib/tools/python/src/Modules/parsermodule.c b/contrib/tools/python/src/Modules/parsermodule.c
index fcc618d5d9..759f0ff4f6 100644
--- a/contrib/tools/python/src/Modules/parsermodule.c
+++ b/contrib/tools/python/src/Modules/parsermodule.c
@@ -1055,14 +1055,15 @@ validate_numnodes(node *n, int num, const char *const name)
static int
validate_terminal(node *terminal, int type, char *string)
{
- int res = (validate_ntype(terminal, type)
- && ((string == 0) || (strcmp(string, STR(terminal)) == 0)));
-
- if (!res && !PyErr_Occurred()) {
+ if (!validate_ntype(terminal, type)) {
+ return 0;
+ }
+ if (string != NULL && strcmp(string, STR(terminal)) != 0) {
PyErr_Format(parser_error,
"Illegal terminal: expected \"%s\"", string);
+ return 0;
}
- return (res);
+ return 1;
}
diff --git a/contrib/tools/python/src/Modules/signalmodule.c b/contrib/tools/python/src/Modules/signalmodule.c
index 8628f7a800..88b4711932 100644
--- a/contrib/tools/python/src/Modules/signalmodule.c
+++ b/contrib/tools/python/src/Modules/signalmodule.c
@@ -173,8 +173,10 @@ trip_signal(int sig_num)
cleared in PyErr_CheckSignals() before .tripped. */
is_tripped = 1;
Py_AddPendingCall(checksignals_witharg, NULL);
- if (wakeup_fd != -1)
- write(wakeup_fd, "\0", 1);
+ if (wakeup_fd != -1) {
+ int rc = write(wakeup_fd, "\0", 1);
+ (void)rc;
+ }
}
static void
diff --git a/contrib/tools/python/src/Modules/socketmodule.c b/contrib/tools/python/src/Modules/socketmodule.c
index 4ab05d97b3..ea7876157d 100644
--- a/contrib/tools/python/src/Modules/socketmodule.c
+++ b/contrib/tools/python/src/Modules/socketmodule.c
@@ -625,16 +625,16 @@ set_gaierror(int error)
#ifdef __VMS
/* Function to send in segments */
-static int
-sendsegmented(int sock_fd, char *buf, int len, int flags)
+static Py_ssize_t
+sendsegmented(int sock_fd, char *buf, Py_ssize_t len, int flags)
{
int n = 0;
- int remaining = len;
+ Py_ssize_t remaining = len;
while (remaining > 0) {
unsigned int segment;
- segment = (remaining >= SEGMENT_SIZE ? SEGMENT_SIZE : remaining);
+ segment = ((size_t)remaining >= SEGMENT_SIZE ? SEGMENT_SIZE : (unsigned int) remaining);
n = send(sock_fd, buf, segment, flags);
if (n < 0) {
return n;
@@ -2797,7 +2797,8 @@ static PyObject *
sock_send(PySocketSockObject *s, PyObject *args)
{
char *buf;
- int len, n = -1, flags = 0, timeout;
+ int flags = 0, timeout;
+ Py_ssize_t len, n = -1;
Py_buffer pbuf;
if (!PyArg_ParseTuple(args, "s*|i:send", &pbuf, &flags))
@@ -2813,12 +2814,18 @@ 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_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);
@@ -2830,7 +2837,7 @@ sock_send(PySocketSockObject *s, PyObject *args)
PyBuffer_Release(&pbuf);
if (n < 0)
return s->errorhandler();
- return PyInt_FromLong((long)n);
+ return PyInt_FromSsize_t(n);
}
PyDoc_STRVAR(send_doc,
@@ -2847,7 +2854,8 @@ static PyObject *
sock_sendall(PySocketSockObject *s, PyObject *args)
{
char *buf;
- int len, n = -1, flags = 0, timeout, saved_errno;
+ int flags = 0, timeout, saved_errno;
+ Py_ssize_t len, n = -1;
Py_buffer pbuf;
if (!PyArg_ParseTuple(args, "s*|i:sendall", &pbuf, &flags))
@@ -2868,6 +2876,11 @@ sock_sendall(PySocketSockObject *s, PyObject *args)
if (!timeout) {
#ifdef __VMS
n = sendsegmented(s->sock_fd, buf, len, flags);
+#elif 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
diff --git a/contrib/tools/python/src/Modules/zipimport.c b/contrib/tools/python/src/Modules/zipimport.c
index 1691773ec1..8ec2475571 100644
--- a/contrib/tools/python/src/Modules/zipimport.c
+++ b/contrib/tools/python/src/Modules/zipimport.c
@@ -714,8 +714,8 @@ read_directory(const char *archive)
unsigned int count, i;
unsigned char buffer[46];
size_t length;
- char path[MAXPATHLEN + 5];
- char name[MAXPATHLEN + 5];
+ char name[MAXPATHLEN + 1];
+ char path[2*MAXPATHLEN + 2]; /* archive + SEP + name + '\0' */
const char *errmsg = NULL;
if (strlen(archive) > MAXPATHLEN) {
@@ -838,7 +838,7 @@ read_directory(const char *archive)
}
}
- strncpy(path + length + 1, name, MAXPATHLEN - length - 1);
+ memcpy(path + length + 1, name, name_size + 1);
t = Py_BuildValue("sHIIkHHI", path, compress, data_size,
file_size, file_offset, time, date, crc);