diff --git a/src/common/saslprep.c b/src/common/saslprep.c index 8945050ad2..0f224508d3 100644 --- a/src/common/saslprep.c +++ b/src/common/saslprep.c @@ -21,8 +21,13 @@ */ #ifndef FRONTEND #include "postgres.h" +#include "utils/memutils.h" #else #include "postgres_fe.h" + +/* It's possible we could use a different value for this in frontend code */ +#define MaxAllocSize ((Size) 0x3fffffff) /* 1 gigabyte - 1 */ + #endif #include "common/saslprep.h" @@ -1077,6 +1082,8 @@ pg_saslprep(const char *input, char **output) input_size = pg_utf8_string_len(input); if (input_size < 0) return SASLPREP_INVALID_UTF8; + if (input_size >= MaxAllocSize / sizeof(pg_wchar)) + goto oom; input_chars = ALLOC((input_size + 1) * sizeof(pg_wchar)); if (!input_chars)