aboutsummaryrefslogtreecommitdiff
path: root/src/common/saslprep.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/saslprep.c')
-rw-r--r--src/common/saslprep.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/common/saslprep.c b/src/common/saslprep.c
index 78f6fcbd805..0a840352802 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"
@@ -1079,6 +1084,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)