linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mdadm/Monitor:triggers core dump when stat2devnm return NULL
@ 2017-03-20  5:21 Zhilong Liu
  2017-03-27 22:25 ` jes.sorensen
  0 siblings, 1 reply; 2+ messages in thread
From: Zhilong Liu @ 2017-03-20  5:21 UTC (permalink / raw)
  To: jes.sorensen; +Cc: linux-raid, Zhilong Liu

Monitor: ensure that the device should be a block
device when uses --wait parameter, such as the 'f'
and 'd' type file would be triggered core dumped.
such as: ./mdadm --wait /dev/md/

Reviewed-by: NeilBrown <neilb@suse.com>
Signed-off-by: Zhilong Liu <zlliu@suse.com>
---
 Monitor.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/Monitor.c b/Monitor.c
index 802a9d9..f8850d3 100644
--- a/Monitor.c
+++ b/Monitor.c
@@ -1002,7 +1002,12 @@ int Wait(char *dev)
 			strerror(errno));
 		return 2;
 	}
-	strcpy(devnm, stat2devnm(&stb));
+	char *tmp = stat2devnm(&stb);
+	if (!tmp) {
+		pr_err("%s is not a block device.\n", dev);
+		return 2;
+	}
+	strcpy(devnm, tmp);
 
 	while(1) {
 		struct mdstat_ent *ms = mdstat_read(1, 0);
-- 
2.6.6


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] mdadm/Monitor:triggers core dump when stat2devnm return NULL
  2017-03-20  5:21 [PATCH] mdadm/Monitor:triggers core dump when stat2devnm return NULL Zhilong Liu
@ 2017-03-27 22:25 ` jes.sorensen
  0 siblings, 0 replies; 2+ messages in thread
From: jes.sorensen @ 2017-03-27 22:25 UTC (permalink / raw)
  To: Zhilong Liu; +Cc: linux-raid

Zhilong Liu <zlliu@suse.com> writes:
> Monitor: ensure that the device should be a block
> device when uses --wait parameter, such as the 'f'
> and 'd' type file would be triggered core dumped.
> such as: ./mdadm --wait /dev/md/

I modified the patch description here to make it easier to read.

> Reviewed-by: NeilBrown <neilb@suse.com>
> Signed-off-by: Zhilong Liu <zlliu@suse.com>
> ---
>  Monitor.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/Monitor.c b/Monitor.c
> index 802a9d9..f8850d3 100644
> --- a/Monitor.c
> +++ b/Monitor.c
> @@ -1002,7 +1002,12 @@ int Wait(char *dev)
>  			strerror(errno));
>  		return 2;
>  	}
> -	strcpy(devnm, stat2devnm(&stb));
> +	char *tmp = stat2devnm(&stb);

Please do not declare variables in the middle of the codeflow, that is
extremely bad programming practice.

I fixed this up and applied the patch.

Thanks,
Jes

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-03-27 22:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-20  5:21 [PATCH] mdadm/Monitor:triggers core dump when stat2devnm return NULL Zhilong Liu
2017-03-27 22:25 ` jes.sorensen

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).