|
|
4f2874 |
commit 7f5f7fe118b87fbc6a2c6cc52aff808564d907a4
|
|
|
4f2874 |
Author: Todd Vierling <todd.vierling@oracle.com>
|
|
|
4f2874 |
Date: Fri Sep 19 10:32:55 2014 -0400
|
|
|
4f2874 |
|
|
|
4f2874 |
exportfs: Properly parse IPv6 literal strings with null termination
|
|
|
4f2874 |
|
|
|
4f2874 |
The original implementation was using strncpy() with a truncation
|
|
|
4f2874 |
length to an uninitialized stack buffer, leaving a string that
|
|
|
4f2874 |
was only null terminated by luck.
|
|
|
4f2874 |
|
|
|
4f2874 |
While here, change to use no-copy semantics (no extra buffer) to
|
|
|
4f2874 |
avoid buffer overflows altogether. exportfs already modifies argv
|
|
|
4f2874 |
contents elsewhere, so this doesn't break anything anew.
|
|
|
4f2874 |
|
|
|
4f2874 |
Fixes: 4663c648 (exportfs: Support raw IPv6 addresses with
|
|
|
4f2874 |
"client:/path")
|
|
|
4f2874 |
|
|
|
4f2874 |
Signed-off-by: Todd Vierling <todd.vierling@oracle.com>
|
|
|
4f2874 |
Reviewed-by: Chuck Lever <chuck.lever@oracle.com>
|
|
|
4f2874 |
Signed-off-by: Steve Dickson <steved@redhat.com>
|
|
|
4f2874 |
|
|
|
4f2874 |
diff --git a/utils/exportfs/exportfs.c b/utils/exportfs/exportfs.c
|
|
|
4f2874 |
index e7d1ac8..bdea12b 100644
|
|
|
4f2874 |
--- a/utils/exportfs/exportfs.c
|
|
|
4f2874 |
+++ b/utils/exportfs/exportfs.c
|
|
|
4f2874 |
@@ -351,16 +351,15 @@ static int exportfs_generic(char *arg, char *options, int verbose)
|
|
|
4f2874 |
|
|
|
4f2874 |
static int exportfs_ipv6(char *arg, char *options, int verbose)
|
|
|
4f2874 |
{
|
|
|
4f2874 |
- char *path, *c, hname[NI_MAXHOST + strlen("/128")];
|
|
|
4f2874 |
+ char *path, *c;
|
|
|
4f2874 |
|
|
|
4f2874 |
arg++;
|
|
|
4f2874 |
c = strchr(arg, ']');
|
|
|
4f2874 |
if (c == NULL)
|
|
|
4f2874 |
return 1;
|
|
|
4f2874 |
- strncpy(hname, arg, c - arg);
|
|
|
4f2874 |
|
|
|
4f2874 |
/* no colon means this is a wildcarded DNS hostname */
|
|
|
4f2874 |
- if (strchr(hname, ':') == NULL)
|
|
|
4f2874 |
+ if (memchr(arg, ':', c - arg) == NULL)
|
|
|
4f2874 |
return exportfs_generic(--arg, options, verbose);
|
|
|
4f2874 |
|
|
|
4f2874 |
path = strstr(c, ":/");
|
|
|
4f2874 |
@@ -370,9 +369,9 @@ static int exportfs_ipv6(char *arg, char *options, int verbose)
|
|
|
4f2874 |
|
|
|
4f2874 |
/* if there's anything between the closing brace and the
|
|
|
4f2874 |
* path separator, it's probably a prefix length */
|
|
|
4f2874 |
- strcat(hname, ++c);
|
|
|
4f2874 |
+ memmove(c, c + 1, path - c);
|
|
|
4f2874 |
|
|
|
4f2874 |
- exportfs_parsed(hname, path, options, verbose);
|
|
|
4f2874 |
+ exportfs_parsed(arg, path, options, verbose);
|
|
|
4f2874 |
return 0;
|
|
|
4f2874 |
}
|
|
|
4f2874 |
|
|
|
4f2874 |
@@ -458,16 +457,15 @@ static int unexportfs_generic(char *arg, int verbose)
|
|
|
4f2874 |
|
|
|
4f2874 |
static int unexportfs_ipv6(char *arg, int verbose)
|
|
|
4f2874 |
{
|
|
|
4f2874 |
- char *path, *c, hname[NI_MAXHOST + strlen("/128")];
|
|
|
4f2874 |
+ char *path, *c;
|
|
|
4f2874 |
|
|
|
4f2874 |
arg++;
|
|
|
4f2874 |
c = strchr(arg, ']');
|
|
|
4f2874 |
if (c == NULL)
|
|
|
4f2874 |
return 1;
|
|
|
4f2874 |
- strncpy(hname, arg, c - arg);
|
|
|
4f2874 |
|
|
|
4f2874 |
/* no colon means this is a wildcarded DNS hostname */
|
|
|
4f2874 |
- if (strchr(hname, ':') == NULL)
|
|
|
4f2874 |
+ if (memchr(arg, ':', c - arg) == NULL)
|
|
|
4f2874 |
return unexportfs_generic(--arg, verbose);
|
|
|
4f2874 |
|
|
|
4f2874 |
path = strstr(c, ":/");
|
|
|
4f2874 |
@@ -477,9 +475,9 @@ static int unexportfs_ipv6(char *arg, int verbose)
|
|
|
4f2874 |
|
|
|
4f2874 |
/* if there's anything between the closing brace and the
|
|
|
4f2874 |
* path separator, it's probably a prefix length */
|
|
|
4f2874 |
- strcat(hname, ++c);
|
|
|
4f2874 |
+ memmove(c, c + 1, path - c);
|
|
|
4f2874 |
|
|
|
4f2874 |
- unexportfs_parsed(hname, path, verbose);
|
|
|
4f2874 |
+ unexportfs_parsed(arg, path, verbose);
|
|
|
4f2874 |
return 0;
|
|
|
4f2874 |
}
|
|
|
4f2874 |
|