VirtualBox

Ignore:
Timestamp:
Nov 8, 2011 1:20:28 PM (13 years ago)
Author:
vboxsync
Message:

Test GET_NOTIFICATION with guard pages.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostServices/GuestProperties/testcase/tstGuestPropSvc.cpp

    r39236 r39240  
    672672
    673673    /* Test "buffer too small" */
    674     char                        achBuffer[MAX_NAME_LEN + MAX_VALUE_LEN + MAX_FLAGS_LEN];
    675674    static char                 s_szPattern[] = "";
    676675    VBOXHGCMCALLHANDLE_TYPEDEF  callHandle = { VINF_SUCCESS };
    677676    VBOXHGCMSVCPARM             aParms[4];
    678     aParms[0].setPointer((void *)s_szPattern, sizeof(s_szPattern));
    679     aParms[1].setUInt64(1);
    680     aParms[2].setPointer((void *)achBuffer, g_aGetNotifications[0].cbBuffer - 1);
    681     pTable->pfnCall(pTable->pvService, &callHandle, 0, NULL, GET_NOTIFICATION, 4, aParms);
    682 
    683     uint32_t cbRetNeeded;
    684     if (   callHandle.rc != VERR_BUFFER_OVERFLOW
    685         || RT_FAILURE(aParms[3].getUInt32(&cbRetNeeded))
    686         || cbRetNeeded != g_aGetNotifications[0].cbBuffer
    687        )
    688     {
    689         RTTestIFailed("Getting notification for property '%s' with a too small buffer did not fail correctly.",
    690                       g_aGetNotifications[0].pchBuffer);
    691         return;
     677    uint32_t                    cbRetNeeded;
     678
     679    for (uint32_t cbBuf = 1;
     680         cbBuf < g_aGetNotifications[0].cbBuffer - 1;
     681         cbBuf++)
     682    {
     683        void *pvBuf = RTTestGuardedAllocTail(g_hTest, cbBuf);
     684        RTTESTI_CHECK_BREAK(pvBuf);
     685        memset(pvBuf, 0x55, cbBuf);
     686
     687        aParms[0].setPointer((void *)s_szPattern, sizeof(s_szPattern));
     688        aParms[1].setUInt64(1);
     689        aParms[2].setPointer(pvBuf, cbBuf);
     690        pTable->pfnCall(pTable->pvService, &callHandle, 0, NULL, GET_NOTIFICATION, 4, aParms);
     691
     692        if (   callHandle.rc != VERR_BUFFER_OVERFLOW
     693            || RT_FAILURE(aParms[3].getUInt32(&cbRetNeeded))
     694            || cbRetNeeded != g_aGetNotifications[0].cbBuffer
     695           )
     696        {
     697            RTTestIFailed("Getting notification for property '%s' with a too small buffer did not fail correctly: %Rrc",
     698                          g_aGetNotifications[0].pchBuffer, callHandle.rc);
     699        }
     700        RTTestGuardedFree(g_hTest, pvBuf);
    692701    }
    693702
     
    697706    for (unsigned i = 0; i < RT_ELEMENTS(g_aGetNotifications); ++i)
    698707    {
     708        uint32_t cbBuf = g_aGetNotifications[i].cbBuffer + _1K;
     709        void *pvBuf = RTTestGuardedAllocTail(g_hTest, cbBuf);
     710        RTTESTI_CHECK_BREAK(pvBuf);
     711        memset(pvBuf, 0x55, cbBuf);
     712
    699713        aParms[0].setPointer((void *)s_szPattern, sizeof(s_szPattern));
    700714        aParms[1].setUInt64(u64Timestamp);
    701         aParms[2].setPointer((void *)achBuffer, sizeof(achBuffer));
     715        aParms[2].setPointer(pvBuf, cbBuf);
    702716        pTable->pfnCall(pTable->pvService, &callHandle, 0, NULL, GET_NOTIFICATION, 4, aParms);
    703717        if (   RT_FAILURE(callHandle.rc)
     
    706720            || RT_FAILURE(aParms[3].getUInt32(&cbRetNeeded))
    707721            || cbRetNeeded != g_aGetNotifications[i].cbBuffer
    708             || memcmp(achBuffer, g_aGetNotifications[i].pchBuffer, cbRetNeeded) != 0
     722            || memcmp(pvBuf, g_aGetNotifications[i].pchBuffer, cbRetNeeded) != 0
    709723           )
    710724        {
     
    712726                          g_aGetNotifications[i].pchBuffer, callHandle.rc);
    713727        }
     728        RTTestGuardedFree(g_hTest, pvBuf);
    714729    }
    715730}
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette