summaryrefslogtreecommitdiffstats
path: root/mdadm.c
diff options
context:
space:
mode:
authorBlazej Kucman <blazej.kucman@intel.com>2023-06-16 21:45:55 +0200
committerJes Sorensen <jes@trained-monkey.org>2023-09-01 17:38:44 +0200
commit21e622f214a38c048c5689158bc6314a91a46e40 (patch)
tree1767839540cfe77cdf669686a81a6e010a561ce1 /mdadm.c
parentimsm: fix free space calculations (diff)
downloadmdadm-21e622f214a38c048c5689158bc6314a91a46e40.tar.xz
mdadm-21e622f214a38c048c5689158bc6314a91a46e40.zip
Add secure gethostname() wrapper
gethostname() func does not ensure null-terminated string if hostname is longer than buffer length. For security, a function s_gethostname() has been added to ensure that "\0" is added to the end of the buffer. Previously this had to be handled in each place of the gethostname() call. Signed-off-by: Blazej Kucman <blazej.kucman@intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
Diffstat (limited to 'mdadm.c')
-rw-r--r--mdadm.c3
1 files changed, 1 insertions, 2 deletions
diff --git a/mdadm.c b/mdadm.c
index 076b45e0..e32598cb 100644
--- a/mdadm.c
+++ b/mdadm.c
@@ -1340,8 +1340,7 @@ int main(int argc, char *argv[])
if (c.homehost == NULL && c.require_homehost)
c.homehost = conf_get_homehost(&c.require_homehost);
if (c.homehost == NULL || strcasecmp(c.homehost, "<system>") == 0) {
- if (gethostname(sys_hostname, sizeof(sys_hostname)) == 0) {
- sys_hostname[sizeof(sys_hostname)-1] = 0;
+ if (s_gethostname(sys_hostname, sizeof(sys_hostname)) == 0) {
c.homehost = sys_hostname;
}
}