Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcc28a27

Browse files
committed
Use dynamic buffer for token buffer in win32 admin check
Magnus Hagander
1 parent1c72d0d commitcc28a27

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

‎src/backend/port/win32/security.c

Lines changed: 27 additions & 4 deletions
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
HANDLEAccessToken;
28-
UCHARInfoBuffer[1024];
29-
PTOKEN_GROUPSGroups= (PTOKEN_GROUPS)InfoBuffer;
28+
char*InfoBuffer=NULL;
29+
PTOKEN_GROUPSGroups;
3030
DWORDInfoBufferSize;
3131
PSIDAdministratorsSid;
3232
PSIDPowerUsersSid;
@@ -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
returnsuccess;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp