aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Python/mysnprintf.c
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.ru>2022-04-18 12:39:32 +0300
committershadchin <shadchin@yandex-team.ru>2022-04-18 12:39:32 +0300
commitd4be68e361f4258cf0848fc70018dfe37a2acc24 (patch)
tree153e294cd97ac8b5d7a989612704a0c1f58e8ad4 /contrib/tools/python3/src/Python/mysnprintf.c
parent260c02f5ccf242d9d9b8a873afaf6588c00237d6 (diff)
downloadydb-d4be68e361f4258cf0848fc70018dfe37a2acc24.tar.gz
IGNIETFERRO-1816 Update Python 3 from 3.9.12 to 3.10.4
ref:9f96be6d02ee8044fdd6f124b799b270c20ce641
Diffstat (limited to 'contrib/tools/python3/src/Python/mysnprintf.c')
-rw-r--r--contrib/tools/python3/src/Python/mysnprintf.c42
1 files changed, 5 insertions, 37 deletions
diff --git a/contrib/tools/python3/src/Python/mysnprintf.c b/contrib/tools/python3/src/Python/mysnprintf.c
index 458ca14d5c..cd69198011 100644
--- a/contrib/tools/python3/src/Python/mysnprintf.c
+++ b/contrib/tools/python3/src/Python/mysnprintf.c
@@ -15,10 +15,6 @@
PyOS_snprintf and PyOS_vsnprintf never write more than size bytes
(including the trailing '\0') into str.
- If the platform doesn't have vsnprintf, and the buffer size needed to
- avoid truncation exceeds size by more than 512, Python aborts with a
- Py_FatalError.
-
Return value (rv):
When 0 <= rv < size, the output conversion was unexceptional, and
@@ -37,6 +33,7 @@
PyMem_Malloc couldn't obtain space for a temp buffer.
CAUTION: Unlike C99, str != NULL and size > 0 are required.
+ Also, size must be smaller than INT_MAX.
*/
int
@@ -56,50 +53,22 @@ PyOS_vsnprintf(char *str, size_t size, const char *format, va_list va)
{
assert(str != NULL);
assert(size > 0);
+ assert(size <= (INT_MAX - 1));
assert(format != NULL);
int len; /* # bytes written, excluding \0 */
-#if defined(_MSC_VER) || defined(HAVE_SNPRINTF)
-# define _PyOS_vsnprintf_EXTRA_SPACE 1
-#else
-# define _PyOS_vsnprintf_EXTRA_SPACE 512
- char *buffer;
-#endif
/* We take a size_t as input but return an int. Sanity check
* our input so that it won't cause an overflow in the
- * vsnprintf return value or the buffer malloc size. */
- if (size > INT_MAX - _PyOS_vsnprintf_EXTRA_SPACE) {
+ * vsnprintf return value. */
+ if (size > INT_MAX - 1) {
len = -666;
goto Done;
}
#if defined(_MSC_VER)
len = _vsnprintf(str, size, format, va);
-#elif defined(HAVE_SNPRINTF)
- len = vsnprintf(str, size, format, va);
#else
- /* Emulate vsnprintf(). */
- buffer = PyMem_MALLOC(size + _PyOS_vsnprintf_EXTRA_SPACE);
- if (buffer == NULL) {
- len = -666;
- goto Done;
- }
-
- len = vsprintf(buffer, format, va);
- if (len < 0) {
- /* ignore the error */;
- }
- else if ((size_t)len >= size + _PyOS_vsnprintf_EXTRA_SPACE) {
- _Py_FatalErrorFunc(__func__, "Buffer overflow");
- }
- else {
- const size_t to_copy = (size_t)len < size ?
- (size_t)len : size - 1;
- assert(to_copy < size);
- memcpy(str, buffer, to_copy);
- str[to_copy] = '\0';
- }
- PyMem_FREE(buffer);
+ len = vsnprintf(str, size, format, va);
#endif
Done:
@@ -107,5 +76,4 @@ Done:
str[size-1] = '\0';
}
return len;
-#undef _PyOS_vsnprintf_EXTRA_SPACE
}