From 4c8dccd5c40d182d23c8ec6b31361535fe113388 Mon Sep 17 00:00:00 2001 From: Shiyong Li Date: Fri, 8 Dec 2017 17:33:51 -0800 Subject: [PATCH] fs/exfat: use correct length for utf conversion when call utf16s_to_utf8s, last parmater 'maxout' will be reduced with the returned value of utf32_to_utf8, the value reflects the size of one utf character, it could be 1~max charset size(3), so maxout should use MAX_NAME_LENGTH * MAX_CHARSET_SIZE when call utf8s_to_utf16s, the inlen will be reduced with the the returned value of utf8_to_utf32, so it should use MAX_NAME_LENGTH * MAX_CHARSET_SIZE or the lenghth of p_cstring whose max value is MAX_NAME_LENGTH * MAX_CHARSET_SIZE. Change-Id: Icbea02ece4b1a5b015037a6a54178ee8e08d4325 Signed-off-by: Shengzhe Zhao Signed-off-by: Shiyong Li Reviewed-on: https://gerrit.mot.com/1102180 SME-Granted: SME Approvals Granted SLTApproved: Slta Waiver Tested-by: Jira Key Reviewed-by: Igor Kovalenko Submit-Approved: Jira Key Reviewed-on: https://gerrit.mot.com/1276881 Reviewed-by: Hua Tan --- fs/exfat/exfat_nls.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/exfat/exfat_nls.c b/fs/exfat/exfat_nls.c index a0ba86b63087..87edeb5b4bb5 100644 --- a/fs/exfat/exfat_nls.c +++ b/fs/exfat/exfat_nls.c @@ -295,7 +295,9 @@ void nls_uniname_to_cstring(struct super_block *sb, u8 *p_cstring, UNI_NAME_T *p struct nls_table *nls = EXFAT_SB(sb)->nls_io; if (nls == NULL) { - len = utf16s_to_utf8s(uniname, MAX_NAME_LENGTH, UTF16_HOST_ENDIAN, p_cstring, MAX_NAME_LENGTH); + len = utf16s_to_utf8s(uniname, MAX_NAME_LENGTH, + UTF16_HOST_ENDIAN, p_cstring, + MAX_NAME_LENGTH * MAX_CHARSET_SIZE); if (len >= MAX_NAME_LENGTH * MAX_CHARSET_SIZE) len--; @@ -359,7 +361,8 @@ void nls_cstring_to_uniname(struct super_block *sb, UNI_NAME_T *p_uniname, u8 *p #if LINUX_VERSION_CODE < KERNEL_VERSION(3,0,101) i = utf8s_to_utf16s(p_cstring, MAX_NAME_LENGTH, uniname); #else - i = utf8s_to_utf16s(p_cstring, MAX_NAME_LENGTH, UTF16_HOST_ENDIAN, uniname, MAX_NAME_LENGTH); + i = utf8s_to_utf16s(p_cstring, MAX_NAME_LENGTH * MAX_CHARSET_SIZE, + UTF16_HOST_ENDIAN, uniname, MAX_NAME_LENGTH); #endif for (j = 0; j < i; j++) SET16_A(upname + j * 2, nls_upper(sb, uniname[j])); -- 2.20.1