diff options
author | Blazej Kucman <blazej.kucman@intel.com> | 2023-06-16 21:45:55 +0200 |
---|---|---|
committer | Jes Sorensen <jes@trained-monkey.org> | 2023-09-01 17:38:44 +0200 |
commit | 21e622f214a38c048c5689158bc6314a91a46e40 (patch) | |
tree | 1767839540cfe77cdf669686a81a6e010a561ce1 /mapfile.c | |
parent | imsm: fix free space calculations (diff) | |
download | mdadm-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.c | 3 |
1 files changed, 1 insertions, 2 deletions
@@ -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; } } |