diff mbox

[v5,10/10] block/vvfat: fix setbuf stream parameter may be NULL

Message ID 1407747189-7936-11-git-send-email-zhang.zhanghailiang@huawei.com
State New
Headers show

Commit Message

Zhanghailiang Aug. 11, 2014, 8:53 a.m. UTC
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 | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Stefan Hajnoczi Sept. 8, 2014, 8:37 a.m. UTC | #1
On Mon, Aug 11, 2014 at 04:53:09PM +0800, zhanghailiang 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 | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/block/vvfat.c b/block/vvfat.c
> index 70176b1..6889ea9 100644
> --- a/block/vvfat.c
> +++ b/block/vvfat.c
> @@ -1084,7 +1084,10 @@ static int vvfat_open(BlockDriverState *bs, QDict *options, int flags,
>  
>  DLOG(if (stderr == NULL) {
>      stderr = fopen("vvfat.log", "a");
> -    setbuf(stderr, NULL);
> +
> +    if (stderr) {
> +        setbuf(stderr, NULL);
> +    }
>  })
>  
>      opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);

This no longer exists:

commit 13b552c2f43298a42e26d7aec7b58a5c205b75a0
Author: Michael Tokarev <mjt@tls.msk.ru>
Date:   Wed Aug 20 19:02:38 2014 +0400

    block/vvfat.c: remove debugging code to reinit stderr if NULL
    
    Just log to stderr unconditionally, like other similar code does.
    
    Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
    Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
    Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Michael Tokarev Sept. 8, 2014, 10:57 a.m. UTC | #2
08.09.2014 12:37, Stefan Hajnoczi wrote:
> On Mon, Aug 11, 2014 at 04:53:09PM +0800, zhanghailiang wrote:
>> From: Li Liu <john.liuli@huawei.com>
>>
>> fopen() may return NULL which will cause setbuf() segmentfault
[]
> This no longer exists:
> 
> commit 13b552c2f43298a42e26d7aec7b58a5c205b75a0
> Author: Michael Tokarev <mjt@tls.msk.ru>
> Date:   Wed Aug 20 19:02:38 2014 +0400
> 
>     block/vvfat.c: remove debugging code to reinit stderr if NULL

The second patch is a result of discussion emerged after first patch,
consider the commit to be a follow-up for the initial patch :)

Thanks,

/mjt
diff mbox

Patch

diff --git a/block/vvfat.c b/block/vvfat.c
index 70176b1..6889ea9 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -1084,7 +1084,10 @@  static int vvfat_open(BlockDriverState *bs, QDict *options, int flags,
 
 DLOG(if (stderr == NULL) {
     stderr = fopen("vvfat.log", "a");
-    setbuf(stderr, NULL);
+
+    if (stderr) {
+        setbuf(stderr, NULL);
+    }
 })
 
     opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);