|
View:
New views
1 Messages
—
Rating Filter:
Alert me
|
|
|
[PATCH 1/2] [CIFS] cleanup code by moving often repeated code sequence into a separate function - part1move all repeating code sequences, which use
- cifsConvertToUCS() to a new function - setup_ucs_nls_name() Signed-off-by: Günter Kukkukk <linux@...> fs/cifs/cifssmb.c | 278 ++++++++++++----------------------------------------- 1 files changed, 61 insertions(+), 217 deletions(-) -- 1.5.4.4 [cleanup_ucs_nls_01.patch] diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c index 174bf8a..7283dd3 100644 --- a/fs/cifs/cifssmb.c +++ b/fs/cifs/cifssmb.c @@ -444,6 +444,27 @@ static int validate_t2(struct smb_t2_rsp *pSMB) sizeof(struct smb_t2_rsp) + 16); return rc; } + +static int +setup_ucs_nls_name(__le16 Flags2, char *dst, const char *src, + const struct nls_table *nls_codepage, int remap) +{ + int name_len; + + if (Flags2 & SMBFLG2_UNICODE) { + name_len = cifsConvertToUCS((__le16 *)dst, src, + PATH_MAX, nls_codepage, remap); + name_len++; /* trailing null */ + name_len *= 2; + } else { /* BB add path length overrun check */ + name_len = strnlen(src, PATH_MAX); + name_len++; /* trailing null */ + strlcpy(dst, src, name_len); + } + + return name_len; +} + int CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses) { @@ -864,17 +885,8 @@ PsxDelete: if (rc) return rc; - if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { - name_len = - cifsConvertToUCS((__le16 *) pSMB->FileName, fileName, - PATH_MAX, nls_codepage, remap); - name_len++; /* trailing null */ - name_len *= 2; - } else { /* BB add path length overrun check */ - name_len = strnlen(fileName, PATH_MAX); - name_len++; /* trailing null */ - strncpy(pSMB->FileName, fileName, name_len); - } + name_len = setup_ucs_nls_name(pSMB->hdr.Flags2, pSMB->FileName, + fileName, nls_codepage, remap); params = 6 + name_len; pSMB->MaxParameterCount = cpu_to_le16(2); @@ -936,17 +948,9 @@ DelFileRetry: if (rc) return rc; - if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { - name_len = - cifsConvertToUCS((__le16 *) pSMB->fileName, fileName, - PATH_MAX, nls_codepage, remap); - name_len++; /* trailing null */ - name_len *= 2; - } else { /* BB improve check for buffer overruns BB */ - name_len = strnlen(fileName, PATH_MAX); - name_len++; /* trailing null */ - strncpy(pSMB->fileName, fileName, name_len); - } + name_len = setup_ucs_nls_name(pSMB->hdr.Flags2, pSMB->fileName, + fileName, nls_codepage, remap); + pSMB->SearchAttributes = cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM); pSMB->BufferFormat = 0x04; @@ -982,16 +986,8 @@ RmDirRetry: if (rc) return rc; - if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { - name_len = cifsConvertToUCS((__le16 *) pSMB->DirName, dirName, - PATH_MAX, nls_codepage, remap); - name_len++; /* trailing null */ - name_len *= 2; - } else { /* BB improve check for buffer overruns BB */ - name_len = strnlen(dirName, PATH_MAX); - name_len++; /* trailing null */ - strncpy(pSMB->DirName, dirName, name_len); - } + name_len = setup_ucs_nls_name(pSMB->hdr.Flags2, pSMB->DirName, + dirName, nls_codepage, remap); pSMB->BufferFormat = 0x04; pSMB->hdr.smb_buf_length += name_len + 1; @@ -1025,16 +1021,8 @@ MkDirRetry: if (rc) return rc; - if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { - name_len = cifsConvertToUCS((__le16 *) pSMB->DirName, name, - PATH_MAX, nls_codepage, remap); - name_len++; /* trailing null */ - name_len *= 2; - } else { /* BB improve check for buffer overruns BB */ - name_len = strnlen(name, PATH_MAX); - name_len++; /* trailing null */ - strncpy(pSMB->DirName, name, name_len); - } + name_len = setup_ucs_nls_name(pSMB->hdr.Flags2, pSMB->DirName, name, + nls_codepage, remap); pSMB->BufferFormat = 0x04; pSMB->hdr.smb_buf_length += name_len + 1; @@ -1073,18 +1061,8 @@ PsxCreat: if (rc) return rc; - if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { - name_len = - cifsConvertToUCS((__le16 *) pSMB->FileName, name, - PATH_MAX, nls_codepage, remap); - name_len++; /* trailing null */ - name_len *= 2; - } else { /* BB improve the check for buffer overruns BB */ - name_len = strnlen(name, PATH_MAX); - name_len++; /* trailing null */ - strncpy(pSMB->FileName, name, name_len); - } - + name_len = setup_ucs_nls_name(pSMB->hdr.Flags2, pSMB->FileName, name, + nls_codepage, remap); params = 6 + name_len; count = sizeof(OPEN_PSX_REQ); pSMB->MaxParameterCount = cpu_to_le16(2); @@ -2275,17 +2253,8 @@ createHardLinkRetry: if (rc) return rc; - if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { - name_len = cifsConvertToUCS((__le16 *) pSMB->FileName, toName, - PATH_MAX, nls_codepage, remap); - name_len++; /* trailing null */ - name_len *= 2; - - } else { /* BB improve the check for buffer overruns BB */ - name_len = strnlen(toName, PATH_MAX); - name_len++; /* trailing null */ - strncpy(pSMB->FileName, toName, name_len); - } + name_len = setup_ucs_nls_name(pSMB->hdr.Flags2, pSMB->FileName, toName, + nls_codepage, remap); params = 6 + name_len; pSMB->MaxSetupCount = 0; pSMB->Reserved = 0; @@ -2297,18 +2266,8 @@ createHardLinkRetry: offset = param_offset + params; data_offset = (char *) (&pSMB->hdr.Protocol) + offset; - if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { - name_len_target = - cifsConvertToUCS((__le16 *) data_offset, fromName, PATH_MAX, - nls_codepage, remap); - name_len_target++; /* trailing null */ - name_len_target *= 2; - } else { /* BB improve the check for buffer overruns BB */ - name_len_target = strnlen(fromName, PATH_MAX); - name_len_target++; /* trailing null */ - strncpy(data_offset, fromName, name_len_target); - } - + name_len_target = setup_ucs_nls_name(pSMB->hdr.Flags2, data_offset, + fromName, nls_codepage, remap); pSMB->MaxParameterCount = cpu_to_le16(2); /* BB find exact max on data count below from sess*/ pSMB->MaxDataCount = cpu_to_le16(1000); @@ -2950,17 +2909,8 @@ setAclRetry: (void **) &pSMBr); if (rc) return rc; - if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { - name_len = - cifsConvertToUCS((__le16 *) pSMB->FileName, fileName, - PATH_MAX, nls_codepage, remap); - name_len++; /* trailing null */ - name_len *= 2; - } else { /* BB improve the check for buffer overruns BB */ - name_len = strnlen(fileName, PATH_MAX); - name_len++; /* trailing null */ - strncpy(pSMB->FileName, fileName, name_len); - } + name_len = setup_ucs_nls_name(pSMB->hdr.Flags2, pSMB->FileName, + fileName, nls_codepage, remap); params = 6 + name_len; pSMB->MaxParameterCount = cpu_to_le16(2); /* BB find max SMB size from sess */ @@ -3272,17 +3222,8 @@ QInfRetry: if (rc) return rc; - if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { - name_len = - cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, - PATH_MAX, nls_codepage, remap); - name_len++; /* trailing null */ - name_len *= 2; - } else { - name_len = strnlen(searchName, PATH_MAX); - name_len++; /* trailing null */ - strncpy(pSMB->FileName, searchName, name_len); - } + name_len = setup_ucs_nls_name(pSMB->hdr.Flags2, pSMB->FileName, + searchName, nls_codepage, remap); pSMB->BufferFormat = 0x04; name_len++; /* account for buffer type byte */ pSMB->hdr.smb_buf_length += (__u16) name_len; @@ -3346,18 +3287,8 @@ QPathInfoRetry: if (rc) return rc; - if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { - name_len = - cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, - PATH_MAX, nls_codepage, remap); - name_len++; /* trailing null */ - name_len *= 2; - } else { /* BB improve the check for buffer overruns BB */ - name_len = strnlen(searchName, PATH_MAX); - name_len++; /* trailing null */ - strncpy(pSMB->FileName, searchName, name_len); - } - + name_len = setup_ucs_nls_name(pSMB->hdr.Flags2, pSMB->FileName, + searchName, nls_codepage, remap); params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; pSMB->TotalDataCount = 0; pSMB->MaxParameterCount = cpu_to_le16(2); @@ -3446,18 +3377,8 @@ UnixQPathInfoRetry: if (rc) return rc; - if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { - name_len = - cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, - PATH_MAX, nls_codepage, remap); - name_len++; /* trailing null */ - name_len *= 2; - } else { /* BB improve the check for buffer overruns BB */ - name_len = strnlen(searchName, PATH_MAX); - name_len++; /* trailing null */ - strncpy(pSMB->FileName, searchName, name_len); - } - + name_len = setup_ucs_nls_name(pSMB->hdr.Flags2, pSMB->FileName, + searchName, nls_codepage, remap); params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; pSMB->TotalDataCount = 0; pSMB->MaxParameterCount = cpu_to_le16(2); @@ -3826,18 +3747,8 @@ GetInodeNumberRetry: if (rc) return rc; - if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { - name_len = - cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, - PATH_MAX, nls_codepage, remap); - name_len++; /* trailing null */ - name_len *= 2; - } else { /* BB improve the check for buffer overruns BB */ - name_len = strnlen(searchName, PATH_MAX); - name_len++; /* trailing null */ - strncpy(pSMB->FileName, searchName, name_len); - } - + name_len = setup_ucs_nls_name(pSMB->hdr.Flags2, pSMB->FileName, + searchName, nls_codepage, remap); params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; pSMB->TotalDataCount = 0; pSMB->MaxParameterCount = cpu_to_le16(2); @@ -4023,19 +3934,11 @@ getDFSRetry: if (ses->capabilities & CAP_DFS) pSMB->hdr.Flags2 |= SMBFLG2_DFS; - if (ses->capabilities & CAP_UNICODE) { + if (ses->capabilities & CAP_UNICODE) pSMB->hdr.Flags2 |= SMBFLG2_UNICODE; - name_len = - cifsConvertToUCS((__le16 *) pSMB->RequestFileName, - searchName, PATH_MAX, nls_codepage, remap); - name_len++; /* trailing null */ - name_len *= 2; - } else { /* BB improve the check for buffer overruns BB */ - name_len = strnlen(searchName, PATH_MAX); - name_len++; /* trailing null */ - strncpy(pSMB->RequestFileName, searchName, name_len); - } + name_len = setup_ucs_nls_name(pSMB->hdr.Flags2, pSMB->RequestFileName, + searchName, nls_codepage, remap); if (ses->server) { if (ses->server->secMode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) @@ -4657,17 +4560,8 @@ SetEOFRetry: if (rc) return rc; - if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { - name_len = - cifsConvertToUCS((__le16 *) pSMB->FileName, fileName, - PATH_MAX, nls_codepage, remap); - name_len++; /* trailing null */ - name_len *= 2; - } else { /* BB improve the check for buffer overruns BB */ - name_len = strnlen(fileName, PATH_MAX); - name_len++; /* trailing null */ - strncpy(pSMB->FileName, fileName, name_len); - } + name_len = setup_ucs_nls_name(pSMB->hdr.Flags2, pSMB->FileName, + fileName, nls_codepage, remap); params = 6 + name_len; data_count = sizeof(struct file_end_of_file_info); pSMB->MaxParameterCount = cpu_to_le16(2); @@ -4900,18 +4794,8 @@ SetTimesRetry: if (rc) return rc; - if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { - name_len = - cifsConvertToUCS((__le16 *) pSMB->FileName, fileName, - PATH_MAX, nls_codepage, remap); - name_len++; /* trailing null */ - name_len *= 2; - } else { /* BB improve the check for buffer overruns BB */ - name_len = strnlen(fileName, PATH_MAX); - name_len++; /* trailing null */ - strncpy(pSMB->FileName, fileName, name_len); - } - + name_len = setup_ucs_nls_name(pSMB->hdr.Flags2, pSMB->FileName, + fileName, nls_codepage, remap); params = 6 + name_len; count = sizeof(FILE_BASIC_INFO); pSMB->MaxParameterCount = cpu_to_le16(2); @@ -5031,18 +4915,8 @@ setPermsRetry: if (rc) return rc; - if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { - name_len = - cifsConvertToUCS((__le16 *) pSMB->FileName, fileName, - PATH_MAX, nls_codepage, remap); - name_len++; /* trailing null */ - name_len *= 2; - } else { /* BB improve the check for buffer overruns BB */ - name_len = strnlen(fileName, PATH_MAX); - name_len++; /* trailing null */ - strncpy(pSMB->FileName, fileName, name_len); - } - + name_len = setup_ucs_nls_name(pSMB->hdr.Flags2, pSMB->FileName, + fileName, nls_codepage, remap); params = 6 + name_len; count = sizeof(FILE_UNIX_BASIC_INFO); pSMB->MaxParameterCount = cpu_to_le16(2); @@ -5214,18 +5088,8 @@ QAllEAsRetry: if (rc) return rc; - if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { - name_len = - cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, - PATH_MAX, nls_codepage, remap); - name_len++; /* trailing null */ - name_len *= 2; - } else { /* BB improve the check for buffer overruns BB */ - name_len = strnlen(searchName, PATH_MAX); - name_len++; /* trailing null */ - strncpy(pSMB->FileName, searchName, name_len); - } - + name_len = setup_ucs_nls_name(pSMB->hdr.Flags2, pSMB->FileName, + searchName, nls_codepage, remap); params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; pSMB->TotalDataCount = 0; pSMB->MaxParameterCount = cpu_to_le16(2); @@ -5362,18 +5226,8 @@ QEARetry: if (rc) return rc; - if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { - name_len = - cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, - PATH_MAX, nls_codepage, remap); - name_len++; /* trailing null */ - name_len *= 2; - } else { /* BB improve the check for buffer overruns BB */ - name_len = strnlen(searchName, PATH_MAX); - name_len++; /* trailing null */ - strncpy(pSMB->FileName, searchName, name_len); - } - + name_len = setup_ucs_nls_name(pSMB->hdr.Flags2, pSMB->FileName, + searchName, nls_codepage, remap); params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; pSMB->TotalDataCount = 0; pSMB->MaxParameterCount = cpu_to_le16(2); @@ -5511,18 +5365,8 @@ SetEARetry: if (rc) return rc; - if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { - name_len = - cifsConvertToUCS((__le16 *) pSMB->FileName, fileName, - PATH_MAX, nls_codepage, remap); - name_len++; /* trailing null */ - name_len *= 2; - } else { /* BB improve the check for buffer overruns BB */ - name_len = strnlen(fileName, PATH_MAX); - name_len++; /* trailing null */ - strncpy(pSMB->FileName, fileName, name_len); - } - + name_len = setup_ucs_nls_name(pSMB->hdr.Flags2, pSMB->FileName, + fileName, nls_codepage, remap); params = 6 + name_len; /* done calculating parms using name_len of file name, _______________________________________________ linux-cifs-client mailing list linux-cifs-client@... https://lists.samba.org/mailman/listinfo/linux-cifs-client |
| Free Forum Powered by Nabble | Forum Help |