Don't leak admin group SID memory
authorJoseph C. Lehner <joseph.c.lehner@gmail.com>
Wed, 18 Jan 2017 12:22:31 +0000 (13:22 +0100)
committerJoseph C. Lehner <joseph.c.lehner@gmail.com>
Wed, 18 Jan 2017 13:37:58 +0000 (14:37 +0100)
main.c

diff --git a/main.c b/main.c
index 66d7d806680424ac926fd3d1cc1344eb4373f9c9..54cad4c5893512c1569ae45da52727f075d66389 100644 (file)
--- a/main.c
+++ b/main.c
@@ -84,22 +84,23 @@ void usage(FILE *fp)
 void require_admin()
 {
        SID_IDENTIFIER_AUTHORITY auth = SECURITY_NT_AUTHORITY;
-       PSID adminGroup = NULL;
-       BOOL success = AllocateAndInitializeSid(
+       PSID group = NULL;
+       BOOL admin, success = AllocateAndInitializeSid(
                &auth, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS,
-               0, 0, 0, 0, 0, 0, &adminGroup
+               0, 0, 0, 0, 0, 0, &group
        );
 
        if (success) {
-               if (CheckTokenMembership(NULL, adminGroup, &success)) {
-                       if (!success) {
+               success = CheckTokenMembership(NULL, group, &admin);
+               FreeSid(group);
+               if (success) {
+                       if (!admin) {
                                fprintf(stderr, "Error: must be run as administrator\n");
                                exit(1);
                        } else {
                                return;
                        }
                }
-               FreeSid(adminGroup);
        }
 
        fprintf(stderr, "Warning: failed to check administrator privileges\n");