From: Jim Meyering <jim@meyering.net>
To: qemu-devel@nongnu.org
Cc: Jim Meyering <meyering@redhat.com>
Subject: [Qemu-devel] [PATCHv3 5/5] softmmu-semi: fix lock_user* functions not to deref NULL upon OOM
Date: Wed, 22 Aug 2012 13:55:56 +0200 [thread overview]
Message-ID: <1345636556-29008-6-git-send-email-jim@meyering.net> (raw)
In-Reply-To: <1345636556-29008-1-git-send-email-jim@meyering.net>
From: Jim Meyering <meyering@redhat.com>
Return NULL upon malloc failure.
Signed-off-by: Jim Meyering <meyering@redhat.com>
---
softmmu-semi.h | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/softmmu-semi.h b/softmmu-semi.h
index 648cb95..bcb979a 100644
--- a/softmmu-semi.h
+++ b/softmmu-semi.h
@@ -40,7 +40,7 @@ static void *softmmu_lock_user(CPUArchState *env, uint32_t addr, uint32_t len,
uint8_t *p;
/* TODO: Make this something that isn't fixed size. */
p = malloc(len);
- if (copy)
+ if (p && copy)
cpu_memory_rw_debug(env, addr, p, len, 0);
return p;
}
@@ -52,6 +52,9 @@ static char *softmmu_lock_user_string(CPUArchState *env, uint32_t addr)
uint8_t c;
/* TODO: Make this something that isn't fixed size. */
s = p = malloc(1024);
+ if (!s) {
+ return NULL;
+ }
do {
cpu_memory_rw_debug(env, addr, &c, 1, 0);
addr++;
--
1.7.12
prev parent reply other threads:[~2012-08-22 11:57 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-22 11:55 [Qemu-devel] [PATCHv3 0/5] plug memory and file-descriptor leaks Jim Meyering
2012-08-22 11:55 ` [Qemu-devel] [PATCHv3 1/5] qemu-ga: don't leak a file descriptor upon failed lockf Jim Meyering
2012-08-22 11:55 ` [Qemu-devel] [PATCHv3 2/5] linux-user: do_msgrcv: don't leak host_mb upon TARGET_EFAULT failure Jim Meyering
2012-08-22 11:55 ` [Qemu-devel] [PATCHv3 3/5] sheepdog: don't leak socket file descriptor upon connection failure Jim Meyering
2012-08-22 11:55 ` [Qemu-devel] [PATCHv3 4/5] arm-semi: don't leak 1KB user string lock buffer upon TARGET_SYS_OPEN Jim Meyering
2012-08-22 11:55 ` Jim Meyering [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1345636556-29008-6-git-send-email-jim@meyering.net \
--to=jim@meyering.net \
--cc=meyering@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).