VirtualBox

Changeset 21485 in vbox for trunk/include


Ignore:
Timestamp:
Jul 10, 2009 4:33:50 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
49929
Message:

sf: parameter validation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/shflsvc.h

    r21227 r21485  
    141141#define SHFL_MAX_MAPPINGS    (64)
    142142
    143 /** Shared Folders strings. They can be either UTF8 or Unicode.
    144  *  @{
    145  */
    146 
     143/** @name Shared Folders strings. They can be either UTF-8 or UTF-16.
     144 * @{
     145 */
     146
     147/**
     148 * Shared folder string buffer structure.
     149 */
    147150typedef struct _SHFLSTRING
    148151{
    149     /** Size of string String buffer in bytes. */
     152    /** Size of the String member in bytes. */
    150153    uint16_t u16Size;
    151154
     
    153156    uint16_t u16Length;
    154157
    155     /** UTF8 or Unicode16 string. Nul terminated. */
     158    /** UTF-8 or UTF-16 string. Nul terminated. */
    156159    union
    157160    {
     
    161164} SHFLSTRING;
    162165
     166/** Pointer to a shared folder string buffer. */
    163167typedef SHFLSTRING *PSHFLSTRING;
     168/** Pointer to a const shared folder string buffer. */
     169typedef const SHFLSTRING *PCSHFLSTRING;
    164170
    165171/** Calculate size of the string. */
    166 DECLINLINE(uint32_t) ShflStringSizeOfBuffer (PSHFLSTRING pString)
     172DECLINLINE(uint32_t) ShflStringSizeOfBuffer (PCSHFLSTRING pString)
    167173{
    168174    return pString? sizeof (SHFLSTRING) - sizeof (pString->String) + pString->u16Size: 0;
    169175}
    170176
    171 DECLINLINE(uint32_t) ShflStringLength (PSHFLSTRING pString)
     177DECLINLINE(uint32_t) ShflStringLength (PCSHFLSTRING pString)
    172178{
    173179    return pString? pString->u16Length: 0;
     
    191197
    192198    return pString;
     199}
     200
     201/**
     202 * Validates a HGCM string parameter.
     203 *
     204 * @returns true if valid, false if not.
     205 *
     206 * @param   pString     The string buffer pointer.
     207 * @param   cbBuf       The buffer size from the parameter.
     208 */
     209DECLINLINE(bool) ShflStringIsValid(PCSHFLSTRING pString, uint32_t cbBuf)
     210{
     211    if (RT_UNLIKELY(cbBuf <= RT_UOFFSETOF(SHFLSTRING, String)))
     212        return false;
     213    if (RT_UNLIKELY((uint32_t)pString->u16Size + RT_UOFFSETOF(SHFLSTRING, String) > cbBuf))
     214        return false;
     215    if (RT_UNLIKELY(pString->u16Length >= pString->u16Size))
     216        return false;
     217    return true;
     218}
     219
     220/**
     221 * Validates an optional HGCM string parameter.
     222 *
     223 * @returns true if valid, false if not.
     224 *
     225 * @param   pString     The string buffer pointer. Can be NULL.
     226 * @param   cbBuf       The buffer size from the parameter.
     227 */
     228DECLINLINE(bool) ShflStringIsValidOrNull(PCSHFLSTRING pString, uint32_t cbBuf)
     229{
     230    if (pString)
     231        return ShflStringIsValid(pString, cbBuf);
     232    if (RT_UNLIKELY(cbBuf > 0))
     233        return false;
     234    return true;
    193235}
    194236
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