VirtualBox

Changeset 22526 in vbox for trunk/src


Ignore:
Timestamp:
Aug 27, 2009 1:52:56 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
51548
Message:

CFGM: Fixed string length bug in CFGMR3InsertStringFV.

Location:
trunk/src/VBox/VMM
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/CFGM.cpp

    r22346 r22526  
    549549
    550550            case CFGMVALUETYPE_STRING:
    551                 *pcb = pLeaf->Value.String.cch;
     551                *pcb = pLeaf->Value.String.cb;
    552552                break;
    553553
     
    638638        if (pLeaf->enmType == CFGMVALUETYPE_STRING)
    639639        {
    640             if (cchString >= pLeaf->Value.String.cch)
     640            size_t cbSrc = pLeaf->Value.String.cb;
     641            if (cchString >= cbSrc)
    641642            {
    642                 memcpy(pszString, pLeaf->Value.String.psz, pLeaf->Value.String.cch);
    643                 memset(pszString + pLeaf->Value.String.cch, 0, cchString - pLeaf->Value.String.cch);
     643                memcpy(pszString, pLeaf->Value.String.psz, cbSrc);
     644                memset(pszString + cbSrc, 0, cchString - cbSrc);
    644645            }
    645646            else
     
    671672        if (pLeaf->enmType == CFGMVALUETYPE_STRING)
    672673        {
    673             if (cchString >= pLeaf->Value.String.cch)
     674            size_t cbSrc = pLeaf->Value.String.cb;
     675            if (cchString >= cbSrc)
    674676            {
    675                 memcpy(pszString, pLeaf->Value.String.psz, pLeaf->Value.String.cch);
    676                 memset(pszString + pLeaf->Value.String.cch, 0, cchString - pLeaf->Value.String.cch);
     677                memcpy(pszString, pLeaf->Value.String.psz, cbSrc);
     678                memset(pszString + cbSrc, 0, cchString - cbSrc);
    677679            }
    678680            else
     
    15351537                MMR3HeapFree(pLeaf->Value.String.psz);
    15361538                pLeaf->Value.String.psz = NULL;
    1537                 pLeaf->Value.String.cch = 0;
     1539                pLeaf->Value.String.cb = 0;
    15381540                break;
    15391541
     
    15741576 * @param   pszName         Value name.
    15751577 * @param   pszString       The value.
    1576  */           
     1578 */
    15771579VMMR3DECL(int) CFGMR3InsertString(PCFGMNODE pNode, const char *pszName, const char *pszString)
    15781580{
     
    15831585         * Allocate string object first.
    15841586         */
    1585         size_t cchString = strlen(pszString) + 1;
    1586         char *pszStringCopy = (char *)MMR3HeapAlloc(pNode->pVM, MM_TAG_CFGM_STRING, RT_ALIGN_Z(cchString, 16));
     1587        size_t cbString = strlen(pszString) + 1;
     1588        char *pszStringCopy = (char *)MMR3HeapAlloc(pNode->pVM, MM_TAG_CFGM_STRING, cbString);
    15871589        if (pszStringCopy)
    15881590        {
    1589             memcpy(pszStringCopy, pszString, cchString);
     1591            memcpy(pszStringCopy, pszString, cbString);
    15901592
    15911593            /*
     
    15981600                pLeaf->enmType = CFGMVALUETYPE_STRING;
    15991601                pLeaf->Value.String.psz = pszStringCopy;
    1600                 pLeaf->Value.String.cch = cchString;
     1602                pLeaf->Value.String.cb  = cbString;
    16011603            }
    16021604            else
     
    16141616
    16151617/**
    1616  * Same as CFGMR3InsertString except the string value given in RTStrPrintfV 
    1617  * fashion. 
    1618  * 
     1618 * Same as CFGMR3InsertString except the string value given in RTStrPrintfV
     1619 * fashion.
     1620 *
    16191621 * @returns VBox status code.
    16201622 * @param   pNode           Parent node.
     
    16431645                pLeaf->enmType = CFGMVALUETYPE_STRING;
    16441646                pLeaf->Value.String.psz = pszString;
    1645                 pLeaf->Value.String.cch = strlen(pszString);
     1647                pLeaf->Value.String.cb  = strlen(pszString) + 1;
    16461648            }
    16471649            else
     
    16591661
    16601662/**
    1661  * Same as CFGMR3InsertString except the string value given in RTStrPrintf 
    1662  * fashion. 
    1663  * 
     1663 * Same as CFGMR3InsertString except the string value given in RTStrPrintf
     1664 * fashion.
     1665 *
    16641666 * @returns VBox status code.
    16651667 * @param   pNode           Parent node.
     
    16801682/**
    16811683 * Same as CFGMR3InsertString except the string value given as a UTF-16 string.
    1682  * 
     1684 *
    16831685 * @returns VBox status code.
    16841686 * @param   pNode           Parent node.
     
    17181720             * Allocate string object first.
    17191721             */
    1720             void *pvCopy = MMR3HeapAlloc(pNode->pVM, MM_TAG_CFGM_STRING, RT_ALIGN_Z(cbBytes, 16));
     1722            void *pvCopy = MMR3HeapAlloc(pNode->pVM, MM_TAG_CFGM_STRING, cbBytes);
    17211723            if (pvCopy || !cbBytes)
    17221724            {
     
    24652467VMMR3DECL(int) CFGMR3QueryStringAlloc(PCFGMNODE pNode, const char *pszName, char **ppszString)
    24662468{
    2467     size_t cch;
    2468     int rc = CFGMR3QuerySize(pNode, pszName, &cch);
    2469     if (RT_SUCCESS(rc))
    2470     {
    2471         char *pszString = (char *)MMR3HeapAlloc(pNode->pVM, MM_TAG_CFGM_USER, cch);
     2469    size_t cbString;
     2470    int rc = CFGMR3QuerySize(pNode, pszName, &cbString);
     2471    if (RT_SUCCESS(rc))
     2472    {
     2473        char *pszString = (char *)MMR3HeapAlloc(pNode->pVM, MM_TAG_CFGM_USER, cbString);
    24722474        if (pszString)
    24732475        {
    2474             rc = CFGMR3QueryString(pNode, pszName, pszString, cch);
     2476            rc = CFGMR3QueryString(pNode, pszName, pszString, cbString);
    24752477            if (RT_SUCCESS(rc))
    24762478                *ppszString = pszString;
     
    24972499VMMR3DECL(int) CFGMR3QueryStringAllocDef(PCFGMNODE pNode, const char *pszName, char **ppszString, const char *pszDef)
    24982500{
    2499     size_t cch;
    2500     int rc = CFGMR3QuerySize(pNode, pszName, &cch);
     2501    size_t cbString;
     2502    int rc = CFGMR3QuerySize(pNode, pszName, &cbString);
    25012503    if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT)
    25022504    {
    2503         cch = strlen(pszDef) + 1;
     2505        cbString = strlen(pszDef) + 1;
    25042506        rc = VINF_SUCCESS;
    25052507    }
    25062508    if (RT_SUCCESS(rc))
    25072509    {
    2508         char *pszString = (char *)MMR3HeapAlloc(pNode->pVM, MM_TAG_CFGM_USER, cch);
     2510        char *pszString = (char *)MMR3HeapAlloc(pNode->pVM, MM_TAG_CFGM_USER, cbString);
    25092511        if (pszString)
    25102512        {
    2511             rc = CFGMR3QueryStringDef(pNode, pszName, pszString, cch, pszDef);
     2513            rc = CFGMR3QueryStringDef(pNode, pszName, pszString, cbString, pszDef);
    25122514            if (RT_SUCCESS(rc))
    25132515                *ppszString = pszString;
     
    26072609
    26082610            case CFGMVALUETYPE_STRING:
    2609                 pHlp->pfnPrintf(pHlp, "  %-*s <string>  = \"%s\" (cch=%d)\n", (int)cchMax, pLeaf->szName, pLeaf->Value.String.psz, pLeaf->Value.String.cch);
     2611                pHlp->pfnPrintf(pHlp, "  %-*s <string>  = \"%s\" (cb=%zu)\n", (int)cchMax, pLeaf->szName, pLeaf->Value.String.psz, pLeaf->Value.String.cb);
    26102612                break;
    26112613
    26122614            case CFGMVALUETYPE_BYTES:
    2613                 pHlp->pfnPrintf(pHlp, "  %-*s <bytes>   = \"%.*Rhxs\" (cb=%d)\n", (int)cchMax, pLeaf->szName, pLeaf->Value.Bytes.cb, pLeaf->Value.Bytes.pau8, pLeaf->Value.Bytes.cb);
     2615                pHlp->pfnPrintf(pHlp, "  %-*s <bytes>   = \"%.*Rhxs\" (cb=%zu)\n", (int)cchMax, pLeaf->szName, pLeaf->Value.Bytes.cb, pLeaf->Value.Bytes.pau8, pLeaf->Value.Bytes.cb);
    26142616                break;
    26152617
  • trunk/src/VBox/VMM/CFGMInternal.h

    r14070 r22526  
    4949    {
    5050        /** Length of string. (In bytes, including the terminator.) */
    51         size_t          cch;
     51        size_t          cb;
    5252        /** Pointer to the string. */
    5353        char           *psz;
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