From: Mark Andrews Date: Tue, 23 Jun 2020 07:00:43 +0000 (+1000) Subject: Resize unamebuf[] to avoid warnings about snprintf() not having X-Git-Tag: v9.17.3~39^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4bc3de070fc9c0bc4d8d15d207e0b1352cd20434;p=thirdparty%2Fbind9.git Resize unamebuf[] to avoid warnings about snprintf() not having enough buffer space. Also change named_os_uname() prototype so that it is now returning (const char *) rather than (char *). If uname() is not supported on a UNIX build prepopulate unamebuf[] with "unknown architecture". --- diff --git a/bin/named/unix/include/named/os.h b/bin/named/unix/include/named/os.h index 5e5d2b894fd..dd437cc45ea 100644 --- a/bin/named/unix/include/named/os.h +++ b/bin/named/unix/include/named/os.h @@ -73,7 +73,7 @@ named_os_tzset(void); void named_os_started(void); -char * +const char * named_os_uname(void); #endif /* NAMED_OS_H */ diff --git a/bin/named/unix/os.c b/bin/named/unix/os.c index 3c5b19d383c..6d37c699659 100644 --- a/bin/named/unix/os.c +++ b/bin/named/unix/os.c @@ -903,8 +903,12 @@ named_os_tzset(void) { #endif /* ifdef HAVE_TZSET */ } -static char unamebuf[BUFSIZ]; -static char *unamep = NULL; +#ifdef HAVE_UNAME +static char unamebuf[sizeof(struct utsname)]; +#else +static const char unamebuf[] = { "unknown architecture" }; +#endif +static const char *unamep = NULL; static void getuname(void) { @@ -919,13 +923,11 @@ getuname(void) { snprintf(unamebuf, sizeof(unamebuf), "%s %s %s %s", uts.sysname, uts.machine, uts.release, uts.version); -#else /* ifdef HAVE_UNAME */ - snprintf(unamebuf, sizeof(unamebuf), "unknown architecture"); #endif /* ifdef HAVE_UNAME */ unamep = unamebuf; } -char * +const char * named_os_uname(void) { if (unamep == NULL) { getuname(); diff --git a/bin/named/win32/include/named/os.h b/bin/named/win32/include/named/os.h index c177bf4adcc..4af96316cc7 100644 --- a/bin/named/win32/include/named/os.h +++ b/bin/named/win32/include/named/os.h @@ -70,7 +70,7 @@ named_os_tzset(void); void named_os_started(void); -char * +const char * named_os_uname(void); #endif /* NAMED_OS_H */ diff --git a/bin/named/win32/os.c b/bin/named/win32/os.c index a7edacaf535..3df95e773d0 100644 --- a/bin/named/win32/os.c +++ b/bin/named/win32/os.c @@ -393,7 +393,7 @@ named_os_started(void) { } static char unamebuf[BUFSIZ]; -static char *unamep = NULL; +static const char *unamep = NULL; static void getuname(void) { @@ -462,7 +462,7 @@ err: * GetVersionEx() returns 6.2 (aka Windows 8.1) since it was obsoleted * so we had to switch to the recommended way to get the Windows version. */ -char * +const char * named_os_uname(void) { if (unamep == NULL) { getuname();