VirtualBox

Changeset 70086 in vbox


Ignore:
Timestamp:
Dec 12, 2017 5:36:51 PM (7 years ago)
Author:
vboxsync
Message:

Guest properties: Added a length check for GuestPropWriteFlags() and got rid of strcpy(), as this now also is marked as being deprecated on macOS.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/HostServices/GuestPropertySvc.h

    r70064 r70086  
    164164/**
    165165 * Write out flags to a string.
     166 *
    166167 * @returns  IPRT status code
    167  * @param    fFlags    the flags to write out
    168  * @param    pszFlags  where to write the flags string.  This must point to
    169  *                     a buffer of size (at least) MAX_FLAGS_LEN.
    170  */
    171 DECLINLINE(int) GuestPropWriteFlags(uint32_t fFlags, char *pszFlags)
     168 * @param    fFlags    The flags to write out.
     169 * @param    pszFlags  Where to write the flags string.
     170 * @param    cbFlags   The size of the destination buffer (in bytes).
     171 */
     172DECLINLINE(int) GuestPropWriteFlags(uint32_t fFlags, char* pszFlags, size_t cbFlags)
    172173{
    173174    /* Putting READONLY before the other RDONLY flags keeps the result short. */
     
    181182    if ((fFlags & ~GUEST_PROP_F_ALLFLAGS) == GUEST_PROP_F_NILFLAG)
    182183    {
    183         char *pszNext;
    184         unsigned i;
    185 
    186184        /* TRANSRESET implies TRANSIENT.  For compatability with old clients we
    187185           always set TRANSIENT when TRANSRESET appears. */
     
    189187            fFlags |= GUEST_PROP_F_TRANSIENT;
    190188
    191         pszNext = pszFlags;
    192         for (i = 0; i < RT_ELEMENTS(s_aFlagList); ++i)
     189        char *pszTemp = NULL;
     190
     191        for (unsigned i = 0; i < RT_ELEMENTS(s_aFlagList); ++i)
    193192        {
    194193            if (s_aFlagList[i] == (fFlags & s_aFlagList[i]))
    195194            {
    196                 strcpy(pszNext, GuestPropFlagName(s_aFlagList[i]));
    197                 pszNext += GuestPropFlagNameLen(s_aFlagList[i]);
     195                RTStrAAppend(&pszTemp, GuestPropFlagName(s_aFlagList[i]));
    198196                fFlags &= ~s_aFlagList[i];
    199197                if (fFlags != GUEST_PROP_F_NILFLAG)
    200                 {
    201                     strcpy(pszNext, ", ");
    202                     pszNext += 2;
    203                 }
     198                    RTStrAAppend(&pszTemp, ", ");
    204199            }
    205200        }
    206         *pszNext = '\0';
     201
     202        if (   RT_SUCCESS(rc)
     203            && pszTemp)
     204            rc = RTStrCopy(pszFlags, cbFlags, pszTemp);
     205
     206        if (pszTemp)
     207            RTStrFree(pszTemp);
    207208
    208209        Assert(fFlags == GUEST_PROP_F_NILFLAG); /* bad s_aFlagList */
  • trunk/src/VBox/HostServices/GuestProperties/service.cpp

    r70063 r70086  
    619619    {
    620620        char szFlags[GUEST_PROP_MAX_FLAGS_LEN];
    621         rc = GuestPropWriteFlags(pProp->mFlags, szFlags);
     621        rc = GuestPropWriteFlags(pProp->mFlags, szFlags, sizeof(szFlags));
    622622        if (RT_SUCCESS(rc))
    623623        {
     
    857857
    858858    char            szFlags[GUEST_PROP_MAX_FLAGS_LEN];
    859     int rc = GuestPropWriteFlags(pProp->mFlags, szFlags);
     859    int rc = GuestPropWriteFlags(pProp->mFlags, szFlags, sizeof(szFlags));
    860860    if (RT_FAILURE(rc))
    861861        return rc;
     
    10161016    {
    10171017        char szFlags[GUEST_PROP_MAX_FLAGS_LEN];
    1018         rc = GuestPropWriteFlags(prop.mFlags, szFlags);
     1018        rc = GuestPropWriteFlags(prop.mFlags, szFlags, sizeof(szFlags));
    10191019        if (RT_SUCCESS(rc))
    10201020        {
     
    12151215            /* Send out a host notification */
    12161216            const char *pszValue = prop.mValue.c_str();
    1217             rc = GuestPropWriteFlags(prop.mFlags, szFlags);
     1217            rc = GuestPropWriteFlags(prop.mFlags, szFlags, sizeof(szFlags));
    12181218            if (RT_SUCCESS(rc))
    12191219                rc = notifyHost(pszProperty, pszValue, u64Timestamp, szFlags);
     
    14061406
    14071407    char szFlags[GUEST_PROP_MAX_FLAGS_LEN];
    1408     int rc = GuestPropWriteFlags(pProp->mFlags, szFlags);
     1408    int rc = GuestPropWriteFlags(pProp->mFlags, szFlags, sizeof(szFlags));
    14091409    if (RT_FAILURE(rc))
    14101410        RTStrPrintf(szFlags, sizeof(szFlags), "???");
  • trunk/src/VBox/HostServices/GuestProperties/testcase/tstGuestPropSvc.cpp

    r70063 r70086  
    120120        if (RT_SUCCESS(rc))
    121121        {
    122             rc = GuestPropWriteFlags(fFlags, pszFlagBuffer);
     122            rc = GuestPropWriteFlags(fFlags, pszFlagBuffer, GUEST_PROP_MAX_FLAGS_LEN);
    123123            if (RT_FAILURE(rc))
    124124                RTTestIFailed("Failed to convert flag string '%s' back to a string.",
     
    159159        RTTestISub("Rejection of an invalid flags field");
    160160        /* This is required to fail. */
    161         if (RT_SUCCESS(GuestPropWriteFlags(u32BadFlags, pszFlagBuffer)))
     161        if (RT_SUCCESS(GuestPropWriteFlags(u32BadFlags, pszFlagBuffer, GUEST_PROP_MAX_FLAGS_LEN)))
    162162        {
    163163            RTTestIFailed("Flags 0x%x were incorrectly written out as '%.*s'\n",
     
    828828    {
    829829        char szFlags[GUEST_PROP_MAX_FLAGS_LEN];
    830         if (RT_FAILURE(GuestPropWriteFlags(fFlags, szFlags)))
     830        if (RT_FAILURE(GuestPropWriteFlags(fFlags, szFlags, sizeof(szFlags))))
    831831            RTTestIFailed("Failed to set the global flags.");
    832832        else
  • trunk/src/VBox/Main/src-client/ConsoleImpl2.cpp

    r70063 r70086  
    59745974    {
    59755975        char szFlags[GUEST_PROP_MAX_FLAGS_LEN];
    5976         if (RT_FAILURE(GuestPropWriteFlags(fFlags, szFlags)))
     5976        if (RT_FAILURE(GuestPropWriteFlags(fFlags, szFlags, sizeof(szFlags))))
    59775977            Log(("Failed to set the global flags.\n"));
    59785978        else
  • trunk/src/VBox/Main/src-server/MachineImpl.cpp

    r70061 r70086  
    56555655        aValue = it->second.strValue;
    56565656        *aTimestamp = it->second.mTimestamp;
    5657         GuestPropWriteFlags(it->second.mFlags, szFlags);
     5657        GuestPropWriteFlags(it->second.mFlags, szFlags, sizeof(szFlags));
    56585658        aFlags = Utf8Str(szFlags);
    56595659    }
     
    59375937        aValues[i] = it->second.strValue;
    59385938        aTimestamps[i] = it->second.mTimestamp;
    5939         GuestPropWriteFlags(it->second.mFlags, szFlags);
     5939        GuestPropWriteFlags(it->second.mFlags, szFlags, sizeof(szFlags));
    59405940        aFlags[i] = Utf8Str(szFlags);
    59415941    }
     
    1045210452            prop.timestamp = property.mTimestamp;
    1045310453            char szFlags[GUEST_PROP_MAX_FLAGS_LEN + 1];
    10454             GuestPropWriteFlags(property.mFlags, szFlags);
     10454            GuestPropWriteFlags(property.mFlags, szFlags, sizeof(szFlags));
    1045510455            prop.strFlags = szFlags;
    1045610456
     
    1353713537        if (it->second.mFlags)
    1353813538        {
    13539             GuestPropWriteFlags(it->second.mFlags, szFlags);
     13539            GuestPropWriteFlags(it->second.mFlags, szFlags, sizeof(szFlags));
    1354013540            aFlags[i] = szFlags;
    1354113541        }
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