VirtualBox

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


Ignore:
Timestamp:
Jun 21, 2013 10:07:31 AM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
86641
Message:

Main/xml/Settings.cpp: limit snapshot depth to 250, avoiding crashes
Main/Snapshot: limit snapshot depth to 250
Main/Medium: eliminate some spurious error messages when saving a VM config

File:
1 edited

Legend:

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

    r46667 r46720  
    34793479 * Snapshot structure.
    34803480 *
     3481 * @param depth
    34813482 * @param elmSnapshot
    34823483 * @param snap
    34833484 */
    3484 void MachineConfigFile::readSnapshot(const xml::ElementNode &elmSnapshot,
     3485void MachineConfigFile::readSnapshot(uint32_t depth,
     3486                                     const xml::ElementNode &elmSnapshot,
    34853487                                     Snapshot &snap)
    34863488{
     3489    if (depth > SETTINGS_SNAPSHOT_DEPTH_MAX)
     3490        throw ConfigFileError(this, &elmSnapshot, N_("Maximum snapshot tree depth of %u exceeded"), depth);
     3491
    34873492    Utf8Str strTemp;
    34883493
     
    35313536                if (pelmChildSnapshot->nameEquals("Snapshot"))
    35323537                {
    3533                     Snapshot child;
    3534                     readSnapshot(*pelmChildSnapshot, child);
    3535                     snap.llChildSnapshots.push_back(child);
     3538                    // Use the heap to reduce the stack footprint. Each
     3539                    // recursion needs over 1K, and there can be VMs with
     3540                    // deeply nested snapshots. The stack can be quite
     3541                    // small, especially with XPCOM.
     3542                    Snapshot *child = new Snapshot();
     3543                    readSnapshot(depth + 1, *pelmChildSnapshot, *child);
     3544                    snap.llChildSnapshots.push_back(*child);
     3545                    delete child;
    35363546                }
    35373547            }
     
    36703680                Snapshot snap;
    36713681                // this will recurse into child snapshots, if necessary
    3672                 readSnapshot(*pelmMachineChild, snap);
     3682                readSnapshot(1, *pelmMachineChild, snap);
    36733683                llFirstSnapshot.push_back(snap);
    36743684            }
     
    45514561             && (sc.controllerType == StorageControllerType_I82078)
    45524562           )
    4553             // floppy controller already got written into <Hardware>/<FloppyController> in writeHardware()
     4563            // floppy controller already got written into <Hardware>/<FloppyController> in buildHardwareXML()
    45544564            // for pre-1.9 settings
    45554565            continue;
     
    47514761 * for the root snapshot of a machine, if present; elmParent then points to the <Snapshots> node under the
    47524762 * <Machine> node to which <Snapshot> must be added. This may then recurse for child snapshots.
     4763 *
     4764 * @param depth
    47534765 * @param elmParent
    47544766 * @param snap
    47554767 */
    4756 void MachineConfigFile::buildSnapshotXML(xml::ElementNode &elmParent,
     4768void MachineConfigFile::buildSnapshotXML(uint32_t depth,
     4769                                         xml::ElementNode &elmParent,
    47574770                                         const Snapshot &snap)
    47584771{
     4772    if (depth > SETTINGS_SNAPSHOT_DEPTH_MAX)
     4773        throw ConfigFileError(this, NULL, N_("Maximum snapshot tree depth of %u exceeded"), SETTINGS_SNAPSHOT_DEPTH_MAX);
     4774
    47594775    xml::ElementNode *pelmSnapshot = elmParent.createChild("Snapshot");
    47604776
     
    47884804        {
    47894805            const Snapshot &child = *it;
    4790             buildSnapshotXML(*pelmChildren, child);
     4806            buildSnapshotXML(depth + 1, *pelmChildren, child);
    47914807        }
    47924808    }
     
    49254941    if (    (fl & BuildMachineXML_IncludeSnapshots)
    49264942         && llFirstSnapshot.size())
    4927         buildSnapshotXML(elmMachine, llFirstSnapshot.front());
     4943        buildSnapshotXML(1, elmMachine, llFirstSnapshot.front());
    49284944
    49294945    buildHardwareXML(elmMachine, hardwareMachine, storageMachine);
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette