VirtualBox

Changeset 70108 in vbox for trunk/include/VBox/HostServices


Ignore:
Timestamp:
Dec 13, 2017 12:35:13 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, take #2.

File:
1 edited

Legend:

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

    r70091 r70108  
    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. */
     
    179180
    180181    AssertLogRelReturn(VALID_PTR(pszFlags), VERR_INVALID_POINTER);
     182    AssertLogRelReturn(cbFlags,             VERR_INVALID_PARAMETER);
     183
     184    pszFlags[0] = '\0';
     185
    181186    if ((fFlags & ~GUEST_PROP_F_ALLFLAGS) == GUEST_PROP_F_NILFLAG)
    182187    {
    183         char *pszNext;
    184188        unsigned i;
    185189
     
    189193            fFlags |= GUEST_PROP_F_TRANSIENT;
    190194
    191         pszNext = pszFlags;
    192195        for (i = 0; i < RT_ELEMENTS(s_aFlagList); ++i)
    193196        {
    194197            if (s_aFlagList[i] == (fFlags & s_aFlagList[i]))
    195198            {
    196                 strcpy(pszNext, GuestPropFlagName(s_aFlagList[i]));
    197                 pszNext += GuestPropFlagNameLen(s_aFlagList[i]);
     199                rc = RTStrCat(pszFlags, cbFlags, GuestPropFlagName(s_aFlagList[i]));
     200                if (RT_FAILURE(rc))
     201                    break;
     202
    198203                fFlags &= ~s_aFlagList[i];
     204
    199205                if (fFlags != GUEST_PROP_F_NILFLAG)
    200206                {
    201                     strcpy(pszNext, ", ");
    202                     pszNext += 2;
     207                    rc = RTStrCat(pszFlags, cbFlags, ", ");
     208                    if (RT_FAILURE(rc))
     209                        break;
    203210                }
    204211            }
    205212        }
    206         *pszNext = '\0';
    207213
    208214        Assert(fFlags == GUEST_PROP_F_NILFLAG); /* bad s_aFlagList */
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