Example #1
0
ULONG
APIENTRY
NtUserGetAtomName(
    _In_ ATOM atom,
    _Inout_ PUNICODE_STRING pustrName)
{
    WCHAR awcBuffer[256];
    ULONG cjLength;

    /* Retrieve the atom name into a local buffer (max length is 255 chars) */
    cjLength = IntGetAtomName((RTL_ATOM)atom, awcBuffer, sizeof(awcBuffer));
    if (cjLength != 0)
    {
        _SEH2_TRY
        {
            /* Probe the unicode string and the buffer */
            ProbeForRead(pustrName, sizeof(*pustrName), 1);
            ProbeForWrite(pustrName->Buffer, pustrName->MaximumLength, 1);

            /* Check if we have enough space to write the NULL termination */
            if (pustrName->MaximumLength >= sizeof(UNICODE_NULL))
            {
                /* Limit the length to the buffer size */
                cjLength = min(pustrName->MaximumLength - sizeof(UNICODE_NULL),
                cjLength);

                /* Copy the string and NULL terminate it */
                RtlCopyMemory(pustrName->Buffer, awcBuffer, cjLength);
                pustrName->Buffer[cjLength / sizeof(WCHAR)] = L'\0';
            }
            else
            {
                cjLength = 0;
            }
        }
        _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
        {
            /* On exception, set last error and fail */
            SetLastNtError(_SEH2_GetExceptionCode());
            cjLength = 0;
        }
        _SEH2_END
    }
Example #2
0
INT APIENTRY
NtUserGetClipboardFormatName(UINT fmt, LPWSTR lpszFormatName, INT cchMaxCount)
{
    INT iRet = 0;

    UserEnterShared();

    /* If the format is built-in we fail */
    if (fmt < 0xc000)
    {
        /* Registetrated formats are >= 0xc000 */
        goto cleanup;
    }

    if (cchMaxCount < 1 || !lpszFormatName)
    {
        EngSetLastError(ERROR_INVALID_PARAMETER);
        goto cleanup;
    }

    _SEH2_TRY
    {
        ProbeForWrite(lpszFormatName, cchMaxCount * sizeof(WCHAR), 1);

        iRet = IntGetAtomName((RTL_ATOM)fmt,
                              lpszFormatName,
                              cchMaxCount * sizeof(WCHAR));
        iRet /= sizeof(WCHAR);
    }
    _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
    {
        SetLastNtError(_SEH2_GetExceptionCode());
    }
    _SEH2_END;

cleanup:
    UserLeave();

    return iRet;
}