]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Resize unamebuf[] to avoid warnings about snprintf() not having
authorMark Andrews <marka@isc.org>
Tue, 23 Jun 2020 07:00:43 +0000 (17:00 +1000)
committerMark Andrews <marka@isc.org>
Wed, 24 Jun 2020 23:32:02 +0000 (09:32 +1000)
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".

(cherry picked from commit 4bc3de070fc9c0bc4d8d15d207e0b1352cd20434)

bin/named/unix/include/named/os.h
bin/named/unix/os.c
bin/named/win32/include/named/os.h
bin/named/win32/os.c

index 5415b83b051da0c4a8c3ba46d9d2b6ec8c21a8bb..15b43d10c7b875c314493db9d9209c3c0a196327 100644 (file)
@@ -73,7 +73,7 @@ ns_os_tzset(void);
 void
 ns_os_started(void);
 
-char *
+const char *
 ns_os_uname(void);
 
 #endif /* NS_OS_H */
index 150492ffc9a003fa05c65b53065174e64ae595c7..50c8097d2e991c0a24a831a233150f279d3f7094 100644 (file)
@@ -1089,8 +1089,12 @@ ns_os_tzset(void) {
 #endif
 }
 
-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) {
@@ -1103,18 +1107,16 @@ getuname(void) {
                return;
        }
 
-       snprintf(unamebuf, sizeof(unamebuf),
-                "%s %s %s %s",
-                uts.sysname, uts.machine, uts.release, uts.version);
-#else
-       snprintf(unamebuf, sizeof(unamebuf), "unknown architecture");
-#endif
+       snprintf(unamebuf, sizeof(unamebuf), "%s %s %s %s", uts.sysname,
+                uts.machine, uts.release, uts.version);
+#endif /* ifdef HAVE_UNAME */
        unamep = unamebuf;
 }
 
-char *
+const char *
 ns_os_uname(void) {
-       if (unamep == NULL)
+       if (unamep == NULL) {
                getuname();
+       }
        return (unamep);
 }
index cac89a48b29c18b2ca88468c7cd450af326c856a..e478151f11bf660689e4759611b36a63d0860af6 100644 (file)
@@ -70,7 +70,7 @@ ns_os_tzset(void);
 void
 ns_os_started(void);
 
-char *
+const char *
 ns_os_uname(void);
 
 #endif /* NS_OS_H */
index 34be311b661df5a17c1a275cf2d554c236d873d3..e878d2a678fcf11b5df10ea9c7967fd8c0046bb2 100644 (file)
@@ -392,7 +392,7 @@ ns_os_started(void) {
 }
 
 static char unamebuf[BUFSIZ];
-static char *unamep = NULL;
+static const char *unamep = NULL;
 
 static void
 getuname(void) {
@@ -461,9 +461,10 @@ getuname(void) {
  * 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 *
 ns_os_uname(void) {
-       if (unamep == NULL)
+       if (unamep == NULL) {
                getuname();
+       }
        return (unamep);
 }