From: Chris Hanna Date: Thu, 23 Mar 2017 18:20:46 +0000 (-0400) Subject: LU-9245 utils: fix string copy handling within lgss_sk X-Git-Tag: 2.9.56~49 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=460ad9d609768e6d8182a2dfd1f24d5fcb0b3560;hp=738374be02d52ba10b44f4c4d4b335807eb48b46 LU-9245 utils: fix string copy handling within lgss_sk Strings are not copied correctly when the fsname or nodemap field of a shared key is replaced. Instead of being zero-terminated, the new string may overlap the original if it is smaller. Fixed by using the buffer length instead of the string length in strncpy(). Change-Id: I17bb5aa0ca7c25b2545c17c6f23e69045730a547 Test-Parameters: trivial Signed-off-by: Chris Hanna Reviewed-on: https://review.whamcloud.com/26165 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Kit Westneat Reviewed-by: Andreas Dilger --- diff --git a/lustre/utils/gss/lgss_sk.c b/lustre/utils/gss/lgss_sk.c index f7254d2..15ff3fc 100644 --- a/lustre/utils/gss/lgss_sk.c +++ b/lustre/utils/gss/lgss_sk.c @@ -550,7 +550,7 @@ int main(int argc, char **argv) generate_prime = type & SK_TYPE_CLIENT; strncpy(config->skc_nodemap, SK_DEFAULT_NODEMAP, - strlen(SK_DEFAULT_NODEMAP)); + sizeof(config->skc_nodemap) - 1); if (!datafile) datafile = "/dev/random"; @@ -567,9 +567,11 @@ int main(int argc, char **argv) if (prime_bits != -1) config->skc_prime_bits = prime_bits; if (fsname) - strncpy(config->skc_fsname, fsname, strlen(fsname)); + strncpy(config->skc_fsname, fsname, + sizeof(config->skc_fsname) - 1); if (nodemap) - strncpy(config->skc_nodemap, nodemap, strlen(nodemap)); + strncpy(config->skc_nodemap, nodemap, + sizeof(config->skc_nodemap) - 1); if (mgsnids && parse_mgsnids(mgsnids, config)) goto error; if (sk_validate_config(config)) {