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".

(cherry picked from commit 4bc3de070f)
This commit is contained in:
Mark Andrews
2020-06-25 09:32:02 +10:00
parent b8fbd0a1ae
commit 003d9d55ca
4 changed files with 18 additions and 15 deletions
+1 -1
View 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 */
+12 -10
View 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);
}
+1 -1
View 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 */
+4 -3
View 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);
}