auth: Don't overflow hostName array
[openafs.git] / src / auth / writeconfig.c
index 3372d27..ad7c0b9 100644 (file)
@@ -11,6 +11,7 @@
 #include <afs/param.h>
 
 #include <roken.h>
+#include <afs/opr.h>
 
 #include <afs/pthread_glock.h>
 #include <afs/afsutil.h>
@@ -53,7 +54,12 @@ VerifyEntries(struct afsconf_cell *aci)
            if (!th) {
                strcpy(aci->hostName[i], "UNKNOWNHOST");
            } else {
-               strcpy(aci->hostName[i], th->h_name);
+               if (strlcpy(aci->hostName[i],
+                           th->h_name,
+                           sizeof(aci->hostName[i]))
+                       >= sizeof(aci->hostName[i])) {
+                  strcpy(aci->hostName[i], "UNKNOWNHOST");
+               }
            }
        }
     }
@@ -87,7 +93,7 @@ afsconf_SetExtendedCellInfo(struct afsconf_dir *adir,
 
     LOCK_GLOBAL_MUTEX;
     /* write ThisCell file */
-    strcompose(tbuffer, 1024, apath, "/", AFSDIR_THISCELL_FILE, NULL);
+    strcompose(tbuffer, 1024, apath, "/", AFSDIR_THISCELL_FILE, (char *)NULL);
 
     fd = open(tbuffer, O_RDWR | O_CREAT | O_TRUNC, 0666);
     if (fd < 0) {
@@ -114,7 +120,7 @@ afsconf_SetExtendedCellInfo(struct afsconf_dir *adir,
     }
 
     /* write CellServDB */
-    strcompose(tbuffer, 1024, apath, "/", AFSDIR_CELLSERVDB_FILE, NULL);
+    strcompose(tbuffer, 1024, apath, "/", AFSDIR_CELLSERVDB_FILE, (char *)NULL);
     tf = fopen(tbuffer, "w");
     if (!tf) {
        UNLOCK_GLOBAL_MUTEX;