提交 d185cda7 编写于 作者: S Steve French

[CIFS] rename cifs_strndup to cifs_strndup_from_ucs

In most cases, cifs_strndup is converting from Unicode (UCS2 / UTF-32) to
the configured local code page for the Linux mount (usually UTF8), so
Jeff suggested that to make it more clear that cifs_strndup is doing
a conversion not just memory allocation and copy, rename the function
to including "from_ucs" (ie Unicode)
Signed-off-by: NSteve French <sfrench@us.ibm.com>
上级 5c2503a8
...@@ -2,7 +2,11 @@ Version 1.58 ...@@ -2,7 +2,11 @@ Version 1.58
------------ ------------
Guard against buffer overruns in various UCS-2 to UTF-8 string conversions Guard against buffer overruns in various UCS-2 to UTF-8 string conversions
when the UTF-8 string is composed of unusually long (more than 4 byte) converted when the UTF-8 string is composed of unusually long (more than 4 byte) converted
characters. characters. Add support for mounting root of a share which redirects immediately
to DFS target. Convert string conversion functions from Unicode to more
accurately mark string length before allocating memory (which may help the
rare cases where a UTF-8 string is much larger than the UCS2 string that
we converted from).
Version 1.57 Version 1.57
------------ ------------
......
/* /*
* fs/cifs/cifs_unicode.c * fs/cifs/cifs_unicode.c
* *
* Copyright (c) International Business Machines Corp., 2000,2005 * Copyright (c) International Business Machines Corp., 2000,2009
* Modified by Steve French (sfrench@us.ibm.com) * Modified by Steve French (sfrench@us.ibm.com)
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
...@@ -244,7 +244,7 @@ cifs_strtoUCS(__le16 *to, const char *from, int len, ...@@ -244,7 +244,7 @@ cifs_strtoUCS(__le16 *to, const char *from, int len,
} }
/* /*
* cifs_strndup - copy a string from wire format to the local codepage * cifs_strndup_from_ucs - copy a string from wire format to the local codepage
* @src - source string * @src - source string
* @maxlen - don't walk past this many bytes in the source string * @maxlen - don't walk past this many bytes in the source string
* @is_unicode - is this a unicode string? * @is_unicode - is this a unicode string?
...@@ -255,7 +255,7 @@ cifs_strtoUCS(__le16 *to, const char *from, int len, ...@@ -255,7 +255,7 @@ cifs_strtoUCS(__le16 *to, const char *from, int len,
* error. * error.
*/ */
char * char *
cifs_strndup(const char *src, const int maxlen, const bool is_unicode, cifs_strndup_from_ucs(const char *src, const int maxlen, const bool is_unicode,
const struct nls_table *codepage) const struct nls_table *codepage)
{ {
int len; int len;
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* Convert a unicode character to upper or lower case using * Convert a unicode character to upper or lower case using
* compressed tables. * compressed tables.
* *
* Copyright (c) International Business Machines Corp., 2000,2007 * Copyright (c) International Business Machines Corp., 2000,2009
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -78,8 +78,9 @@ int cifs_ucs2_bytes(const __le16 *from, int maxbytes, ...@@ -78,8 +78,9 @@ int cifs_ucs2_bytes(const __le16 *from, int maxbytes,
const struct nls_table *codepage); const struct nls_table *codepage);
int cifs_strfromUCS_le(char *, const __le16 *, int, const struct nls_table *); int cifs_strfromUCS_le(char *, const __le16 *, int, const struct nls_table *);
int cifs_strtoUCS(__le16 *, const char *, int, const struct nls_table *); int cifs_strtoUCS(__le16 *, const char *, int, const struct nls_table *);
char *cifs_strndup(const char *src, const int maxlen, const bool is_unicode, char *cifs_strndup_from_ucs(const char *src, const int maxlen,
const struct nls_table *codepage); const bool is_unicode,
const struct nls_table *codepage);
#endif #endif
/* /*
......
/* /*
* fs/cifs/cifssmb.c * fs/cifs/cifssmb.c
* *
* Copyright (C) International Business Machines Corp., 2002,2008 * Copyright (C) International Business Machines Corp., 2002,2009
* Author(s): Steve French (sfrench@us.ibm.com) * Author(s): Steve French (sfrench@us.ibm.com)
* *
* Contains the routines for constructing the SMB PDUs themselves * Contains the routines for constructing the SMB PDUs themselves
...@@ -2457,7 +2457,7 @@ CIFSSMBUnixQuerySymLink(const int xid, struct cifsTconInfo *tcon, ...@@ -2457,7 +2457,7 @@ CIFSSMBUnixQuerySymLink(const int xid, struct cifsTconInfo *tcon,
le16_to_cpu(pSMBr->t2.DataOffset); le16_to_cpu(pSMBr->t2.DataOffset);
/* BB FIXME investigate remapping reserved chars here */ /* BB FIXME investigate remapping reserved chars here */
*symlinkinfo = cifs_strndup(data_start, count, *symlinkinfo = cifs_strndup_from_ucs(data_start, count,
pSMBr->hdr.Flags2 & pSMBr->hdr.Flags2 &
SMBFLG2_UNICODE, SMBFLG2_UNICODE,
nls_codepage); nls_codepage);
...@@ -3965,8 +3965,8 @@ parse_DFS_referrals(TRANSACTION2_GET_DFS_REFER_RSP *pSMBr, ...@@ -3965,8 +3965,8 @@ parse_DFS_referrals(TRANSACTION2_GET_DFS_REFER_RSP *pSMBr,
/* copy DfsPath */ /* copy DfsPath */
temp = (char *)ref + le16_to_cpu(ref->DfsPathOffset); temp = (char *)ref + le16_to_cpu(ref->DfsPathOffset);
max_len = data_end - temp; max_len = data_end - temp;
node->path_name = cifs_strndup(temp, max_len, is_unicode, node->path_name = cifs_strndup_from_ucs(temp, max_len,
nls_codepage); is_unicode, nls_codepage);
if (IS_ERR(node->path_name)) { if (IS_ERR(node->path_name)) {
rc = PTR_ERR(node->path_name); rc = PTR_ERR(node->path_name);
node->path_name = NULL; node->path_name = NULL;
...@@ -3976,8 +3976,8 @@ parse_DFS_referrals(TRANSACTION2_GET_DFS_REFER_RSP *pSMBr, ...@@ -3976,8 +3976,8 @@ parse_DFS_referrals(TRANSACTION2_GET_DFS_REFER_RSP *pSMBr,
/* copy link target UNC */ /* copy link target UNC */
temp = (char *)ref + le16_to_cpu(ref->NetworkAddressOffset); temp = (char *)ref + le16_to_cpu(ref->NetworkAddressOffset);
max_len = data_end - temp; max_len = data_end - temp;
node->node_name = cifs_strndup(temp, max_len, is_unicode, node->node_name = cifs_strndup_from_ucs(temp, max_len,
nls_codepage); is_unicode, nls_codepage);
if (IS_ERR(node->node_name)) { if (IS_ERR(node->node_name)) {
rc = PTR_ERR(node->node_name); rc = PTR_ERR(node->node_name);
node->node_name = NULL; node->node_name = NULL;
......
/* /*
* fs/cifs/connect.c * fs/cifs/connect.c
* *
* Copyright (C) International Business Machines Corp., 2002,2008 * Copyright (C) International Business Machines Corp., 2002,2009
* Author(s): Steve French (sfrench@us.ibm.com) * Author(s): Steve French (sfrench@us.ibm.com)
* *
* This library is free software; you can redistribute it and/or modify * This library is free software; you can redistribute it and/or modify
...@@ -3463,7 +3463,8 @@ CIFSTCon(unsigned int xid, struct cifsSesInfo *ses, ...@@ -3463,7 +3463,8 @@ CIFSTCon(unsigned int xid, struct cifsSesInfo *ses,
strncpy(tcon->treeName, tree, MAX_TREE_SIZE); strncpy(tcon->treeName, tree, MAX_TREE_SIZE);
/* mostly informational -- no need to fail on error here */ /* mostly informational -- no need to fail on error here */
tcon->nativeFileSystem = cifs_strndup(bcc_ptr, bytes_left, tcon->nativeFileSystem = cifs_strndup_from_ucs(bcc_ptr,
bytes_left,
smb_buffer->Flags2 & smb_buffer->Flags2 &
SMBFLG2_UNICODE, SMBFLG2_UNICODE,
nls_codepage); nls_codepage);
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* SMB/CIFS session setup handling routines * SMB/CIFS session setup handling routines
* *
* Copyright (c) International Business Machines Corp., 2006, 2007 * Copyright (c) International Business Machines Corp., 2006, 2009
* Author(s): Steve French (sfrench@us.ibm.com) * Author(s): Steve French (sfrench@us.ibm.com)
* *
* This library is free software; you can redistribute it and/or modify * This library is free software; you can redistribute it and/or modify
...@@ -300,7 +300,7 @@ decode_unicode_ssetup(char **pbcc_area, int bleft, struct cifsSesInfo *ses, ...@@ -300,7 +300,7 @@ decode_unicode_ssetup(char **pbcc_area, int bleft, struct cifsSesInfo *ses,
} }
kfree(ses->serverOS); kfree(ses->serverOS);
ses->serverOS = cifs_strndup(data, bleft, true, nls_cp); ses->serverOS = cifs_strndup_from_ucs(data, bleft, true, nls_cp);
cFYI(1, ("serverOS=%s", ses->serverOS)); cFYI(1, ("serverOS=%s", ses->serverOS));
len = (UniStrnlen((wchar_t *) data, bleft / 2) * 2) + 2; len = (UniStrnlen((wchar_t *) data, bleft / 2) * 2) + 2;
data += len; data += len;
...@@ -309,7 +309,7 @@ decode_unicode_ssetup(char **pbcc_area, int bleft, struct cifsSesInfo *ses, ...@@ -309,7 +309,7 @@ decode_unicode_ssetup(char **pbcc_area, int bleft, struct cifsSesInfo *ses,
return; return;
kfree(ses->serverNOS); kfree(ses->serverNOS);
ses->serverNOS = cifs_strndup(data, bleft, true, nls_cp); ses->serverNOS = cifs_strndup_from_ucs(data, bleft, true, nls_cp);
cFYI(1, ("serverNOS=%s", ses->serverNOS)); cFYI(1, ("serverNOS=%s", ses->serverNOS));
len = (UniStrnlen((wchar_t *) data, bleft / 2) * 2) + 2; len = (UniStrnlen((wchar_t *) data, bleft / 2) * 2) + 2;
data += len; data += len;
...@@ -318,7 +318,7 @@ decode_unicode_ssetup(char **pbcc_area, int bleft, struct cifsSesInfo *ses, ...@@ -318,7 +318,7 @@ decode_unicode_ssetup(char **pbcc_area, int bleft, struct cifsSesInfo *ses,
return; return;
kfree(ses->serverDomain); kfree(ses->serverDomain);
ses->serverDomain = cifs_strndup(data, bleft, true, nls_cp); ses->serverDomain = cifs_strndup_from_ucs(data, bleft, true, nls_cp);
cFYI(1, ("serverDomain=%s", ses->serverDomain)); cFYI(1, ("serverDomain=%s", ses->serverDomain));
return; return;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册