Error 0x8007000e in LookupAccountSid()

0

I've got a quite old VS6 app that is generating error 0x8007000E (ERROR_OUTOFMEMORY "Not enough storage is available to complete this operation.") in a call to LookupAccountSid.

The call that fails is just trying to determine how large the buffers need to be to use in a second call to LookupAccountSid:

std::string GetNameFromSID(PSID pSid)
{
    if (NULL == pSid)
        return "";

    DWORD        _dwName;   //Size of the name in TCHARs
    DWORD        _dwDomain; //Size of the domain in TCHARs
    SID_NAME_USE _use;      //Usage type of the name (user,group etc).
    BOOL         _b;

    //Determine the buffer sizes we require
    SetLastError(0);
    _b = LookupAccountSid( NULL, pSid, NULL, &_dwName, NULL, &_dwDomain, &_use );
    if ( !_b ) {
        DWORD _dw = GetLastError();
        if ( ERROR_NONE_MAPPED == _dw ) {
            //There is no name for this SID
            return "";
        } else if ( ERROR_INSUFFICIENT_BUFFER == _dw ) {
            //This is expected.
        } else if ( S_OK != _dw ) {
            //This is where we see ERROR_OUTOFMEMORY
            return "";
        }
    }
    //Do some other stuff here...
}

What I expected was error 0x8007007A : ERROR_INSUFFICIENT_BUFFER "The data area passed to a system call is too small." Which would indicate that I (unsurprisingly) needed to allocate larger buffers.

The system is not low on memory at all, so can anybody suggest a cause?

c++
windows
winapi
asked on Stack Overflow Jan 19, 2012 by Nigel Hawkins • edited Jan 19, 2012 by Nigel Hawkins

1 Answer

2

See if it works if you properly initialize _dwName and _dwDomain to 0.

There might be some random garbage on the stack, but according to http://msdn.microsoft.com/en-us/library/windows/desktop/aa379166(v=vs.85).aspx these have to be actually set to 0 to receive required buffer sizes

answered on Stack Overflow Jan 19, 2012 by bronekk

User contributions licensed under CC BY-SA 3.0