CIFS: Make cifs_convert_address() take a const src pointer and a length
Make cifs_convert_address() take a const src pointer and a length so that all the strlen() calls in their can be cut out and to make it unnecessary to modify the src string. Also return the data length from dns_resolve_server_name_to_ip() so that a strlen() can be cut out of cifs_compose_mount_options() too. Acked-by: Jeff Layton <jlayton@redhat.com> Signed-off-by: David Howells <dhowells@redhat.com> Signed-off-by: Steve French <sfrench@us.ibm.com>
This commit is contained in:
committed by
Steve French
parent
f579903ef3
commit
67b7626a05
@ -40,11 +40,11 @@ static const struct cred *dns_resolver_cache;
|
||||
* 0 - name is not IP
|
||||
*/
|
||||
static int
|
||||
is_ip(char *name)
|
||||
is_ip(const char *name, int len)
|
||||
{
|
||||
struct sockaddr_storage ss;
|
||||
|
||||
return cifs_convert_address((struct sockaddr *)&ss, name);
|
||||
return cifs_convert_address((struct sockaddr *)&ss, name, len);
|
||||
}
|
||||
|
||||
static int
|
||||
@ -54,6 +54,10 @@ dns_resolver_instantiate(struct key *key, const void *data,
|
||||
int rc = 0;
|
||||
char *ip;
|
||||
|
||||
/* make sure this looks like an address */
|
||||
if (!is_ip(data, datalen))
|
||||
return -EINVAL;
|
||||
|
||||
ip = kmalloc(datalen + 1, GFP_KERNEL);
|
||||
if (!ip)
|
||||
return -ENOMEM;
|
||||
@ -61,12 +65,6 @@ dns_resolver_instantiate(struct key *key, const void *data,
|
||||
memcpy(ip, data, datalen);
|
||||
ip[datalen] = '\0';
|
||||
|
||||
/* make sure this looks like an address */
|
||||
if (!is_ip(ip)) {
|
||||
kfree(ip);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
key->type_data.x[0] = datalen;
|
||||
key->payload.data = ip;
|
||||
|
||||
@ -93,7 +91,7 @@ struct key_type key_type_dns_resolver = {
|
||||
* unc - server UNC
|
||||
* output:
|
||||
* *ip_addr - pointer to server ip, caller responcible for freeing it.
|
||||
* return 0 on success
|
||||
* return the length of the returned string on success
|
||||
*/
|
||||
int
|
||||
dns_resolve_server_name_to_ip(const char *unc, char **ip_addr)
|
||||
@ -131,7 +129,7 @@ dns_resolve_server_name_to_ip(const char *unc, char **ip_addr)
|
||||
memcpy(name, unc+2, len);
|
||||
name[len] = 0;
|
||||
|
||||
if (is_ip(name)) {
|
||||
if (is_ip(name, len)) {
|
||||
cFYI(1, "%s: it is IP, skipping dns upcall: %s",
|
||||
__func__, name);
|
||||
data = name;
|
||||
@ -164,7 +162,7 @@ skip_upcall:
|
||||
name,
|
||||
*ip_addr
|
||||
);
|
||||
rc = 0;
|
||||
rc = len;
|
||||
} else {
|
||||
rc = -ENOMEM;
|
||||
}
|
||||
|
Reference in New Issue
Block a user