From: Martin Wilck <mwilck@suse.com>
To: Bart Van Assche <bart.vanassche@wdc.com>,
Christophe Varoqui <christophe.varoqui@opensvc.com>
Cc: dm-devel@redhat.com
Subject: Re: [PATCH 4/6] kpartx: Improve reliability of find_loop_by_file()
Date: Mon, 05 Mar 2018 19:38:57 +0100 [thread overview]
Message-ID: <1520275137.7660.39.camel@suse.com> (raw)
In-Reply-To: <20180301192935.14643-5-bart.vanassche@wdc.com>
On Thu, 2018-03-01 at 11:29 -0800, Bart Van Assche wrote:
> Avoid that the strchr() call in this function examines uninitialized
> data on the stack. This patch avoids that Coverity reports the
> following:
>
> CID 173252: Error handling issues (CHECKED_RETURN)
> "read(int, void *, size_t)" returns the number of bytes read, but
> it is ignored.
>
> Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
Reviewed-by: Martin Wilck <mwilck@suse.com>
> ---
> kpartx/lopart.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/kpartx/lopart.c b/kpartx/lopart.c
> index 02b29e8cf91d..69c1eda1cc5c 100644
> --- a/kpartx/lopart.c
> +++ b/kpartx/lopart.c
> @@ -64,7 +64,7 @@ char *find_loop_by_file(const char *filename)
> DIR *dir;
> struct dirent *dent;
> char dev[64], *found = NULL, *p;
> - int fd;
> + int fd, bytes_read;
> struct stat statbuf;
> struct loop_info loopinfo;
> const char VIRT_BLOCK[] = "/sys/devices/virtual/block";
> @@ -86,14 +86,15 @@ char *find_loop_by_file(const char *filename)
> if (fd < 0)
> continue;
>
> - if (read(fd, dev, sizeof(dev)) <= 0) {
> + bytes_read = read(fd, dev, sizeof(dev) - 1);
> + if (bytes_read <= 0) {
> close(fd);
> continue;
> }
>
> close(fd);
>
> - dev[sizeof(dev)-1] = '\0';
> + dev[bytes_read] = '\0';
> p = strchr(dev, '\n');
> if (p != NULL)
> *p = '\0';
--
Dr. Martin Wilck <mwilck@suse.com>, Tel. +49 (0)911 74053 2107
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
next prev parent reply other threads:[~2018-03-05 18:38 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-01 19:29 [PATCH 0/6] Various multipath-tools patches Bart Van Assche
2018-03-01 19:29 ` [PATCH 1/6] multipathd/main.c: Fix indentation Bart Van Assche
2018-03-05 16:09 ` Martin Wilck
2018-03-01 19:29 ` [PATCH 2/6] libmultipath, alloc_path_with_pathinfo(): Ensure that pp->wwid is '\0'-terminated Bart Van Assche
2018-03-05 16:11 ` Martin Wilck
2018-03-01 19:29 ` [PATCH 3/6] libmultipath, alloc_path_with_pathinfo(): Declare third argument const Bart Van Assche
2018-03-05 16:18 ` Martin Wilck
2018-03-05 16:21 ` Bart Van Assche
2018-03-01 19:29 ` [PATCH 4/6] kpartx: Improve reliability of find_loop_by_file() Bart Van Assche
2018-03-05 18:38 ` Martin Wilck [this message]
2018-03-01 19:29 ` [PATCH 5/6] libmultipath: Fix sgio_get_vpd() Bart Van Assche
2018-03-05 16:53 ` Martin Wilck
2018-03-05 17:09 ` Martin Wilck
2018-03-05 19:14 ` Martin Wilck
2018-03-05 19:18 ` Bart Van Assche
2018-03-05 20:47 ` Martin Wilck
2018-03-05 21:13 ` Bart Van Assche
2018-03-05 23:24 ` Martin Wilck
2018-03-05 23:35 ` Martin Wilck
2018-03-01 19:29 ` [PATCH 6/6] Introduce the ibmultipath/unaligned.h header file Bart Van Assche
2018-03-05 17:18 ` Martin Wilck
2018-03-06 15:25 ` [PATCH 0/6] Various multipath-tools patches Benjamin Marzinski
2018-03-07 9:56 ` Christophe Varoqui
2018-03-08 20:39 ` Bart Van Assche
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=1520275137.7660.39.camel@suse.com \
--to=mwilck@suse.com \
--cc=bart.vanassche@wdc.com \
--cc=christophe.varoqui@opensvc.com \
--cc=dm-devel@redhat.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.