Skip to content

Commit 82c117c

Browse files
committed
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
1 parent 8a24179 commit 82c117c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/backend/utils/mmgr/mcxt.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include "postgres.h"
2323

24+
#include "common/string.h"
2425
#include "miscadmin.h"
2526
#include "utils/memdebug.h"
2627
#include "utils/memutils.h"
@@ -1086,10 +1087,14 @@ pstrdup(const char *in)
10861087
char *
10871088
pnstrdup(const char *in, Size len)
10881089
{
1089-
char *out = palloc(len + 1);
1090+
char *out;
10901091

1092+
len = pg_strnlen(in, len);
1093+
1094+
out = palloc(len + 1);
10911095
memcpy(out, in, len);
10921096
out[len] = '\0';
1097+
10931098
return out;
10941099
}
10951100

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy