From: Fam Zheng <famz@redhat.com>
To: Jie Wang <wangjie88@huawei.com>
Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org,
stefanha@redhat.com, eblake@redhat.com, eric.fangyi@huawei.com,
wu.wubin@huawei.com
Subject: Re: [Qemu-devel] [PATCH] util/async: avoid NULL pointer dereference
Date: Mon, 11 Jun 2018 17:29:31 +0800 [thread overview]
Message-ID: <20180611092931.GA25583@lemon.usersys.redhat.com> (raw)
In-Reply-To: <1528700647-58638-1-git-send-email-wangjie88@huawei.com>
On Mon, 06/11 15:04, Jie Wang wrote:
> if laio_init create linux_aio failed and return NULL, NULL pointer
> dereference will occur when laio_attach_aio_context dereference
> linux_aio in aio_get_linux_aio, so add assert to avoid it.
>
> Signed-off-by: Jie Wang <wangjie88@huawei.com>
> ---
> util/async.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/util/async.c b/util/async.c
> index 03f62787f2..7766bcd8bc 100644
> --- a/util/async.c
> +++ b/util/async.c
> @@ -327,6 +327,7 @@ LinuxAioState *aio_get_linux_aio(AioContext *ctx)
> {
> if (!ctx->linux_aio) {
> ctx->linux_aio = laio_init();
> + assert(ctx->linux_aio);
> laio_attach_aio_context(ctx->linux_aio, ctx);
> }
> return ctx->linux_aio;
> --
I'm afraid this is not the correct fix. If laio_init() can fail, this function
should skip laio_attach_aio_context() and return NULL, then callers should check
the return value and handle the error. E.g. Set s->use_linux_aio to false and
fall back to posix I/O, and perhaps report the error with error_report. Or even
better, call laio_init during raw_open and use error_setg(errp, ...).
assert() will simply crash the program, it is not the right way to catch errors.
Fam
prev parent reply other threads:[~2018-06-11 9:29 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-11 7:04 [Qemu-devel] [PATCH] util/async: avoid NULL pointer dereference Jie Wang
2018-06-11 9:29 ` Fam Zheng [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=20180611092931.GA25583@lemon.usersys.redhat.com \
--to=famz@redhat.com \
--cc=eblake@redhat.com \
--cc=eric.fangyi@huawei.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=wangjie88@huawei.com \
--cc=wu.wubin@huawei.com \
/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).