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

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