aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2015-02-21 16:49:28 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2015-02-21 16:49:35 -0500
commit332f02f88beead6365bc2126c95451520bbfe163 (patch)
tree0247a8f88212db6aa9b68ba6b2ecf0a45ec39754 /src
parent82a532b34d7547b43b90e2e4d4953f4be1c655b8 (diff)
downloadpostgresql-332f02f88beead6365bc2126c95451520bbfe163.tar.gz
postgresql-332f02f88beead6365bc2126c95451520bbfe163.zip
Use FLEXIBLE_ARRAY_MEMBER in Windows-specific code.
Be a tad more paranoid about overlength input, too.
Diffstat (limited to 'src')
-rw-r--r--src/port/dirmod.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/port/dirmod.c b/src/port/dirmod.c
index 6187a0a36dd..0d8b8a80699 100644
--- a/src/port/dirmod.c
+++ b/src/port/dirmod.c
@@ -143,7 +143,7 @@ typedef struct
WORD SubstituteNameLength;
WORD PrintNameOffset;
WORD PrintNameLength;
- WCHAR PathBuffer[1];
+ WCHAR PathBuffer[FLEXIBLE_ARRAY_MEMBER];
} REPARSE_JUNCTION_DATA_BUFFER;
#define REPARSE_JUNCTION_DATA_BUFFER_HEADER_SIZE \
@@ -160,7 +160,7 @@ pgsymlink(const char *oldpath, const char *newpath)
{
HANDLE dirhandle;
DWORD len;
- char buffer[MAX_PATH * sizeof(WCHAR) + sizeof(REPARSE_JUNCTION_DATA_BUFFER)];
+ char buffer[MAX_PATH * sizeof(WCHAR) + offsetof(REPARSE_JUNCTION_DATA_BUFFER, PathBuffer)];
char nativeTarget[MAX_PATH];
char *p = nativeTarget;
REPARSE_JUNCTION_DATA_BUFFER *reparseBuf = (REPARSE_JUNCTION_DATA_BUFFER *) buffer;
@@ -174,10 +174,10 @@ pgsymlink(const char *oldpath, const char *newpath)
return -1;
/* make sure we have an unparsed native win32 path */
- if (memcmp("\\??\\", oldpath, 4))
- sprintf(nativeTarget, "\\??\\%s", oldpath);
+ if (memcmp("\\??\\", oldpath, 4) != 0)
+ snprintf(nativeTarget, sizeof(nativeTarget), "\\??\\%s", oldpath);
else
- strcpy(nativeTarget, oldpath);
+ strlcpy(nativeTarget, oldpath, sizeof(nativeTarget));
while ((p = strchr(p, '/')) != NULL)
*p++ = '\\';
@@ -239,7 +239,7 @@ pgreadlink(const char *path, char *buf, size_t size)
{
DWORD attr;
HANDLE h;
- char buffer[MAX_PATH * sizeof(WCHAR) + sizeof(REPARSE_JUNCTION_DATA_BUFFER)];
+ char buffer[MAX_PATH * sizeof(WCHAR) + offsetof(REPARSE_JUNCTION_DATA_BUFFER, PathBuffer)];
REPARSE_JUNCTION_DATA_BUFFER *reparseBuf = (REPARSE_JUNCTION_DATA_BUFFER *) buffer;
DWORD len;
int r;