[libvirt] [PATCH] snapshot: require user to supply external memory file name

For disk snapshots, the user could request an external snapshot but not supply a filename; later on, we would check this condition and generate a suitable name if possible, or gracefully error out when not possible (such as when the original file was a block device). But unless we come up with a suitable way to generate external memory file names, we have no later code point that was checking for NULL, so we should forbid this up front. * src/conf/snapshot_conf.c (virDomainSnapshotDefParseString): Avoid NULL deref, since we don't generate names yet. --- src/conf/snapshot_conf.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index 1ee4017..72bdd30 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -293,6 +293,12 @@ virDomainSnapshotDefParseString(const char *xmlStr, memoryFile); goto cleanup; } + if (!memoryFile && + def->memory == VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("external memory snapshots require a filename")); + goto cleanup; + } } else if (memoryFile) { def->memory = VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL; } else if (flags & VIR_DOMAIN_SNAPSHOT_PARSE_REDEFINE) { -- 1.7.11.7

On 2012年11月16日 08:49, Eric Blake wrote:
For disk snapshots, the user could request an external snapshot but not supply a filename; later on, we would check this condition and generate a suitable name if possible, or gracefully error out when not possible (such as when the original file was a block device). But unless we come up with a suitable way to generate external memory file names, we have no later code point that was checking for NULL, so we should forbid this up front.
* src/conf/snapshot_conf.c (virDomainSnapshotDefParseString): Avoid NULL deref, since we don't generate names yet. --- src/conf/snapshot_conf.c | 6 ++++++ 1 file changed, 6 insertions(+)
diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index 1ee4017..72bdd30 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -293,6 +293,12 @@ virDomainSnapshotDefParseString(const char *xmlStr, memoryFile); goto cleanup; } + if (!memoryFile&& + def->memory == VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("external memory snapshots require a filename")); + goto cleanup; + } } else if (memoryFile) { def->memory = VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL; } else if (flags& VIR_DOMAIN_SNAPSHOT_PARSE_REDEFINE) {
ACK.

On 11/15/2012 09:53 PM, Osier Yang wrote:
On 2012年11月16日 08:49, Eric Blake wrote:
For disk snapshots, the user could request an external snapshot but not supply a filename; later on, we would check this condition and generate a suitable name if possible, or gracefully error out when not possible (such as when the original file was a block device). But unless we come up with a suitable way to generate external memory file names, we have no later code point that was checking for NULL, so we should forbid this up front.
* src/conf/snapshot_conf.c (virDomainSnapshotDefParseString): Avoid NULL deref, since we don't generate names yet. --- src/conf/snapshot_conf.c | 6 ++++++ 1 file changed, 6 insertions(+)
ACK.
Thanks; pushed. -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
participants (2)
-
Eric Blake
-
Osier Yang