From 21e622f214a38c048c5689158bc6314a91a46e40 Mon Sep 17 00:00:00 2001 From: Blazej Kucman Date: Fri, 16 Jun 2023 21:45:55 +0200 Subject: 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 Signed-off-by: Jes Sorensen --- mapfile.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'mapfile.c') 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, "")==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; } } -- cgit v1.2.3