mdmon: fix fd leak and possible buffer overrun.
We normally wouldn't close 'fd', and as 'buf' might not have had a nul, strstr could have overrun it. Signed-off-by: NeilBrown <neilb@suse.de>
This commit is contained in:
parent
0c8675cbed
commit
417a4b046d
10
mdmon.c
10
mdmon.c
|
@ -180,6 +180,7 @@ static void try_kill_monitor(pid_t pid, char *devname, int sock)
|
||||||
char buf[100];
|
char buf[100];
|
||||||
int fd;
|
int fd;
|
||||||
struct mdstat_ent *mdstat;
|
struct mdstat_ent *mdstat;
|
||||||
|
int n;
|
||||||
|
|
||||||
/* first rule of survival... don't off yourself */
|
/* first rule of survival... don't off yourself */
|
||||||
if (pid == getpid())
|
if (pid == getpid())
|
||||||
|
@ -191,12 +192,11 @@ static void try_kill_monitor(pid_t pid, char *devname, int sock)
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (read(fd, buf, sizeof(buf)) < 0) {
|
n = read(fd, buf, sizeof(buf)-1);
|
||||||
close(fd);
|
buf[sizeof(buf)-1] = 0;
|
||||||
return;
|
close(fd);
|
||||||
}
|
|
||||||
|
|
||||||
if (!strstr(buf, "mdmon"))
|
if (n < 0 || !strstr(buf, "mdmon"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
kill(pid, SIGTERM);
|
kill(pid, SIGTERM);
|
||||||
|
|
Loading…
Reference in New Issue