VirtualBox

Changeset 9995 in vbox


Ignore:
Timestamp:
Jun 27, 2008 1:20:53 PM (17 years ago)
Author:
vboxsync
Message:

HostServices/SharedInfoService: did a cleanup todo

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostServices/SharedInfoServices/service.cpp

    r9917 r9995  
    153153    }
    154154private:
     155    int validateKey(const char *pszKey, uint32_t cbKey);
     156    int validateValue(char *pszValue, uint32_t cbValue);
    155157    int getKey(uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
    156     int validateGetKey(const char *pszKey, uint32_t cbKey, char *pszValue, uint32_t cbValue);
    157158    int setKey(uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
    158     int validateSetKey(const char *pszKey, uint32_t cbKey, char *pszValue, uint32_t cbValue);
    159159    void call (VBOXHGCMCALLHANDLE callHandle, uint32_t u32ClientID,
    160160               void *pvClient, uint32_t eFunction, uint32_t cParms,
     
    165165
    166166/**
    167  * Retrieve a value from the guest registry by key, checking the validity
    168  * of the arguments passed.
    169  *
    170  * @returns iprt status value
    171  * @param   cParms  the number of HGCM parameters supplied
    172  * @param   paParms the array of HGCM parameters
    173  * @thread  HGCM
    174  */
    175 int Service::getKey(uint32_t cParms, VBOXHGCMSVCPARM paParms[])
    176 {
    177     int rc = VINF_SUCCESS;
    178     char *pszKey, *pszValue;
    179     uint32_t cbKey, cbValue;
    180     size_t cbValueActual;
    181 
    182     LogFlowThisFunc(("\n"));
    183     if (   (cParms != 3)  /* Hardcoded value as the next lines depend on it. */
    184         || (paParms[0].type != VBOX_HGCM_SVC_PARM_PTR)   /* key */
    185         || (paParms[1].type != VBOX_HGCM_SVC_PARM_PTR)   /* value */
    186        )
    187         rc = VERR_INVALID_PARAMETER;
    188     if (RT_SUCCESS(rc))
    189         rc = VBoxHGCMParmPtrGet(&paParms[0], (void **) &pszKey, &cbKey);
    190     if (RT_SUCCESS(rc))
    191         rc = VBoxHGCMParmPtrGet(&paParms[1], (void **) &pszValue, &cbValue);
    192     if (RT_SUCCESS(rc))
    193         rc = validateGetKey(pszKey, cbKey, pszValue, cbValue);
    194     if (RT_SUCCESS(rc))
    195         rc = CFGMR3QuerySize(mpNode, pszKey, &cbValueActual);
    196     if (RT_SUCCESS(rc))
    197         VBoxHGCMParmUInt32Set(&paParms[2], cbValueActual);
    198     if (RT_SUCCESS(rc) && (cbValueActual > cbValue))
    199         rc = VINF_BUFFER_OVERFLOW;
    200     if (RT_SUCCESS(rc) && (rc != VINF_BUFFER_OVERFLOW))
    201         rc = CFGMR3QueryString(mpNode, pszKey, pszValue, cbValue);
    202     if (RT_SUCCESS(rc) && (rc != VINF_BUFFER_OVERFLOW))
    203         Log2(("Queried string %s, rc=%Rrc, value=%.*s\n", pszKey, rc, cbValue, pszValue));
    204     else if (VERR_CFGM_VALUE_NOT_FOUND == rc)
    205     {
    206         VBoxHGCMParmUInt32Set(&paParms[2], 0);
    207         rc = VINF_SUCCESS;
    208     }
    209     LogFlowThisFunc(("rc = %Rrc\n", rc));
    210     return rc;
    211 }
    212 
    213 
    214 /**
    215  * Checking that the data passed by the guest fits our criteria for getting the
    216  * value of a configuration key (currently stored as extra data in the machine
    217  * XML file)
     167 * Checking that the key passed by the guest fits our criteria for a
     168 * configuration key
    218169 *
    219170 * @returns IPRT status code
    220171 * @param   pszKey    the key passed by the guest
    221  * @param   cbKey     the number of bytes pszKey points to, including the terminating '\0'
    222  * @param   pszValue  the buffer to store the key name into
    223  * @param   cbValue   the size of the array for storing the key value
     172 * @param   cbKey     the number of bytes pszKey points to, including the
     173 *                    terminating '\0'
    224174 * @thread  HGCM
    225175 */
    226 int Service::validateGetKey(const char *pszKey, uint32_t cbKey, char *pszValue, uint32_t cbValue)
    227 {
    228     LogFlowFunc(("cbKey=%d, cbValue=%d\n", cbKey, cbValue));
     176int Service::validateKey(const char *pszKey, uint32_t cbKey)
     177{
     178    LogFlowFunc(("cbKey=%d\n", cbKey));
    229179
    230180    unsigned count;
     
    244194        rc = VERR_INVALID_PARAMETER;
    245195
    246     if (RT_SUCCESS(rc))
    247         LogFlow(("    pszKey=%s\n", pszKey));
    248196    LogFlowFunc(("returning %Rrc\n", rc));
    249197    return rc;
     
    252200
    253201/**
    254  * Set a value in the guest registry by key, checking the validity
    255  * of the arguments passed.
    256  *
    257  * @returns iprt status value
    258  * @param   cParms  the number of HGCM parameters supplied
    259  * @param   paParms the array of HGCM parameters
    260  * @thread  HGCM
    261  */
    262 int Service::setKey(uint32_t cParms, VBOXHGCMSVCPARM paParms[])
    263 {
    264     int rc = VINF_SUCCESS;
    265     char *pszKey, *pszValue;
    266     uint32_t cbKey, cbValue;
    267 
    268     LogFlowThisFunc(("\n"));
    269     if (   (cParms != 2)  /* Hardcoded value as the next lines depend on it. */
    270         || (paParms[0].type != VBOX_HGCM_SVC_PARM_PTR)   /* key */
    271         || (paParms[1].type != VBOX_HGCM_SVC_PARM_PTR)   /* value */
    272        )
    273         rc = VERR_INVALID_PARAMETER;
    274     if (RT_SUCCESS(rc))
    275         rc = VBoxHGCMParmPtrGet(&paParms[0], (void **) &pszKey, &cbKey);
    276     if (RT_SUCCESS(rc))
    277         rc = VBoxHGCMParmPtrGet(&paParms[1], (void **) &pszValue, &cbValue);
    278     if (RT_SUCCESS(rc))
    279         rc = validateSetKey(pszKey, cbKey, pszValue, cbValue);
    280     if (RT_SUCCESS(rc))
    281     {
    282         /* Limit the number of keys that we can set. */
    283         unsigned cChildren = 0;
    284         for (PCFGMNODE pChild = CFGMR3GetFirstChild(mpNode); pChild != 0; pChild = CFGMR3GetNextChild(pChild))
    285             ++cChildren;
    286         if (cChildren >= KEY_MAX_KEYS)
    287             rc = VERR_TOO_MUCH_DATA;
    288     }
    289     if (RT_SUCCESS(rc))
    290     {
    291         CFGMR3RemoveValue(mpNode, pszKey);
    292         if (pszValue > 0)
    293             rc = CFGMR3InsertString(mpNode, pszKey, pszValue);
    294     }
    295     if (RT_SUCCESS(rc))
    296         Log2(("Set string %s, rc=%Rrc, value=%s\n", pszKey, rc, pszValue));
    297     LogFlowThisFunc(("rc = %Rrc\n", rc));
    298     return rc;
    299 }
    300 
    301 
    302 /**
    303  * Check that the data passed by the guest fits our criteria for setting the
    304  * value of a configuration key (currently stored as extra data in the machine
    305  * XML file)
     202 * Check that the data passed by the guest fits our criteria for the value of
     203 * a configuration key
    306204 *
    307205 * @returns IPRT status code
    308  * @param   pszKey    the key passed by the guest
    309  * @param   cbKey     the number of bytes in the buffer pszKey points to
    310206 * @param   pszValue  the value to store in the key
    311207 * @param   cbValue   the number of bytes in the buffer pszValue points to
    312208 * @thread  HGCM
    313209 */
    314 int Service::validateSetKey(const char *pszKey, uint32_t cbKey, char *pszValue,
    315                                    uint32_t cbValue)
    316 {
    317     LogFlowFunc(("cbKey=%d, cbValue=%d\n", cbKey, cbValue));
    318 
    319     unsigned count;
    320     int rc = VINF_SUCCESS;
    321 
    322     /* Validate the format of the key. */
    323     if (cbKey < sizeof(VBOX_SHARED_INFO_KEY_PREFIX))
    324         rc = VERR_INVALID_PARAMETER;
    325     /** @todo duplicate check in validateGetKey, use separate method. mixing unsigned and uint32_t. */
    326     /* Only accept names in printable ASCII without spaces */
    327     for (count = 0; (count < cbKey) && (pszKey[count] != '\0'); ++count)
    328         if ((pszKey[count] < 33) || (pszKey[count] > 126))
    329             rc = VERR_INVALID_PARAMETER;
    330     if (RT_SUCCESS(rc) && (count == cbKey))
    331         /* This would mean that no null terminator was found */
    332         rc = VERR_INVALID_PARAMETER;
    333     if (RT_SUCCESS(rc) && (count > KEY_MAX_LEN))
    334         rc = VERR_INVALID_PARAMETER;
     210int Service::validateValue(char *pszValue, uint32_t cbValue)
     211{
     212    LogFlowFunc(("cbValue=%d\n", cbValue));
     213
     214    uint32_t count;
     215    int rc = VINF_SUCCESS;
    335216
    336217    if (cbValue != 0)
     
    349230
    350231    if (RT_SUCCESS(rc))
    351         LogFlow(("    pszKey=%s, pszValue=%s\n", pszKey, cbValue > 0 ? pszValue : NULL));
     232        LogFlow(("    pszValue=%s\n", cbValue > 0 ? pszValue : NULL));
    352233    LogFlowFunc(("returning %Rrc\n", rc));
     234    return rc;
     235}
     236
     237
     238/**
     239 * Retrieve a value from the guest registry by key, checking the validity
     240 * of the arguments passed.
     241 *
     242 * @returns iprt status value
     243 * @param   cParms  the number of HGCM parameters supplied
     244 * @param   paParms the array of HGCM parameters
     245 * @thread  HGCM
     246 */
     247int Service::getKey(uint32_t cParms, VBOXHGCMSVCPARM paParms[])
     248{
     249    int rc = VINF_SUCCESS;
     250    char *pszKey, *pszValue;
     251    uint32_t cbKey, cbValue;
     252    size_t cbValueActual;
     253
     254    LogFlowThisFunc(("\n"));
     255    if (   (cParms != 3)  /* Hardcoded value as the next lines depend on it. */
     256        || (paParms[0].type != VBOX_HGCM_SVC_PARM_PTR)   /* key */
     257        || (paParms[1].type != VBOX_HGCM_SVC_PARM_PTR)   /* value */
     258       )
     259        rc = VERR_INVALID_PARAMETER;
     260    if (RT_SUCCESS(rc))
     261        rc = VBoxHGCMParmPtrGet(&paParms[0], (void **) &pszKey, &cbKey);
     262    if (RT_SUCCESS(rc))
     263        rc = VBoxHGCMParmPtrGet(&paParms[1], (void **) &pszValue, &cbValue);
     264    if (RT_SUCCESS(rc))
     265        rc = validateKey(pszKey, cbKey);
     266    if (RT_SUCCESS(rc))
     267        rc = CFGMR3QuerySize(mpNode, pszKey, &cbValueActual);
     268    if (RT_SUCCESS(rc))
     269        VBoxHGCMParmUInt32Set(&paParms[2], cbValueActual);
     270    if (RT_SUCCESS(rc) && (cbValueActual > cbValue))
     271        rc = VINF_BUFFER_OVERFLOW;
     272    if (RT_SUCCESS(rc) && (rc != VINF_BUFFER_OVERFLOW))
     273        rc = CFGMR3QueryString(mpNode, pszKey, pszValue, cbValue);
     274    if (RT_SUCCESS(rc) && (rc != VINF_BUFFER_OVERFLOW))
     275        Log2(("Queried string %s, rc=%Rrc, value=%.*s\n", pszKey, rc, cbValue, pszValue));
     276    else if (VERR_CFGM_VALUE_NOT_FOUND == rc)
     277    {
     278        VBoxHGCMParmUInt32Set(&paParms[2], 0);
     279        rc = VINF_SUCCESS;
     280    }
     281    LogFlowThisFunc(("rc = %Rrc\n", rc));
     282    return rc;
     283}
     284
     285
     286/**
     287 * Set a value in the guest registry by key, checking the validity
     288 * of the arguments passed.
     289 *
     290 * @returns iprt status value
     291 * @param   cParms  the number of HGCM parameters supplied
     292 * @param   paParms the array of HGCM parameters
     293 * @thread  HGCM
     294 */
     295int Service::setKey(uint32_t cParms, VBOXHGCMSVCPARM paParms[])
     296{
     297    int rc = VINF_SUCCESS;
     298    char *pszKey, *pszValue;
     299    uint32_t cbKey, cbValue;
     300
     301    LogFlowThisFunc(("\n"));
     302    if (   (cParms != 2)  /* Hardcoded value as the next lines depend on it. */
     303        || (paParms[0].type != VBOX_HGCM_SVC_PARM_PTR)   /* key */
     304        || (paParms[1].type != VBOX_HGCM_SVC_PARM_PTR)   /* value */
     305       )
     306        rc = VERR_INVALID_PARAMETER;
     307    if (RT_SUCCESS(rc))
     308        rc = VBoxHGCMParmPtrGet(&paParms[0], (void **) &pszKey, &cbKey);
     309    if (RT_SUCCESS(rc))
     310        rc = VBoxHGCMParmPtrGet(&paParms[1], (void **) &pszValue, &cbValue);
     311    if (RT_SUCCESS(rc))
     312        rc = validateKey(pszKey, cbKey);
     313    if (RT_SUCCESS(rc))
     314        rc = validateValue(pszValue, cbValue);
     315    if (RT_SUCCESS(rc))
     316    {
     317        /* Limit the number of keys that we can set. */
     318        unsigned cChildren = 0;
     319        for (PCFGMNODE pChild = CFGMR3GetFirstChild(mpNode); pChild != 0; pChild = CFGMR3GetNextChild(pChild))
     320            ++cChildren;
     321        if (cChildren >= KEY_MAX_KEYS)
     322            rc = VERR_TOO_MUCH_DATA;
     323    }
     324    if (RT_SUCCESS(rc))
     325    {
     326        CFGMR3RemoveValue(mpNode, pszKey);
     327        if (pszValue > 0)
     328            rc = CFGMR3InsertString(mpNode, pszKey, pszValue);
     329    }
     330    if (RT_SUCCESS(rc))
     331        Log2(("Set string %s, rc=%Rrc, value=%s\n", pszKey, rc, pszValue));
     332    LogFlowThisFunc(("rc = %Rrc\n", rc));
    353333    return rc;
    354334}
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