From 2358e27bc14683129a4c9f69f880c20d2e65db34 Mon Sep 17 00:00:00 2001
From: nathan <nathan>
Date: Mon, 12 Feb 2007 21:52:46 +0000
Subject: [PATCH] b=11564 bad null-termination of 8-char filesystem names

---
 lustre/mgs/lproc_mgs.c      | 4 ++--
 lustre/mgs/mgs_internal.h   | 2 +-
 lustre/mgs/mgs_llog.c       | 1 +
 lustre/tests/cfg/local.sh   | 2 +-
 lustre/tests/conf-sanity.sh | 8 +++++---
 5 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/lustre/mgs/lproc_mgs.c b/lustre/mgs/lproc_mgs.c
index acfab55434..2453dc3400 100644
--- a/lustre/mgs/lproc_mgs.c
+++ b/lustre/mgs/lproc_mgs.c
@@ -103,10 +103,10 @@ static int mgs_live_seq_show(struct seq_file *seq, void *v)
                    fsdb->fsdb_flags, fsdb->fsdb_gen);
         for (i = 0; i < INDEX_MAP_SIZE * 8; i++)
                  if (test_bit(i, fsdb->fsdb_mdt_index_map)) 
-                         seq_printf(seq, "%.8s-MDT%04x\n", fsdb->fsdb_name, i);
+                         seq_printf(seq, "%s-MDT%04x\n", fsdb->fsdb_name, i);
         for (i = 0; i < INDEX_MAP_SIZE * 8; i++)
                  if (test_bit(i, fsdb->fsdb_ost_index_map)) 
-                         seq_printf(seq, "%.8s-OST%04x\n", fsdb->fsdb_name, i);
+                         seq_printf(seq, "%s-OST%04x\n", fsdb->fsdb_name, i);
 
         up(&fsdb->fsdb_sem);
         return 0;
diff --git a/lustre/mgs/mgs_internal.h b/lustre/mgs/mgs_internal.h
index a13bd95e48..81c94ad99f 100644
--- a/lustre/mgs/mgs_internal.h
+++ b/lustre/mgs/mgs_internal.h
@@ -29,7 +29,7 @@ int class_dentry_readdir(struct obd_device *obd, struct dentry *dir,
 #define FSDB_OLDLOG14   0x0002  /* log starts in old (1.4) style */
 
 struct fs_db {
-        char              fsdb_name[8];
+        char              fsdb_name[9];
         struct list_head  fsdb_list;           /* list of databases */
         struct semaphore  fsdb_sem;
         void             *fsdb_ost_index_map;  /* bitmap of used indicies */
diff --git a/lustre/mgs/mgs_llog.c b/lustre/mgs/mgs_llog.c
index 4dadf73880..e062bfcdb8 100644
--- a/lustre/mgs/mgs_llog.c
+++ b/lustre/mgs/mgs_llog.c
@@ -292,6 +292,7 @@ static struct fs_db *mgs_new_fsdb(struct obd_device *obd, char *fsname)
         }
         
         strncpy(fsdb->fsdb_name, fsname, sizeof(fsdb->fsdb_name));
+        fsdb->fsdb_name[sizeof(fsdb->fsdb_name) - 1] = 0;
         rc = name_create(&fsdb->fsdb_mdtlov, fsname, "-mdtlov");
         if (rc) 
                 GOTO(err, rc);
diff --git a/lustre/tests/cfg/local.sh b/lustre/tests/cfg/local.sh
index 475847f819..2d2461364b 100644
--- a/lustre/tests/cfg/local.sh
+++ b/lustre/tests/cfg/local.sh
@@ -1,4 +1,4 @@
-FSNAME=lustre
+FSNAME=${FSNAME:-lustre}
 
 # facet hosts
 mds_HOST=${mds_HOST:-`hostname`}
diff --git a/lustre/tests/conf-sanity.sh b/lustre/tests/conf-sanity.sh
index 9fc1b3a300..546a0d89dd 100644
--- a/lustre/tests/conf-sanity.sh
+++ b/lustre/tests/conf-sanity.sh
@@ -820,17 +820,19 @@ test_23() {
 
 test_24a() {
 	local fs2mds_HOST=$mds_HOST
-        add fs2mds $MDS_MKFS_OPTS --fsname=${FSNAME}2 --nomgs --mgsnode=$MGSNID --reformat ${MDSDEV}_2 || exit 10
+	# test 8-char fsname as well
+	local FSNAME2=test1234
+        add fs2mds $MDS_MKFS_OPTS --fsname=${FSNAME2} --nomgs --mgsnode=$MGSNID --reformat ${MDSDEV}_2 || exit 10
 
 	local fs2ost_HOST=$ost_HOST
 	local fs2ostdev=$(ostdevname 1)_2
-	add fs2ost $OST_MKFS_OPTS --fsname=${FSNAME}2 --reformat $fs2ostdev || exit 10
+	add fs2ost $OST_MKFS_OPTS --fsname=${FSNAME2} --reformat $fs2ostdev || exit 10
 
 	setup
 	start fs2mds ${MDSDEV}_2 $MDS_MOUNT_OPTS
 	start fs2ost $fs2ostdev $OST_MOUNT_OPTS
 	mkdir -p $MOUNT2
-	mount -t lustre $MGSNID:/${FSNAME}2 $MOUNT2 || return 1
+	mount -t lustre $MGSNID:/${FSNAME2} $MOUNT2 || return 1
 	# 1 still works
 	check_mount || return 2
 	# files written on 1 should not show up on 2
-- 
GitLab