Skip to content

Commit c2578c1

Browse files
committed
Refactor GetProcessSid to remove do while FALSE
1 parent 7d1de9b commit c2578c1

File tree

3 files changed

+19
-32
lines changed

3 files changed

+19
-32
lines changed
Binary file not shown.
Binary file not shown.

external/source/exploits/cve-2017-8464/template.c

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -48,44 +48,31 @@ BOOL GetProcessSid(HANDLE hProc, PSID *pSid) {
4848
SIZE_T szSid = 0;
4949

5050
*pSid = NULL;
51-
do {
52-
if (!OpenProcessToken(hProc, (TOKEN_READ), &hToken)) {
53-
return FALSE;
54-
}
55-
56-
GetTokenInformation(hToken, TokenUser, NULL, 0, &dwLength);
57-
tuUser = (TOKEN_USER *)malloc(dwLength);
58-
if (tuUser == NULL) {
59-
break;
60-
}
61-
62-
if (!GetTokenInformation(hToken, TokenUser, tuUser, dwLength, &dwLength)) {
63-
break;
64-
}
65-
66-
szSid = GetLengthSid(tuUser->User.Sid);
67-
*pSid = LocalAlloc(LPTR, szSid);
68-
if (*pSid == NULL) {
69-
break;
70-
}
51+
if (!OpenProcessToken(hProc, (TOKEN_READ), &hToken)) {
52+
return FALSE;
53+
}
7154

72-
if (!CopySid((DWORD)szSid, *pSid, tuUser->User.Sid)) {
73-
LocalFree(*pSid);
74-
*pSid = NULL;
75-
}
76-
} while (FALSE);
55+
GetTokenInformation(hToken, TokenUser, NULL, 0, &dwLength);
56+
tuUser = (TOKEN_USER *)malloc(dwLength);
57+
if (!tuUser) {
58+
return FALSE;
59+
}
7760

78-
if (tuUser != NULL) {
61+
if (!GetTokenInformation(hToken, TokenUser, tuUser, dwLength, &dwLength)) {
7962
free(tuUser);
80-
}
81-
if (hToken) {
82-
CloseHandle(hToken);
63+
return FALSE;
8364
}
8465

85-
if (*pSid != NULL) {
86-
return TRUE;
66+
szSid = GetLengthSid(tuUser->User.Sid);
67+
*pSid = LocalAlloc(LPTR, szSid);
68+
if ((*pSid) && (!CopySid((DWORD)szSid, *pSid, tuUser->User.Sid))) {
69+
LocalFree(*pSid);
70+
*pSid = NULL;
8771
}
88-
return FALSE;
72+
73+
free(tuUser);
74+
CloseHandle(hToken);
75+
return *pSid != NULL;
8976
}
9077

9178
BOOL IsProcessRunningAsSidString(HANDLE hProc, LPCTSTR sStringSid, PBOOL pbResult) {

0 commit comments

Comments
 (0)