VirtualBox

Changeset 26848 in vbox for trunk/src/VBox/Runtime


Ignore:
Timestamp:
Feb 26, 2010 1:22:09 PM (15 years ago)
Author:
vboxsync
Message:

tstRTSystemQueryOsInfo.cpp: Copied back the corrected overflow test from tstRTSystemQueryDmi.cpp.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/testcase/tstRTSystemQueryOsInfo.cpp

    r26605 r26848  
    3333*******************************************************************************/
    3434#include <iprt/system.h>
     35
     36#include <iprt/assert.h>
    3537#include <iprt/string.h>
    3638#include <iprt/test.h>
     
    5456     * Simple stuff.
    5557     */
    56     char szInfo[256];
     58    char szInfo[_4K];
    5759
    5860    rc = RTSystemQueryOSInfo(RTSYSOSINFO_PRODUCT, szInfo, sizeof(szInfo));
     
    8789     * Check buffer overflow
    8890     */
    89     for (int i = RTSYSOSINFO_INVALID + 1; i < RTSYSOSINFO_END; i++)
     91    RTAssertSetQuiet(true);
     92    RTAssertSetMayPanic(false);
     93    for (int i = RTSYSDMISTR_INVALID + 1; i < RTSYSDMISTR_END; i++)
    9094    {
    91         rc = VERR_BUFFER_OVERFLOW;
    92         for (size_t cch = 0; cch < sizeof(szInfo) && rc == VERR_BUFFER_OVERFLOW; cch++)
     95        RTTESTI_CHECK_RC(RTSystemQueryDmiString((RTSYSDMISTR)i, szInfo, 0), VERR_INVALID_PARAMETER);
     96
     97        /* Get the length of the info and check that we get overflow errors for
     98           everything less that it.  */
     99        rc = RTSystemQueryOSInfo((RTSYSOSINFO)i, szInfo, sizeof(szInfo));
     100        if (RT_FAILURE(rc))
     101            continue;
     102        size_t const cchInfo = strlen(szInfo);
     103
     104        for (size_t cch = 1; cch < sizeof(szInfo) && cch < cchInfo; cch++)
    93105        {
    94106            memset(szInfo, 0x7f, sizeof(szInfo));
    95             rc = RTSystemQueryOSInfo((RTSYSOSINFO)i, szInfo, cch);
     107            RTTESTI_CHECK_RC(RTSystemQueryOSInfo((RTSYSOSINFO)i, szInfo, cch), VERR_BUFFER_OVERFLOW);
    96108
    97109            /* check the padding. */
     
    104116
    105117            /* check for zero terminator. */
    106             if (    (   rc == VERR_BUFFER_OVERFLOW
    107                      || rc == VERR_NOT_SUPPORTED
    108                      || RT_SUCCESS(rc))
    109                 &&  cch > 0
    110                 &&  !memchr(szInfo, '\0', cch))
    111             {
     118            if (!memchr(szInfo, '\0', cch))
     119                RTTestIFailed("level=%d, rc=%Rrc, cch=%zu: Buffer not terminated!\n", i, rc, cch);
     120        }
    112121
    113                 RTTestIFailed("level=%d, rc=%Rrc, cch=%zu: Buffer not terminated!\n", i, rc, cch);
    114                 g_cErrors++;
    115             }
    116         }
     122        /* Check that the exact length works. */
     123        rc = RTSystemQueryOSInfo((RTSYSOSINFO)i, szInfo, cchInfo + 1);
     124        if (rc != VINF_SUCCESS)
     125            RTTestIFailed("level=%d: rc=%Rrc when specifying exactly right buffer length (%zu)\n", i, rc, cchInfo + 1);
    117126    }
    118127
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