summaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Modules
diff options
context:
space:
mode:
authorarcadia-devtools <[email protected]>2022-03-25 10:46:04 +0300
committerarcadia-devtools <[email protected]>2022-03-25 10:46:04 +0300
commit4a07b03673d315e0d98c5e29cc9cbeeec1d5c94f (patch)
tree7cdc507d170dc6f879b1fde1093012f5be58fece /contrib/tools/python3/src/Modules
parent86f93d737e9db0e8bfdb6d6a291b6dbdab9d1bdb (diff)
intermediate changes
ref:ac52b2b4969cd1562fcebef15e16af428f77648b
Diffstat (limited to 'contrib/tools/python3/src/Modules')
-rw-r--r--contrib/tools/python3/src/Modules/_hashopenssl.c13
-rw-r--r--contrib/tools/python3/src/Modules/_sre.c44
-rw-r--r--contrib/tools/python3/src/Modules/binascii.c22
-rw-r--r--contrib/tools/python3/src/Modules/faulthandler.c6
-rw-r--r--contrib/tools/python3/src/Modules/sre.h1
5 files changed, 69 insertions, 17 deletions
diff --git a/contrib/tools/python3/src/Modules/_hashopenssl.c b/contrib/tools/python3/src/Modules/_hashopenssl.c
index 4873bb11aa0..4db058c0627 100644
--- a/contrib/tools/python3/src/Modules/_hashopenssl.c
+++ b/contrib/tools/python3/src/Modules/_hashopenssl.c
@@ -1860,15 +1860,21 @@ typedef struct _internal_name_mapper_state {
/* A callback function to pass to OpenSSL's OBJ_NAME_do_all(...) */
static void
+#if OPENSSL_VERSION_NUMBER >= 0x30000000L
+_openssl_hash_name_mapper(EVP_MD *md, void *arg)
+#else
_openssl_hash_name_mapper(const EVP_MD *md, const char *from,
const char *to, void *arg)
+#endif
{
_InternalNameMapperState *state = (_InternalNameMapperState *)arg;
PyObject *py_name;
assert(state != NULL);
- if (md == NULL)
+ // ignore all undefined providers
+ if ((md == NULL) || (EVP_MD_nid(md) == NID_undef)) {
return;
+ }
py_name = py_digest_name(md);
if (py_name == NULL) {
@@ -1894,7 +1900,12 @@ hashlib_md_meth_names(PyObject *module)
return -1;
}
+#if OPENSSL_VERSION_NUMBER >= 0x30000000L
+ // get algorithms from all activated providers in default context
+ EVP_MD_do_all_provided(NULL, &_openssl_hash_name_mapper, &state);
+#else
EVP_MD_do_all(&_openssl_hash_name_mapper, &state);
+#endif
if (state.error) {
Py_DECREF(state.set);
diff --git a/contrib/tools/python3/src/Modules/_sre.c b/contrib/tools/python3/src/Modules/_sre.c
index 8225c36da1a..338530e2dc9 100644
--- a/contrib/tools/python3/src/Modules/_sre.c
+++ b/contrib/tools/python3/src/Modules/_sre.c
@@ -2391,6 +2391,25 @@ scanner_dealloc(ScannerObject* self)
PyObject_DEL(self);
}
+static int
+scanner_begin(ScannerObject* self)
+{
+ if (self->executing) {
+ PyErr_SetString(PyExc_ValueError,
+ "regular expression scanner already executing");
+ return 0;
+ }
+ self->executing = 1;
+ return 1;
+}
+
+static void
+scanner_end(ScannerObject* self)
+{
+ assert(self->executing);
+ self->executing = 0;
+}
+
/*[clinic input]
_sre.SRE_Scanner.match
@@ -2404,16 +2423,23 @@ _sre_SRE_Scanner_match_impl(ScannerObject *self)
PyObject* match;
Py_ssize_t status;
- if (state->start == NULL)
+ if (!scanner_begin(self)) {
+ return NULL;
+ }
+ if (state->start == NULL) {
+ scanner_end(self);
Py_RETURN_NONE;
+ }
state_reset(state);
state->ptr = state->start;
status = sre_match(state, PatternObject_GetCode(self->pattern));
- if (PyErr_Occurred())
+ if (PyErr_Occurred()) {
+ scanner_end(self);
return NULL;
+ }
match = pattern_new_match((PatternObject*) self->pattern,
state, status);
@@ -2425,6 +2451,7 @@ _sre_SRE_Scanner_match_impl(ScannerObject *self)
state->start = state->ptr;
}
+ scanner_end(self);
return match;
}
@@ -2442,16 +2469,23 @@ _sre_SRE_Scanner_search_impl(ScannerObject *self)
PyObject* match;
Py_ssize_t status;
- if (state->start == NULL)
+ if (!scanner_begin(self)) {
+ return NULL;
+ }
+ if (state->start == NULL) {
+ scanner_end(self);
Py_RETURN_NONE;
+ }
state_reset(state);
state->ptr = state->start;
status = sre_search(state, PatternObject_GetCode(self->pattern));
- if (PyErr_Occurred())
+ if (PyErr_Occurred()) {
+ scanner_end(self);
return NULL;
+ }
match = pattern_new_match((PatternObject*) self->pattern,
state, status);
@@ -2463,6 +2497,7 @@ _sre_SRE_Scanner_search_impl(ScannerObject *self)
state->start = state->ptr;
}
+ scanner_end(self);
return match;
}
@@ -2476,6 +2511,7 @@ pattern_scanner(PatternObject *self, PyObject *string, Py_ssize_t pos, Py_ssize_
if (!scanner)
return NULL;
scanner->pattern = NULL;
+ scanner->executing = 0;
/* create search state object */
if (!state_init(&scanner->state, self, string, pos, endpos)) {
diff --git a/contrib/tools/python3/src/Modules/binascii.c b/contrib/tools/python3/src/Modules/binascii.c
index 1f3248b6049..3777580a79f 100644
--- a/contrib/tools/python3/src/Modules/binascii.c
+++ b/contrib/tools/python3/src/Modules/binascii.c
@@ -1120,16 +1120,20 @@ binascii_crc32_impl(PyObject *module, Py_buffer *data, unsigned int crc)
/*[clinic end generated code: output=52cf59056a78593b input=bbe340bc99d25aa8]*/
#ifdef USE_ZLIB_CRC32
-/* This was taken from zlibmodule.c PyZlib_crc32 (but is PY_SSIZE_T_CLEAN) */
+/* The same core as zlibmodule.c zlib_crc32_impl. */
{
- const Byte *buf;
- Py_ssize_t len;
- int signed_val;
-
- buf = (Byte*)data->buf;
- len = data->len;
- signed_val = crc32(crc, buf, len);
- return (unsigned int)signed_val & 0xffffffffU;
+ unsigned char *buf = data->buf;
+ Py_ssize_t len = data->len;
+
+ /* Avoid truncation of length for very large buffers. crc32() takes
+ length as an unsigned int, which may be narrower than Py_ssize_t. */
+ while ((size_t)len > UINT_MAX) {
+ crc = crc32(crc, buf, UINT_MAX);
+ buf += (size_t) UINT_MAX;
+ len -= (size_t) UINT_MAX;
+ }
+ crc = crc32(crc, buf, (unsigned int)len);
+ return crc & 0xffffffff;
}
#else /* USE_ZLIB_CRC32 */
{ /* By Jim Ahlstrom; All rights transferred to CNRI */
diff --git a/contrib/tools/python3/src/Modules/faulthandler.c b/contrib/tools/python3/src/Modules/faulthandler.c
index 764ff439d77..16f98ace3bb 100644
--- a/contrib/tools/python3/src/Modules/faulthandler.c
+++ b/contrib/tools/python3/src/Modules/faulthandler.c
@@ -21,9 +21,9 @@
# define FAULTHANDLER_USE_ALT_STACK
#endif
-#if defined(FAULTHANDLER_USE_ALT_STACK) && defined(HAVE_LINUX_AUXVEC_H)
-# include <linux/auxvec.h>
-# include <sys/auxv.h>
+#if defined(FAULTHANDLER_USE_ALT_STACK) && defined(HAVE_LINUX_AUXVEC_H) && defined(HAVE_SYS_AUXV_H)
+# include <linux/auxvec.h> // AT_MINSIGSTKSZ
+# include <sys/auxv.h> // getauxval()
#endif
/* Allocate at maximum 100 MiB of the stack to raise the stack overflow */
diff --git a/contrib/tools/python3/src/Modules/sre.h b/contrib/tools/python3/src/Modules/sre.h
index 9b0d8b19042..785adbd003e 100644
--- a/contrib/tools/python3/src/Modules/sre.h
+++ b/contrib/tools/python3/src/Modules/sre.h
@@ -89,6 +89,7 @@ typedef struct {
PyObject_HEAD
PyObject* pattern;
SRE_STATE state;
+ int executing;
} ScannerObject;
#endif