4d64abc
commit 50ef80739d9e1e0df6616289ef2ff626a94666ee
4d64abc
Author: Steve Dickson <steved@redhat.com>
4d64abc
Date:   Thu May 23 09:24:49 2019 -0400
4d64abc
4d64abc
    rpc.mountd: Fix e_hostname and e_uuid leaks
4d64abc
    
4d64abc
    strdup of exportent uuid and hostname in getexportent() ends up leaking
4d64abc
    memory. Free the memory before getexportent() is called again from xtab_read()
4d64abc
    
4d64abc
    Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1713360
4d64abc
    Signed-off-by: Nikhil Kshirsagar <nkshirsa@redhat.com>
4d64abc
    Signed-off-by: Steve Dickson <steved@redhat.com>
4d64abc
4d64abc
diff --git a/support/export/xtab.c b/support/export/xtab.c
4d64abc
index d42eeef..1e1d679 100644
4d64abc
--- a/support/export/xtab.c
4d64abc
+++ b/support/export/xtab.c
4d64abc
@@ -50,6 +50,14 @@ xtab_read(char *xtab, char *lockfn, int is_export)
4d64abc
 	while ((xp = getexportent(is_export==0, 0)) != NULL) {
4d64abc
 		if (!(exp = export_lookup(xp->e_hostname, xp->e_path, is_export != 1)) &&
4d64abc
 		    !(exp = export_create(xp, is_export!=1))) {
4d64abc
+                        if(xp->e_hostname) {
4d64abc
+                            free(xp->e_hostname);
4d64abc
+                            xp->e_hostname=NULL;
4d64abc
+                        }
4d64abc
+                        if(xp->e_uuid) {
4d64abc
+                            free(xp->e_uuid);
4d64abc
+                            xp->e_uuid=NULL;
4d64abc
+                        }
4d64abc
 			continue;
4d64abc
 		}
4d64abc
 		switch (is_export) {
4d64abc
@@ -62,7 +70,16 @@ xtab_read(char *xtab, char *lockfn, int is_export)
4d64abc
 			if ((xp->e_flags & NFSEXP_FSID) && xp->e_fsid == 0)
4d64abc
 				v4root_needed = 0;
4d64abc
 			break;
4d64abc
-		}
4d64abc
+		}  
4d64abc
+                if(xp->e_hostname) {
4d64abc
+                    free(xp->e_hostname);
4d64abc
+                    xp->e_hostname=NULL;
4d64abc
+                }
4d64abc
+                if(xp->e_uuid) {
4d64abc
+                    free(xp->e_uuid);
4d64abc
+                    xp->e_uuid=NULL;
4d64abc
+                }
4d64abc
+
4d64abc
 	}
4d64abc
 	endexportent();
4d64abc
 	xfunlock(lockid);
4d64abc
diff --git a/support/nfs/exports.c b/support/nfs/exports.c
4d64abc
index 5f4cb95..a7582ca 100644
4d64abc
--- a/support/nfs/exports.c
4d64abc
+++ b/support/nfs/exports.c
4d64abc
@@ -179,9 +179,20 @@ getexportent(int fromkernel, int fromexports)
4d64abc
 	}
4d64abc
 	ee.e_hostname = xstrdup(hostname);
4d64abc
 
4d64abc
-	if (parseopts(opt, &ee, fromexports && !has_default_subtree_opts, NULL) < 0)
4d64abc
-		return NULL;
4d64abc
+	if (parseopts(opt, &ee, fromexports && !has_default_subtree_opts, NULL) < 0) {
4d64abc
+                if(ee.e_hostname)
4d64abc
+                {
4d64abc
+                    xfree(ee.e_hostname);
4d64abc
+                    ee.e_hostname=NULL;
4d64abc
+                }
4d64abc
+                if(ee.e_uuid)
4d64abc
+                {
4d64abc
+                    xfree(ee.e_uuid);
4d64abc
+                    ee.e_uuid=NULL;
4d64abc
+                }
4d64abc
 
4d64abc
+		return NULL;
4d64abc
+        }
4d64abc
 	/* resolve symlinks */
4d64abc
 	if (realpath(ee.e_path, rpath) != NULL) {
4d64abc
 		rpath[sizeof (rpath) - 1] = '\0';