aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndres Freund <andres@anarazel.de>2017-10-09 15:20:42 -0700
committerAndres Freund <andres@anarazel.de>2017-10-09 15:20:42 -0700
commit82c117cb90e6b6b79f06d61eb1ddf06e94e75b60 (patch)
tree9157fe6d998ef40cadd2aa6392b42d1d7a6ba22f /src
parent8a241792f968ed5be6cf4d41e32c0d264f6c0c65 (diff)
downloadpostgresql-82c117cb90e6b6b79f06d61eb1ddf06e94e75b60.tar.gz
postgresql-82c117cb90e6b6b79f06d61eb1ddf06e94e75b60.zip
Fix pnstrdup() to not memcpy() the maximum allowed length.
The previous behaviour was dangerous if the length passed wasn't the size of the underlying buffer, but the maximum size of the underlying buffer. Author: Andres Freund Discussion: https://postgr.es/m/20161003215524.mwz5p45pcverrkyk@alap3.anarazel.de
Diffstat (limited to 'src')
-rw-r--r--src/backend/utils/mmgr/mcxt.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/backend/utils/mmgr/mcxt.c b/src/backend/utils/mmgr/mcxt.c
index cd696f16bc7..64e0408d5af 100644
--- a/src/backend/utils/mmgr/mcxt.c
+++ b/src/backend/utils/mmgr/mcxt.c
@@ -21,6 +21,7 @@
#include "postgres.h"
+#include "common/string.h"
#include "miscadmin.h"
#include "utils/memdebug.h"
#include "utils/memutils.h"
@@ -1086,10 +1087,14 @@ pstrdup(const char *in)
char *
pnstrdup(const char *in, Size len)
{
- char *out = palloc(len + 1);
+ char *out;
+ len = pg_strnlen(in, len);
+
+ out = palloc(len + 1);
memcpy(out, in, len);
out[len] = '\0';
+
return out;
}