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

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