Home > Blockchain >  GetAce() failing with - ERROR_INVALID_PARAMETER
GetAce() failing with - ERROR_INVALID_PARAMETER

Time:04-17

I'm attempting to do some ACL modification with some C code in Visual Studio. I'm stumbling into several issues, one of which is that, when I try to read the ACEs off the existing ACL using GetAce(), the call to the function fails and it returns error 87, ERROR_INVALID_PARAMETER.

The ACL in question includes four entries, and the first two are read successfully, but the second two fail with the invalid parameter error.

Here's the snippet of code that I'm running, I'd appreciate any insight anyone has on it.

// filePath variable is passed in from command line...
PACL existingAcl;

if(GetNamedSecurityInfo(filePath, SE_FILE_OBJECT, DACL_SECURITY_INFORMATION, NULL, NULL, &existingAcl, NULL, &securityDescriptor) != ERROR_SUCCESS) {
    OutputDebugString("Could not retrieve ACL.\n");
    return false;
}

const int numEntries = existingAcl->AceCount;

for(DWORD i = 0; i < numEntries; i  ) {
    EXPLICIT_ACCESS* thisAce;

    if (!GetAce(existingAcl, i, (LPVOID*) &thisAce)) {
        OutputDebugString("Failed to retrieve ACE.\n");
        return false;
    }
}

CodePudding user response:

I was modifying a member of one of the ACEs retrieved from the ACL directly, within the loop, which was most likely adjusting pointers or memory in such a way that broke things with memory allocation, etc. Thanks to @273K for pointing me in the right direction!

  • Related