VirtualBox

Changeset 95229 in vbox for trunk/src/VBox/Main/xml


Ignore:
Timestamp:
Jun 8, 2022 1:10:39 PM (3 years ago)
Author:
vboxsync
Message:

Guest properties: more checks when reading properties from xml, bugref:10185.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/xml/Settings.cpp

    r94981 r95229  
    8383#include <iprt/stream.h>
    8484#include <iprt/uri.h>
     85
     86// Guest Properties validation.
     87#include "VBox/HostServices/GuestPropertySvc.h"
    8588
    8689// generated header
     
    46444647    {
    46454648        GuestProperty prop;
     4649        int rc;
     4650
    46464651        pelmProp->getAttributeValue("name", prop.strName);
    46474652        pelmProp->getAttributeValue("value", prop.strValue);
     
    46494654        pelmProp->getAttributeValue("timestamp", prop.timestamp);
    46504655        pelmProp->getAttributeValue("flags", prop.strFlags);
     4656
     4657        /* Check guest property 'name' and 'value' for correctness before
     4658         * placing it to local cache. */
     4659
     4660        rc = GuestPropValidateName(prop.strName.c_str(), (uint32_t)prop.strName.length() + 1  /* '\0' */);
     4661        if (RT_FAILURE(rc))
     4662        {
     4663            LogRel(("WARNING: Guest property with invalid name (%s) present in VM configuration file. Guest property will be dropped.\n",
     4664                    prop.strName.c_str()));
     4665            continue;
     4666        }
     4667
     4668        rc = GuestPropValidateValue(prop.strValue.c_str(), (uint32_t)prop.strValue.length() + 1  /* '\0' */);
     4669        if (rc == VERR_TOO_MUCH_DATA)
     4670        {
     4671            LogRel(("WARNING: Guest property '%s' present in VM configuration file and has too long value. Guest property value will be truncated.\n",
     4672                    prop.strName.c_str()));
     4673
     4674            /* In order to pass validation, guest property value length (including '\0') in bytes
     4675             * should be less than GUEST_PROP_MAX_VALUE_LEN. Reallocate it to corresponding size. */
     4676            rc = prop.strValue.reserveNoThrow(GUEST_PROP_MAX_VALUE_LEN - 1);
     4677            if (RT_SUCCESS(rc))
     4678            {
     4679                prop.strValue.mutableRaw()[GUEST_PROP_MAX_VALUE_LEN - 2] = '\0';
     4680                prop.strValue.jolt();
     4681            }
     4682            else
     4683            {
     4684                LogRel(("WARNING: Unable to truncate guest property '%s' valuem rc=%Rrc. Guest property value will be skipped.\n",
     4685                        prop.strName.c_str(), rc));
     4686                continue;
     4687            }
     4688        }
     4689        else if (RT_FAILURE(rc))
     4690        {
     4691            LogRel(("WARNING: Guest property '%s' present in VM configuration file and has invalid value. Guest property will be dropped.\n",
     4692                    prop.strName.c_str()));
     4693            continue;
     4694        }
     4695
    46514696        hw.llGuestProperties.push_back(prop);
    46524697    }
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