8000 WIP: Make mkdtemp() more secure on Windows. · Giperboloid/postgres@62b1cdb · GitHub
[go: up one dir, main page]

Skip to content 8000

Commit 62b1cdb

Browse files
committed
WIP: Make mkdtemp() more secure on Windows.
Our POSIX mkdtemp() implementation in src/port/mkdtemp.c code would create directories with default permissions on Windows. Fix, using native Windows API instead of mkdir().
1 parent edf1
8000
2e7 commit 62b1cdb

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/port/mkdtemp.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,20 @@ GETTEMP(char *path, int *doopen, int domkdir)
187187
}
188188
else if (domkdir)
189189
{
190+
#ifdef WIN32
191+
SECURITY_ATTRIBUTES sa = {
192+
.nLength = sizeof(SECURITY_ATTRIBUTES),
193+
.lpSecurityDescriptor = NULL,
194+
.bInheritHandle = false
195+
};
196+
197+
if (CreateDirectory(path, &sa))
198+
return 1;
199+
_dosmaperr(GetLastError());
200+
#else
190201
if (mkdir(path, 0700) >= 0)
191202
return 1;
203+
#endif
192204
if (errno != EEXIST)
193205
return 0;
194206
}

0 commit comments

Comments
 (0)
0