All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Tokarev <mjt@tls.msk.ru>
To: Peter Maydell <peter.maydell@linaro.org>,
	 zhanghailiang <zhang.zhanghailiang@huawei.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
	QEMU Trivial <qemu-trivial@nongnu.org>,
	Li Liu <john.liuli@huawei.com>,
	Luonengjun <luonengjun@huawei.com>,
	QEMU Developers <qemu-devel@nongnu.org>,
	peter.huangpeng@huawei.com, Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [Qemu-trivial] [Qemu-devel] [PATCH v7] block/vvfat: assert return value of fopen which may fail
Date: Mon, 18 Aug 2014 15:42:22 +0400	[thread overview]
Message-ID: <53F1E69E.6030103@msgid.tls.msk.ru> (raw)
In-Reply-To: <CAFEAcA8r51UaT4bety0h3tTjMmyvb2UwZj6scuTLZUBBYJkxVw@mail.gmail.com>

18.08.2014 12:06, Peter Maydell wrote:
> On 18 August 2014 09:00, zhanghailiang <zhang.zhanghailiang@huawei.com> wrote:
>> From: Li Liu <john.liuli@huawei.com>
>>
>> fopen() may return NULL which will cause setbuf() segmentfault
>>
>> Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
>> Signed-off-by: Li Liu <john.liuli@huawei.com>
>> ---
>>  block/vvfat.c | 1 +
>>  1 file changed, 1 insertion(+)
>>
>> diff --git a/block/vvfat.c b/block/vvfat.c
>> index 70176b1..62023e1 100644
>> --- a/block/vvfat.c
>> +++ b/block/vvfat.c
>> @@ -1084,6 +1084,7 @@ static int vvfat_open(BlockDriverState *bs, QDict *options, int flags,
>>
>>  DLOG(if (stderr == NULL) {
>>      stderr = fopen("vvfat.log", "a");
>> +    assert(stderr);
>>      setbuf(stderr, NULL);
>>  })
> 
> An assertion is no better than a segfault.
> 
> Better I think would be to just remove this whole lump of code
> entirely. Lots of other files do debug printing to stderr without
> attempting to open a file if stderr happens to be NULL, why
> should vvfat.c be special?

Indeed.  I've applied a patch which just removes these 6 lines of code
(and sent it to the list too, for review).

Thanks,

/mjt


WARNING: multiple messages have this Message-ID (diff)
From: Michael Tokarev <mjt@tls.msk.ru>
To: Peter Maydell <peter.maydell@linaro.org>,
	zhanghailiang <zhang.zhanghailiang@huawei.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
	QEMU Trivial <qemu-trivial@nongnu.org>,
	Li Liu <john.liuli@huawei.com>,
	Luonengjun <luonengjun@huawei.com>,
	QEMU Developers <qemu-devel@nongnu.org>,
	peter.huangpeng@huawei.com, Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [Qemu-devel] [Qemu-trivial] [PATCH v7] block/vvfat: assert return value of fopen which may fail
Date: Mon, 18 Aug 2014 15:42:22 +0400	[thread overview]
Message-ID: <53F1E69E.6030103@msgid.tls.msk.ru> (raw)
In-Reply-To: <CAFEAcA8r51UaT4bety0h3tTjMmyvb2UwZj6scuTLZUBBYJkxVw@mail.gmail.com>

18.08.2014 12:06, Peter Maydell wrote:
> On 18 August 2014 09:00, zhanghailiang <zhang.zhanghailiang@huawei.com> wrote:
>> From: Li Liu <john.liuli@huawei.com>
>>
>> fopen() may return NULL which will cause setbuf() segmentfault
>>
>> Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
>> Signed-off-by: Li Liu <john.liuli@huawei.com>
>> ---
>>  block/vvfat.c | 1 +
>>  1 file changed, 1 insertion(+)
>>
>> diff --git a/block/vvfat.c b/block/vvfat.c
>> index 70176b1..62023e1 100644
>> --- a/block/vvfat.c
>> +++ b/block/vvfat.c
>> @@ -1084,6 +1084,7 @@ static int vvfat_open(BlockDriverState *bs, QDict *options, int flags,
>>
>>  DLOG(if (stderr == NULL) {
>>      stderr = fopen("vvfat.log", "a");
>> +    assert(stderr);
>>      setbuf(stderr, NULL);
>>  })
> 
> An assertion is no better than a segfault.
> 
> Better I think would be to just remove this whole lump of code
> entirely. Lots of other files do debug printing to stderr without
> attempting to open a file if stderr happens to be NULL, why
> should vvfat.c be special?

Indeed.  I've applied a patch which just removes these 6 lines of code
(and sent it to the list too, for review).

Thanks,

/mjt

  reply	other threads:[~2014-08-18 11:42 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-18  8:00 [Qemu-trivial] [PATCH v7] block/vvfat: assert return value of fopen which may fail zhanghailiang
2014-08-18  8:00 ` [Qemu-devel] " zhanghailiang
2014-08-18  8:06 ` [Qemu-trivial] " Peter Maydell
2014-08-18  8:06   ` Peter Maydell
2014-08-18 11:42   ` Michael Tokarev [this message]
2014-08-18 11:42     ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
2014-08-19  6:28     ` [Qemu-trivial] [Qemu-devel] " zhanghailiang
2014-08-19  6:28       ` [Qemu-devel] [Qemu-trivial] " zhanghailiang

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=53F1E69E.6030103@msgid.tls.msk.ru \
    --to=mjt@tls.msk.ru \
    --cc=john.liuli@huawei.com \
    --cc=kwolf@redhat.com \
    --cc=luonengjun@huawei.com \
    --cc=peter.huangpeng@huawei.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=zhang.zhanghailiang@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.