summaryrefslogtreecommitdiffstats
path: root/mapfile.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 /mapfile.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 'mapfile.c')
-rw-r--r--mapfile.c3
1 files changed, 1 insertions, 2 deletions
diff --git a/mapfile.c b/mapfile.c
index 34fea179..f1f3ee2c 100644
--- a/mapfile.c
+++ b/mapfile.c
@@ -363,8 +363,7 @@ void RebuildMap(void)
char *homehost = conf_get_homehost(&require_homehost);
if (homehost == NULL || strcmp(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) {
homehost = sys_hostname;
}
}