Blame SOURCES/nfs-utils-1.3.0-exportfs-ipv6-arg.patch

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