autofs-5.1.9 - dont use alloca for nfsoptions

From: Ian Kent <raven@themaw.net>

In modules/mount_nfs.c don't use alloca() for nfsoptions.

Signed-off-by: Ian Kent <raven@themaw.net>
---
 CHANGELOG           |    1 +
 modules/mount_nfs.c |   14 +++++++++++++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/CHANGELOG b/CHANGELOG
index 04d70ed0f..57beddfc9 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -47,6 +47,7 @@
 - fix incorrect error handling in sasl_do_kinit_ext_cc().
 - fix off by one error in macro_init().
 - fix incorrect allocation in match_key().
+- dont use alloca for nfsoptions.
 
 02/11/2023 autofs-5.1.9
 - fix kernel mount status notification.
diff --git a/modules/mount_nfs.c b/modules/mount_nfs.c
index 34ec82225..57fb04d68 100644
--- a/modules/mount_nfs.c
+++ b/modules/mount_nfs.c
@@ -107,7 +107,7 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name, int
 		char *nfsp;
 		int o_len = strlen(options) + 1;
 
-		nfsp = nfsoptions = alloca(o_len + 1);
+		nfsp = nfsoptions = malloc(o_len + 1);
 		if (!nfsoptions)
 			return 1;
 
@@ -225,6 +225,8 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name, int
 
 	if (!parse_location(ap->logopt, &hosts, what, flags)) {
 		info(ap->logopt, MODPREFIX "no hosts available");
+		if (nfsoptions)
+			free(nfsoptions);
 		return 1;
 	}
 	/*
@@ -274,6 +276,8 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name, int
 dont_probe:
 	if (!hosts) {
 		info(ap->logopt, MODPREFIX "no hosts available");
+		if (nfsoptions)
+			free(nfsoptions);
 		return 1;
 	}
 
@@ -284,6 +288,8 @@ dont_probe:
 		char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
 		error(ap->logopt,
 		      MODPREFIX "mkdir_path %s failed: %s", fullpath, estr);
+		if (nfsoptions)
+			free(nfsoptions);
 		free_host_list(&hosts);
 		return 1;
 	}
@@ -313,6 +319,8 @@ dont_probe:
 
 			/* Success - we're done */
 			if (!err) {
+				if (nfsoptions)
+					free(nfsoptions);
 				free_host_list(&hosts);
 				return 0;
 			}
@@ -407,6 +415,8 @@ dont_probe:
 			         MODPREFIX "mounted %s type %s on %s",
 				 loc, fstype, fullpath);
 			free(loc);
+			if (nfsoptions)
+				free(nfsoptions);
 			free_host_list(&hosts);
 			return 0;
 		}
@@ -416,6 +426,8 @@ next:
 	}
 
 forced_fail:
+	if (nfsoptions)
+		free(nfsoptions);
 	free_host_list(&hosts);
 
 	/* If we get here we've failed to complete the mount */
