Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit cc28a27

Browse files
committed
Use dynamic buffer for token buffer in win32 admin check
Magnus Hagander
1 parent 1c72d0d commit cc28a27

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

src/backend/port/win32/security.c

+27-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
77
*
88
* IDENTIFICATION
9-
* $PostgreSQL: pgsql/src/backend/port/win32/security.c,v 1.1 2004/06/24 21:02:42 tgl Exp $
9+
* $PostgreSQL: pgsql/src/backend/port/win32/security.c,v 1.2 2004/08/28 21:00:35 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -25,8 +25,8 @@ int
2525
pgwin32_is_admin(void)
2626
{
2727
HANDLE AccessToken;
28-
UCHAR InfoBuffer[1024];
29-
PTOKEN_GROUPS Groups = (PTOKEN_GROUPS)InfoBuffer;
28+
char *InfoBuffer = NULL;
29+
PTOKEN_GROUPS Groups;
3030
DWORD InfoBufferSize;
3131
PSID AdministratorsSid;
3232
PSID PowerUsersSid;
@@ -41,8 +41,30 @@ pgwin32_is_admin(void)
4141
exit(1);
4242
}
4343

44+
if (GetTokenInformation(AccessToken,TokenGroups,NULL,0,&InfoBufferSize))
45+
{
46+
write_stderr("failed to get token information - got zero size!\n");
47+
exit(1);
48+
}
49+
50+
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
51+
{
52+
write_stderr("failed to get token information: %d\n",
53+
(int)GetLastError());
54+
exit(1);
55+
}
56+
57+
InfoBuffer = malloc(InfoBufferSize);
58+
if (!InfoBuffer)
59+
{
60+
write_stderr("failed to allocate %i bytes for token information!\n",
61+
(int)InfoBufferSize);
62+
exit(1);
63+
}
64+
Groups = (PTOKEN_GROUPS)InfoBuffer;
65+
4466
if (!GetTokenInformation(AccessToken,TokenGroups,InfoBuffer,
45-
1024, &InfoBufferSize))
67+
InfoBufferSize, &InfoBufferSize))
4668
{
4769
write_stderr("failed to get token information: %d\n",
4870
(int)GetLastError());
@@ -81,6 +103,7 @@ pgwin32_is_admin(void)
81103
}
82104
}
83105

106+
free(InfoBuffer);
84107
FreeSid(AdministratorsSid);
85108
FreeSid(PowerUsersSid);
86109
return success;

0 commit comments

Comments
 (0)