Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 101934
b: refs/heads/master
c: d1aa082
h: refs/heads/master
v: v3
  • Loading branch information
Chuck Lever authored and Trond Myklebust committed Jul 9, 2008
1 parent 568f1d8 commit 727e14a
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 9 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: dc04589827f7e1af12714af8bb00e3f3c4c48c62
refs/heads/master: d1aa08257312f1439c1ab7c8a18e3856f9530f46
90 changes: 82 additions & 8 deletions trunk/fs/nfs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -1195,14 +1195,9 @@ static int nfs_try_mount(struct nfs_parsed_mount_data *args,
return status;
}

/*
* Split "dev_name" into "hostname:export_path".
*
* Note: caller frees hostname and export path, even on error.
*/
static int nfs_parse_devname(const char *dev_name,
char **hostname, size_t maxnamlen,
char **export_path, size_t maxpathlen)
static int nfs_parse_simple_hostname(const char *dev_name,
char **hostname, size_t maxnamlen,
char **export_path, size_t maxpathlen)
{
size_t len;
char *colon, *comma;
Expand Down Expand Up @@ -1256,6 +1251,85 @@ static int nfs_parse_devname(const char *dev_name,
return -ENAMETOOLONG;
}

/*
* Hostname has square brackets around it because it contains one or
* more colons. We look for the first closing square bracket, and a
* colon must follow it.
*/
static int nfs_parse_protected_hostname(const char *dev_name,
char **hostname, size_t maxnamlen,
char **export_path, size_t maxpathlen)
{
size_t len;
char *start, *end;

start = (char *)(dev_name + 1);

end = strchr(start, ']');
if (end == NULL)
goto out_bad_devname;
if (*(end + 1) != ':')
goto out_bad_devname;

len = end - start;
if (len > maxnamlen)
goto out_hostname;

/* N.B. caller will free nfs_server.hostname in all cases */
*hostname = kstrndup(start, len, GFP_KERNEL);
if (*hostname == NULL)
goto out_nomem;

end += 2;
len = strlen(end);
if (len > maxpathlen)
goto out_path;
*export_path = kstrndup(end, len, GFP_KERNEL);
if (!*export_path)
goto out_nomem;

return 0;

out_bad_devname:
dfprintk(MOUNT, "NFS: device name not in host:path format\n");
return -EINVAL;

out_nomem:
dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
return -ENOMEM;

out_hostname:
dfprintk(MOUNT, "NFS: server hostname too long\n");
return -ENAMETOOLONG;

out_path:
dfprintk(MOUNT, "NFS: export pathname too long\n");
return -ENAMETOOLONG;
}

/*
* Split "dev_name" into "hostname:export_path".
*
* The leftmost colon demarks the split between the server's hostname
* and the export path. If the hostname starts with a left square
* bracket, then it may contain colons.
*
* Note: caller frees hostname and export path, even on error.
*/
static int nfs_parse_devname(const char *dev_name,
char **hostname, size_t maxnamlen,
char **export_path, size_t maxpathlen)
{
if (*dev_name == '[')
return nfs_parse_protected_hostname(dev_name,
hostname, maxnamlen,
export_path, maxpathlen);

return nfs_parse_simple_hostname(dev_name,
hostname, maxnamlen,
export_path, maxpathlen);
}

/*
* Validate the NFS2/NFS3 mount data
* - fills in the mount root filehandle
Expand Down

0 comments on commit 727e14a

Please sign in to comment.