[PATCH 4/4] virtiofsd: do_read missing NULL check

Dr. David Alan Gilbert (git) posted 4 patches 6 years ago
Maintainers: Stefan Hajnoczi <stefanha@redhat.com>, "Dr. David Alan Gilbert" <dgilbert@redhat.com>
[PATCH 4/4] virtiofsd: do_read missing NULL check
Posted by Dr. David Alan Gilbert (git) 6 years ago
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>

Missing a NULL check if the argument fetch fails.

Fixes: Coverity CID 1413119
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
---
 tools/virtiofsd/fuse_lowlevel.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tools/virtiofsd/fuse_lowlevel.c b/tools/virtiofsd/fuse_lowlevel.c
index 01c418aade..704c0369b2 100644
--- a/tools/virtiofsd/fuse_lowlevel.c
+++ b/tools/virtiofsd/fuse_lowlevel.c
@@ -1116,6 +1116,10 @@ static void do_read(fuse_req_t req, fuse_ino_t nodeid,
         struct fuse_file_info fi;
 
         arg = fuse_mbuf_iter_advance(iter, sizeof(*arg));
+        if (!arg) {
+            fuse_reply_err(req, EINVAL);
+            return;
+        }
 
         memset(&fi, 0, sizeof(fi));
         fi.fh = arg->fh;
-- 
2.24.1


Re: [PATCH 4/4] virtiofsd: do_read missing NULL check
Posted by Philippe Mathieu-Daudé 6 years ago
On 2/4/20 12:05 PM, Dr. David Alan Gilbert (git) wrote:
> From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
> 
> Missing a NULL check if the argument fetch fails.

Surprisingly all other calls to fuse_mbuf_iter_advance() do the check.

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> 
> Fixes: Coverity CID 1413119
> Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> ---
>   tools/virtiofsd/fuse_lowlevel.c | 4 ++++
>   1 file changed, 4 insertions(+)
> 
> diff --git a/tools/virtiofsd/fuse_lowlevel.c b/tools/virtiofsd/fuse_lowlevel.c
> index 01c418aade..704c0369b2 100644
> --- a/tools/virtiofsd/fuse_lowlevel.c
> +++ b/tools/virtiofsd/fuse_lowlevel.c
> @@ -1116,6 +1116,10 @@ static void do_read(fuse_req_t req, fuse_ino_t nodeid,
>           struct fuse_file_info fi;
>   
>           arg = fuse_mbuf_iter_advance(iter, sizeof(*arg));
> +        if (!arg) {
> +            fuse_reply_err(req, EINVAL);
> +            return;
> +        }
>   
>           memset(&fi, 0, sizeof(fi));
>           fi.fh = arg->fh;
>