2010/8/19 Eric Blake <eblake(a)redhat.com>:
Work in progress:
This gets 2 of the 5 suspect uses; I ran out of time today.
* src/vbox/vbox_tmpl.c (vboxStartMachine): Use virAsprintf instead.
---
I could check this in as is (after tweaking the commit comment)
and do the other three sprintf uses in another patch, but I'd
rather merge all sprintf changes in this file to a single commit.
At any rate, reviewing this portion for any memory leaks now will
be helpful.
src/vbox/vbox_tmpl.c | 19 ++++++++++++++-----
1 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index c28981c..6b9de6c 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -3162,7 +3162,6 @@ vboxStartMachine(virDomainPtr dom, int i, IMachine *machine,
vboxIID *iid
PRUnichar *valueDisplayUtf16 = NULL;
char *valueDisplayUtf8 = NULL;
IProgress *progress = NULL;
- char displayutf8[32] = {0};
PRUnichar *env = NULL;
PRUnichar *sessionType = NULL;
nsresult rc;
@@ -3242,8 +3241,13 @@ vboxStartMachine(virDomainPtr dom, int i, IMachine *machine,
vboxIID *iid
if (guiPresent) {
if (guiDisplay) {
- sprintf(displayutf8, "DISPLAY=%.24s", guiDisplay);
- VBOX_UTF8_TO_UTF16(displayutf8, &env);
+ char *displayutf8;
+ if (virAsprintf(&displayutf8, "DISPLAY=%s", guiDisplay) <
0)
+ virReportOOMError();
Why don't we abort the try to start the guest when hitting OOM?
Starting the guest will probably fail because of OOM anyway.
Also why switch to virAsprintf when snprintf would work too?
Matthias