VirtualBox

Changeset 10814

Show
Ignore:
Timestamp:
07/22/08 15:50:54 (1 month ago)
Author:
vboxsync
Message:

HostServices/GuestProperties?, Main, Additions/common, VBox/VBoxGuest.h: guest properties fixes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/include/VBox/VBoxGuest.h

    r10797 r10814  
    15331533VBGLR3DECL(int)     VbglR3GuestPropConnect(uint32_t *pu32ClientId); 
    15341534VBGLR3DECL(int)     VbglR3GuestPropDisconnect(uint32_t u32ClientId); 
    1535 VBGLR3DECL(int)     VbglR3GuestPropWrite(uint32_t u32ClientId, char *pszName, char *pszValue, char *pszFlags); 
    1536 VBGLR3DECL(int)     VbglR3GuestPropWriteValue(uint32_t u32ClientId, char *pszName, char *pszValue); 
     1535VBGLR3DECL(int)     VbglR3GuestPropWrite(uint32_t u32ClientId, const char *pszName, const char *pszValue, const char *pszFlags); 
     1536VBGLR3DECL(int)     VbglR3GuestPropWriteValue(uint32_t u32ClientId, const char *pszName, const char *pszValue); 
    15371537VBGLR3DECL(int)     VbglR3GuestPropRead(uint32_t u32ClientId, const char *pszName, void *pvBuf, uint32_t cbBuf, char **ppszValue, uint64_t *pu64Timestamp, char **ppszFlags, uint32_t *pcbBufActual); 
    15381538VBGLR3DECL(int)     VbglR3GuestPropReadValue(uint32_t ClientId, const char *pszName, char *pszValue, uint32_t cchValue, uint32_t *pcchValueActual); 
  • trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibGuestProp.cpp

    r10797 r10814  
    9191 * @param   pszFlags        The flags for the property 
    9292 */ 
    93 VBGLR3DECL(int) VbglR3GuestPropWrite(uint32_t u32ClientId, char *pszName, char *pszValue, char *pszFlags) 
     93VBGLR3DECL(int) VbglR3GuestPropWrite(uint32_t u32ClientId, const char *pszName, const char *pszValue, const char *pszFlags) 
    9494{ 
    9595    int rc; 
     
    103103        Msg.hdr.u32Function = SET_PROP_VALUE; 
    104104        Msg.hdr.cParms = 2; 
    105         VbglHGCMParmPtrSet(&Msg.name, pszName, strlen(pszName) + 1); 
    106         VbglHGCMParmPtrSet(&Msg.value, pszValue, strlen(pszValue) + 1); 
    107         VbglHGCMParmPtrSet(&Msg.flags, pszFlags, strlen(pszFlags) + 1); 
     105        VbglHGCMParmPtrSet(&Msg.name, const_cast<char *>(pszName), strlen(pszName) + 1); 
     106        VbglHGCMParmPtrSet(&Msg.value, const_cast<char *>(pszValue), strlen(pszValue) + 1); 
     107        VbglHGCMParmPtrSet(&Msg.flags, const_cast<char *>(pszFlags), strlen(pszFlags) + 1); 
    108108        rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg)); 
    109109        if (RT_SUCCESS(rc)) 
     
    118118        Msg.hdr.u32Function = DEL_PROP; 
    119119        Msg.hdr.cParms = 1; 
    120         VbglHGCMParmPtrSet(&Msg.name, pszName, strlen(pszName) + 1); 
     120        VbglHGCMParmPtrSet(&Msg.name, const_cast<char *>(pszName), strlen(pszName) + 1); 
    121121        rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg)); 
    122122        if (RT_SUCCESS(rc)) 
     
    138138 *        property's flags field will be left unchanged 
    139139 */ 
    140 VBGLR3DECL(int) VbglR3GuestPropWriteValue(uint32_t u32ClientId, char *pszName, char *pszValue) 
     140VBGLR3DECL(int) VbglR3GuestPropWriteValue(uint32_t u32ClientId, const char *pszName, const char *pszValue) 
    141141{ 
    142142    int rc; 
     
    150150        Msg.hdr.u32Function = SET_PROP_VALUE; 
    151151        Msg.hdr.cParms = 2; 
    152         VbglHGCMParmPtrSet(&Msg.name, pszName, strlen(pszName) + 1); 
    153         VbglHGCMParmPtrSet(&Msg.value, pszValue, strlen(pszValue) + 1); 
     152        VbglHGCMParmPtrSet(&Msg.name, const_cast<char *>(pszName), strlen(pszName) + 1); 
     153        VbglHGCMParmPtrSet(&Msg.value, const_cast<char *>(pszValue), strlen(pszValue) + 1); 
    154154        rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg)); 
    155155        if (RT_SUCCESS(rc)) 
     
    164164        Msg.hdr.u32Function = DEL_PROP; 
    165165        Msg.hdr.cParms = 1; 
    166         VbglHGCMParmPtrSet(&Msg.name, pszName, strlen(pszName) + 1); 
     166        VbglHGCMParmPtrSet(&Msg.name, const_cast<char *>(pszName), strlen(pszName) + 1); 
    167167        rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg)); 
    168168        if (RT_SUCCESS(rc)) 
     
    228228    if (RT_SUCCESS(rc) && (ppszFlags != NULL)) 
    229229    { 
    230         bool found = false; 
    231         size_t i = 0; 
    232         char *pcBuf = reinterpret_cast<char *>(pvBuf); 
    233         for (; i < cbBuf && !found; ++i) 
    234             if (0 == pcBuf[i]) 
    235                 found = true; 
    236         if (!found) 
    237             /* To my mind this is an internal error, but whatever */ 
     230        char *pszEos = reinterpret_cast<char *>(memchr(pvBuf, '\0', cbBuf)); 
     231        if (pszEos) 
     232            *ppszFlags = pszEos + 1; 
     233        else 
    238234            rc = VERR_TOO_MUCH_DATA; 
    239         else 
    240             *ppszFlags = pcBuf + i; 
    241235    } 
    242236    return rc; 
     
    248242 * 
    249243 * @returns VBox status code. 
    250  * @retval  VINF_SUCCESS on success, pszValue containing valid data. 
    251  * @retval  VERR_NOT_FOUND if the key wasn't found. 
     244 * @retval  VINF_SUCCESS on success, *ppszValue containing valid data. 
     245 * @retval  VERR_NOT_FOUND if the key wasn't found and *ppszValue set to NULL. 
     246 * @retval  VERR_TOO_MUCH_DATA if we were unable to determine the right size 
     247 *          to allocate for the buffer.  This can happen as the result of a 
     248 *          race between our allocating space and the host changing the 
     249 *          property value. 
    252250 * 
    253251 * @param   u32ClientId     The client id returned by VbglR3ClipboardConnect(). 
     
    263261    void *pvBuf = RTMemAlloc(cchBuf); 
    264262    char *pszValue = NULL; 
     263    *ppszValue = NULL; 
    265264    if (NULL == pvBuf) 
    266265        rc = VERR_NO_MEMORY; 
    267266    if (RT_SUCCESS(rc)) 
    268267    { 
    269         rc = VbglR3GuestPropRead(u32ClientId, pszName, pvBuf, cchBuf, 
    270                                  &pszValue, NULL, NULL, &cchBuf); 
     268        /* There is a race here between our reading the property size and the 
     269         * host changing the value before we read it.  Try up to ten times and 
     270         * report the problem if that fails. */ 
     271        bool finish = false; 
     272        for (unsigned i = 0; (i < 10) && !finish; ++i) 
     273        { 
     274            rc = VbglR3GuestPropRead(u32ClientId, pszName, pvBuf, cchBuf, 
     275                                     &pszValue, NULL, NULL, &cchBuf); 
     276            if (VERR_BUFFER_OVERFLOW == rc) 
     277            { 
     278                pvBuf = RTMemRealloc(pvBuf, cchBuf); 
     279                if (NULL == pvBuf) 
     280                    rc = VERR_NO_MEMORY; 
     281            } 
     282            if (rc != VERR_BUFFER_OVERFLOW) 
     283                finish = true; 
     284        } 
    271285        if (VERR_BUFFER_OVERFLOW == rc) 
    272         { 
    273             /** @todo how should we handle the race condition here? */ 
    274             pvBuf = RTMemRealloc(pvBuf, cchBuf); 
    275             if (pvBuf != NULL) 
    276                 rc = VbglR3GuestPropRead(u32ClientId, pszName, pvBuf, cchBuf, 
    277                                          &pszValue, NULL, NULL, NULL); 
    278             else 
    279                 rc = VERR_NO_MEMORY; 
    280             if (VERR_BUFFER_OVERFLOW == rc) 
    281                 /* VERR_BUFFER_OVERFLOW has a different meaning here as a 
    282                  * return code */ 
    283                 rc = VERR_TOO_MUCH_DATA; 
    284         } 
     286            /* VERR_BUFFER_OVERFLOW has a different meaning here as a 
     287             * return code, but we need to report the race. */ 
     288            rc = VERR_TOO_MUCH_DATA; 
    285289    } 
    286290    if (RT_SUCCESS(rc)) 
  • trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibVideo.cpp

    r10797 r10814  
    246246    using namespace guestProp; 
    247247 
    248     char szModeName[MAX_NAME_LEN]; 
    249     char szModeParms[MAX_VALUE_LEN]; 
     248    char szModeName[MAX_NAME_LEN + 1]; 
     249    char szModeParms[MAX_VALUE_LEN + 1]; 
    250250    uint32_t u32ClientId = 0; 
    251251    RTStrPrintf(szModeName, sizeof(szModeName), VIDEO_PROP_PREFIX"%s", pszName); 
     
    290290    if (RT_SUCCESS(rc)) 
    291291    { 
    292         char szModeName[MAX_NAME_LEN]; 
     292        char szModeName[MAX_NAME_LEN + 1]; 
    293293        RTStrPrintf(szModeName, sizeof(szModeName), VIDEO_PROP_PREFIX"%s", pszName); 
    294294        /** @todo add a VbglR3GuestPropReadValueF/FV that does the RTStrPrintf for you. */ 
  • trunk/src/VBox/HostServices/GuestProperties/service.cpp

    r10797 r10814  
    196196    /* Validate the format of the key. */ 
    197197    /* Only accept names in valid Utf8. */ 
    198     rc = RTStrValidateEncodingEx(pszKey, cbKey, 0); 
     198    rc = RTStrValidateEncodingEx(pszKey, cbKey - 1, 0); 
    199199    if (RT_SUCCESS(rc)) 
    200200        /* We want the byte length, not the Utf8 length */ 
     
    226226    /* Validate the format of the value. */ 
    227227    /* Only accept values in valid Utf8 */ 
    228     rc = RTStrValidateEncodingEx(pszValue, cbValue, 0); 
     228    rc = RTStrValidateEncodingEx(pszValue, cbValue - 1, 0); 
    229229    if (RT_SUCCESS(rc)) 
    230230        /* We want the byte length, not the Utf8 length */ 
  • trunk/src/VBox/Main/ConsoleImpl.cpp

    r10797 r10814  
    35613561    VBOXHGCMSVCPARM parm[3]; 
    35623562    Utf8Str Utf8Key = aKey; 
    3563     Utf8Str Utf8Value (MAX_VALUE_LEN); 
     3563    Utf8Str Utf8Value (MAX_VALUE_LEN + 1); 
    35643564 
    35653565    parm[0].type = VBOX_HGCM_SVC_PARM_PTR; 
     
    35703570    parm[1].type = VBOX_HGCM_SVC_PARM_PTR; 
    35713571    parm[1].u.pointer.addr = Utf8Value.mutableRaw(); 
    3572     parm[1].u.pointer.size = MAX_VALUE_LEN
     3572    parm[1].u.pointer.size = MAX_VALUE_LEN + 1
    35733573    int vrc = mVMMDev->hgcmHostCall ("VBoxGuestPropSvc", GET_CONFIG_KEY_HOST, 
    35743574                                     3, &parm[0]); 
     
    41804180    { 
    41814181        using namespace guestProp; 
    4182         char szKeyName[MAX_NAME_LEN]; 
    4183         char szKeyValue[MAX_VALUE_LEN]; 
    4184         char szExtraDataName[VBOX_SHARED_INFO_PREFIX_LEN + MAX_NAME_LEN]; 
    4185         vrc = CFGMR3GetValueName (pValue, szKeyName, MAX_NAME_LEN); 
     4182        char szKeyName[MAX_NAME_LEN + 1]; 
     4183        char szKeyValue[MAX_VALUE_LEN + 1]; 
     4184        char szExtraDataName[VBOX_SHARED_INFO_PREFIX_LEN + MAX_NAME_LEN + 1]; 
     4185        vrc = CFGMR3GetValueName (pValue, szKeyName, sizeof(szKeyName)); 
    41864186        if (RT_SUCCESS(vrc)) 
    41874187            vrc = CFGMR3QueryString (pRegistry, szKeyName, szKeyValue, sizeof(szKeyValue)); 
     
    42244224 
    42254225        /* Now see if a lookup of the name in the CFGM node succeeds. */ 
    4226         char szKeyValue[MAX_VALUE_LEN]; 
     4226        char szKeyValue[MAX_VALUE_LEN + 1]; 
    42274227        vrc = CFGMR3QueryString (pRegistry, pszCFGMValueName, szKeyValue, sizeof(szKeyValue)); 
    42284228        /* And delete it from the extra data if it failed. */ 

© 2008 Sun Microsystems, Inc.
ContactPrivacy policy