From: Peter Krempa Date: Wed, 24 Feb 2021 09:20:55 +0000 (+0100) Subject: vbox: abort() on allocation failure in UTF8<->UTF16 conversion X-Git-Tag: v7.2.0-rc1~274 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3fdf0013e59fa1b5f9630b3501eef9d38d6c9d5b;p=thirdparty%2Flibvirt.git vbox: abort() on allocation failure in UTF8<->UTF16 conversion Trying to report an error on OOM is pointless since error handling allocates memory. Signed-off-by: Peter Krempa Reviewed-by: Laine Stump --- diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 0c4126bd38..69b99317f2 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -5465,17 +5465,9 @@ vboxDomainSnapshotCreateXML(virDomainPtr dom, } VBOX_UTF8_TO_UTF16(def->parent.name, &name); - if (!name) { - virReportOOMError(); - goto cleanup; - } if (def->parent.description) { VBOX_UTF8_TO_UTF16(def->parent.description, &description); - if (!description) { - virReportOOMError(); - goto cleanup; - } } rc = gVBoxAPI.UIConsole.TakeSnapshot(console, name, description, &progress); @@ -6475,10 +6467,6 @@ vboxDomainSnapshotGetParent(virDomainSnapshotPtr snapshot, goto cleanup; } VBOX_UTF16_TO_UTF8(nameUtf16, &name); - if (!name) { - virReportOOMError(); - goto cleanup; - } ret = virGetDomainSnapshot(dom, name); @@ -6533,10 +6521,6 @@ vboxDomainSnapshotCurrent(virDomainPtr dom, unsigned int flags) } VBOX_UTF16_TO_UTF8(nameUtf16, &name); - if (!name) { - virReportOOMError(); - goto cleanup; - } ret = virGetDomainSnapshot(dom, name); @@ -6593,10 +6577,6 @@ static int vboxDomainSnapshotIsCurrent(virDomainSnapshotPtr snapshot, } VBOX_UTF16_TO_UTF8(nameUtf16, &name); - if (!name) { - virReportOOMError(); - goto cleanup; - } ret = STREQ(snapshot->name, name); diff --git a/src/vbox/vbox_common.h b/src/vbox/vbox_common.h index 8b1fb2ac30..1fb922aaf0 100644 --- a/src/vbox/vbox_common.h +++ b/src/vbox/vbox_common.h @@ -391,8 +391,19 @@ typedef nsISupports IKeyboard; } \ } while (0) -#define VBOX_UTF16_TO_UTF8(arg1, arg2) gVBoxAPI.UPFN.Utf16ToUtf8(data->pFuncs, arg1, arg2) -#define VBOX_UTF8_TO_UTF16(arg1, arg2) gVBoxAPI.UPFN.Utf8ToUtf16(data->pFuncs, arg1, arg2) +#define VBOX_UTF16_TO_UTF8(arg1, arg2) \ + do { \ + gVBoxAPI.UPFN.Utf16ToUtf8(data->pFuncs, arg1, arg2); \ + if (!*(arg2)) \ + abort(); \ + } while (0) + +#define VBOX_UTF8_TO_UTF16(arg1, arg2) \ + do { \ + gVBoxAPI.UPFN.Utf8ToUtf16(data->pFuncs, arg1, arg2); \ + if (!*(arg2)) \ + abort(); \ + } while (0) #define VBOX_ADDREF(arg) gVBoxAPI.nsUISupports.AddRef((void *)(arg))