From fe2356bf5f9da5fe5800e7ec014e81f52e787dce Mon Sep 17 00:00:00 2001 From: Frank Zago Date: Thu, 26 Mar 2015 18:42:25 -0500 Subject: [PATCH] LU-6406 tests: fix undersized fsname and FID strings A Lustre filesystem name is up to 8 characters, plus 1 for the NUL terminator. If a filesystem name is 8 characters, then the llapi_layout_test, llapi_hsm_test, group_lock_test and llapi_fid_test may have their stack scribbled or overran when they call llapi_search_mounts(). Add one extra byte for the NUL character. Same issue with a FID string, which also needs an extra character for NUL termination. Signed-off-by: frank zago Change-Id: Ic7757ebce051e12f4723e27b5b00d4db1637b384 Reviewed-on: http://review.whamcloud.com/14213 Tested-by: Jenkins Reviewed-by: Dmitry Eremin Tested-by: Maloo Reviewed-by: John L. Hammond Reviewed-by: Oleg Drokin --- lustre/lod/lod_object.c | 3 ++- lustre/tests/llapi_fid_test.c | 8 ++++---- lustre/tests/llapi_hsm_test.c | 2 +- lustre/tests/llapi_layout_test.c | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lustre/lod/lod_object.c b/lustre/lod/lod_object.c index 2ba89c2..a87c4e8 100644 --- a/lustre/lod/lod_object.c +++ b/lustre/lod/lod_object.c @@ -853,7 +853,8 @@ int lod_load_lmv_shards(const struct lu_env *env, struct lod_object *lo, goto next; } - len = snprintf(name, FID_LEN + 1, DFID":", PFID(&ent->lde_fid)); + len = snprintf(name, sizeof(name), + DFID":", PFID(&ent->lde_fid)); /* The ent->lde_name is composed of ${FID}:${index} */ if (ent->lde_namelen < len + 1 || memcmp(ent->lde_name, name, len) != 0) { diff --git a/lustre/tests/llapi_fid_test.c b/lustre/tests/llapi_fid_test.c index e7d18f9..e8433a1 100644 --- a/lustre/tests/llapi_fid_test.c +++ b/lustre/tests/llapi_fid_test.c @@ -105,7 +105,7 @@ static void helper_fid2path(const char *filename, int fd) lustre_fid fid; lustre_fid fid2; lustre_fid fid3; - char fidstr[FID_LEN]; + char fidstr[FID_LEN + 1]; char path1[PATH_MAX]; char path2[PATH_MAX]; char path3[PATH_MAX]; @@ -241,7 +241,7 @@ static void test11(void) int rc; int fd; lustre_fid fid; - char fidstr[FID_LEN]; + char fidstr[FID_LEN + 1]; char path[PATH_MAX]; long long recno; int linkno; @@ -371,7 +371,7 @@ static void test30(void) char buf[PATH_MAX]; char buf2[PATH_MAX]; lustre_fid fid; - char fidstr[FID_LEN]; + char fidstr[FID_LEN + 1]; int rc; int i; int j; @@ -698,7 +698,7 @@ static void process_args(int argc, char *argv[]) int main(int argc, char *argv[]) { - char fsname[8]; + char fsname[8 + 1]; int rc; process_args(argc, argv); diff --git a/lustre/tests/llapi_hsm_test.c b/lustre/tests/llapi_hsm_test.c index 54c3495..7c47654 100644 --- a/lustre/tests/llapi_hsm_test.c +++ b/lustre/tests/llapi_hsm_test.c @@ -1024,7 +1024,7 @@ static void process_args(int argc, char *argv[]) int main(int argc, char *argv[]) { - char fsname[8]; + char fsname[8 + 1]; int rc; process_args(argc, argv); diff --git a/lustre/tests/llapi_layout_test.c b/lustre/tests/llapi_layout_test.c index 12109f1..53b20b7 100644 --- a/lustre/tests/llapi_layout_test.c +++ b/lustre/tests/llapi_layout_test.c @@ -1313,7 +1313,7 @@ int main(int argc, char *argv[]) int rc = 0; int i; struct stat s; - char fsname[8]; + char fsname[8 + 1]; llapi_msg_set_level(LLAPI_MSG_OFF); -- 1.8.3.1