Blame SOURCES/nfs-utils-2.3.3-mountd-memleak.patch

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