VirtualBox

Ignore:
Timestamp:
Jul 22, 2008 1:50:54 PM (16 years ago)
Author:
vboxsync
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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))
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