Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 144699
b: refs/heads/master
c: 066ce68
h: refs/heads/master
i:
  144697: 1590815
  144695: b1e7978
v: v3
  • Loading branch information
Jeff Layton authored and Steve French committed Apr 30, 2009
1 parent ebe446d commit 564f944
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 44 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 69f801fcaa03be83d58c564f00913b7c172808e4
refs/heads/master: 066ce6899484d9026acd6ba3a8dbbedb33d7ae1b
38 changes: 38 additions & 0 deletions trunk/fs/cifs/cifs_unicode.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,41 @@ cifs_strtoUCS(__le16 *to, const char *from, int len,
return i;
}

/*
* cifs_strndup - copy a string from wire format to the local codepage
* @src - source string
* @maxlen - don't walk past this many bytes in the source string
* @is_unicode - is this a unicode string?
* @codepage - destination codepage
*
* Take a string given by the server, convert it to the local codepage and
* put it in a new buffer. Returns a pointer to the new string or NULL on
* error.
*/
char *
cifs_strndup(const char *src, const int maxlen, const bool is_unicode,
const struct nls_table *codepage)
{
int len;
char *dst;

if (is_unicode) {
len = cifs_ucs2_bytes((__le16 *) src, maxlen, codepage);
len += nls_nullsize(codepage);
dst = kmalloc(len, GFP_KERNEL);
if (!dst)
return NULL;
cifs_from_ucs2(dst, (__le16 *) src, len, maxlen, codepage,
false);
} else {
len = strnlen(src, maxlen);
len++;
dst = kmalloc(len, GFP_KERNEL);
if (!dst)
return NULL;
strlcpy(dst, src, len);
}

return dst;
}

2 changes: 2 additions & 0 deletions trunk/fs/cifs/cifs_unicode.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ int cifs_ucs2_bytes(const __le16 *from, int maxbytes,
const struct nls_table *codepage);
int cifs_strfromUCS_le(char *, const __le16 *, 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,
const struct nls_table *codepage);
#endif

/*
Expand Down
55 changes: 12 additions & 43 deletions trunk/fs/cifs/cifssmb.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,41 +81,6 @@ static struct {
#endif /* CONFIG_CIFS_WEAK_PW_HASH */
#endif /* CIFS_POSIX */

/* Allocates buffer into dst and copies smb string from src to it.
* caller is responsible for freeing dst if function returned 0.
* returns:
* on success - 0
* on failure - errno
*/
static int
cifs_strlcpy_to_host(char **dst, const char *src, const int maxlen,
const bool is_unicode, const struct nls_table *nls_codepage)
{
int plen;

if (is_unicode) {
plen = UniStrnlen((wchar_t *)src, maxlen);
*dst = kmalloc((4 * plen) + 2, GFP_KERNEL);
if (!*dst)
goto cifs_strlcpy_to_host_ErrExit;
cifs_strfromUCS_le(*dst, (__le16 *)src, plen, nls_codepage);
(*dst)[plen] = 0;
(*dst)[plen+1] = 0; /* needed for Unicode */
} else {
plen = strnlen(src, maxlen);
*dst = kmalloc(plen + 2, GFP_KERNEL);
if (!*dst)
goto cifs_strlcpy_to_host_ErrExit;
strlcpy(*dst, src, plen);
}
return 0;

cifs_strlcpy_to_host_ErrExit:
cERROR(1, ("Failed to allocate buffer for string\n"));
return -ENOMEM;
}


/* Mark as invalid, all open files on tree connections since they
were closed when session to server was lost */
static void mark_open_files_invalid(struct cifsTconInfo *pTcon)
Expand Down Expand Up @@ -4008,20 +3973,24 @@ parse_DFS_referrals(TRANSACTION2_GET_DFS_REFER_RSP *pSMBr,
/* copy DfsPath */
temp = (char *)ref + le16_to_cpu(ref->DfsPathOffset);
max_len = data_end - temp;
rc = cifs_strlcpy_to_host(&(node->path_name), temp,
max_len, is_unicode, nls_codepage);
if (rc)
node->path_name = cifs_strndup(temp, max_len, is_unicode,
nls_codepage);
if (IS_ERR(node->path_name)) {
rc = PTR_ERR(node->path_name);
node->path_name = NULL;
goto parse_DFS_referrals_exit;
}

/* copy link target UNC */
temp = (char *)ref + le16_to_cpu(ref->NetworkAddressOffset);
max_len = data_end - temp;
rc = cifs_strlcpy_to_host(&(node->node_name), temp,
max_len, is_unicode, nls_codepage);
if (rc)
node->node_name = cifs_strndup(temp, max_len, is_unicode,
nls_codepage);
if (IS_ERR(node->node_name)) {
rc = PTR_ERR(node->node_name);
node->node_name = NULL;
goto parse_DFS_referrals_exit;

ref += le16_to_cpu(ref->Size);
}
}

parse_DFS_referrals_exit:
Expand Down

0 comments on commit 564f944

Please sign in to comment.