RE: Can there be any bug in GetSecurityInfo ?
- From: lelteto <lelteto@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 3 Jul 2007 09:16:01 -0700
Well, if CreateFile fails you don't free the allocated memory and your code
will leak.
and BTW I would first check if malloc succeeds before doing anything. There
is no point calling GetSecurityInfo if you don't have a buffer to get the
info.
(And your ZeroMemory might blow up anyway if it doesn't check for NULL
pointer)
Laszlo Elteto
SafeNet, Inc.
"Akın ÖCal" wrote:
I am doing everything for allocating and freeing sid structure but it always.
gives leakages please check the code :
BOOL GetAll (char* sFileOrFolderName )
{
DWORD dwRtnCode = 0;
HANDLE hFile;
char* pSidOwner = (char * ) malloc (MAX_SID_SIZE);
ZeroMemory(pSidOwner,MAX_SID_SIZE);
hFile = CreateFile(
sFileOrFolderName,
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
return FALSE;
}
dwRtnCode = GetSecurityInfo(
hFile,
SE_FILE_OBJECT,
OWNER_SECURITY_INFORMATION,
(PSID *)(pSidOwner),
NULL,
NULL,
NULL,
NULL);
if( !pSidOwner )
{
CloseHandle(hFile);
return FALSE;
}
free(pSidOwner);
CloseHandle(hFile);
return TRUE ;
}
int _tmain(int argc, _TCHAR* argv[])
{
while(1)
{
if(!GetAll("d:\\aa.txt"))
{
printf("\nFailed");
}
Sleep(1000);
}
return 0;
}
- References:
- Can there be any bug in GetSecurityInfo ?
- From: Akın ÖCal
- Can there be any bug in GetSecurityInfo ?
- Prev by Date: acquiring access token for "LocalService" from application started by the admin for SHGetFolderPath()
- Next by Date: Re: Failed to decrypt
- Previous by thread: Can there be any bug in GetSecurityInfo ?
- Next by thread: acquiring access token for "LocalService" from application started by the admin for SHGetFolderPath()
- Index(es):
Relevant Pages
|
|