From eff37b355c0e0c6ecf077898f34a8cf8bb5f9378 Mon Sep 17 00:00:00 2001
From: Lev Kujawski <int21h@mailbox.org>
Date: Wed, 6 Jan 2021 12:00:17 -0700
Subject: [PATCH 01/14] Define _DtPLATFORM_MAX_LEN for C libraries (including
 musl) that do not provide the SVID SYS_NMLN definition. Use sizeof() to
 replace another #ifdef.

---
 cde/lib/DtSvc/DtUtil2/XlationSvc.c | 11 ++++-------
 cde/lib/DtSvc/DtUtil2/XlationSvc.h | 13 +++++++------
 2 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/cde/lib/DtSvc/DtUtil2/XlationSvc.c b/cde/lib/DtSvc/DtUtil2/XlationSvc.c
index a7298c0a..c36f97de 100644
--- a/cde/lib/DtSvc/DtUtil2/XlationSvc.c
+++ b/cde/lib/DtSvc/DtUtil2/XlationSvc.c
@@ -2199,18 +2199,15 @@ int _DtXlateGetXlateEnv(
    /* then look up version number of execution host */
    if (ret_AppExecEnvVersion) 
    {
-#if defined(sun) || defined(_AIX) || defined(__linux__) || defined(CSRG_BASED)
-      char version[SYS_NMLN+SYS_NMLN+2];
-#else
-      char version[UTSLEN+UTSLEN+2];
-#endif
+      char version[sizeof(names.release)+sizeof(names.version)-1];
       char * stdVer = NULL;
       int  verNum = MATCHALL_VER;
 
       /* cat release version and do a translation on it to a std value */
       /* then convert the std value to a integer */
-      strcpy(version,names.release);
-      strcat(version,names.version);
+      strncpy(version,names.release,sizeof(names.release)-1);
+      version[sizeof(names.release)-1] = EOS;
+      strncat(version,names.version,sizeof(names.version)-1);
       ret = _DtXlateOpToStdValue(db,names.sysname,0,
                    _DtXLATE_OPER_VERSION,version,&stdVer,NULL);
       if (ret == 0)
diff --git a/cde/lib/DtSvc/DtUtil2/XlationSvc.h b/cde/lib/DtSvc/DtUtil2/XlationSvc.h
index ab2763e5..4cbf865b 100644
--- a/cde/lib/DtSvc/DtUtil2/XlationSvc.h
+++ b/cde/lib/DtSvc/DtUtil2/XlationSvc.h
@@ -109,14 +109,15 @@ platforms as part of a translation.
 /*================================================$SKIP$==*/
 #endif
 /* $DEF$, Platform constants */
-#if defined(SVR4) || defined(_AIX)
+#if defined(SVR4) || defined(_AIX) || defined(SYS_NMLN)
 #define _DtPLATFORM_MAX_LEN SYS_NMLN
-#else
-#if defined(SYS_NMLN)
-#define _DtPLATFORM_MAX_LEN SYS_NMLN
-#else
+#elif defined(UTSLEN)
 #define _DtPLATFORM_MAX_LEN UTSLEN
-#endif
+#else
+/* POSIX guarantees that hostnames are limited to 255 bytes,
+ * but SVR4 platforms commonly allow for 256.
+ */
+#define _DtPLATFORM_MAX_LEN 257
 #endif
 
 #define _DtPLATFORM_UNKNOWN ((const char *)0)
-- 
2.30.0

