diff options
author | Kinga Tanska <kinga.tanska@intel.com> | 2022-06-06 12:32:12 +0200 |
---|---|---|
committer | Jes Sorensen <jsorensen@fb.com> | 2022-06-14 16:36:03 +0200 |
commit | e702f392959d1c2ad2089e595b52235ed97b4e18 (patch) | |
tree | 8c7c640a9e700c970e1c51f1a0393f18843b81dc /mdopen.c | |
parent | Incremental: Fix possible memory and resource leaks (diff) | |
download | mdadm-e702f392959d1c2ad2089e595b52235ed97b4e18.tar.xz mdadm-e702f392959d1c2ad2089e595b52235ed97b4e18.zip |
Mdmonitor: Fix segfault
Mdadm with "--monitor" parameter requires md device
as an argument to be monitored. If given argument is
not a md device, error shall be returned. Previously
it was not checked and invalid argument caused
segmentation fault. This commit adds checking
that devices passed to mdmonitor are md devices.
Signed-off-by: Kinga Tanska <kinga.tanska@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
Diffstat (limited to 'mdopen.c')
-rw-r--r-- | mdopen.c | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -475,6 +475,23 @@ int open_mddev(char *dev, int report_errors) return mdfd; } +/** + * is_mddev() - check that file name passed is an md device. + * @dev: file name that has to be checked. + * Return: 1 if file passed is an md device, 0 if not. + */ +int is_mddev(char *dev) +{ + int fd = open_mddev(dev, 1); + + if (fd >= 0) { + close(fd); + return 1; + } + + return 0; +} + char *find_free_devnm(int use_partitions) { static char devnm[32]; |