Blame SOURCES/autofs-5.1.5-use-malloc-in-spawn_c.patch

135b98
autofs-5.1.5 - use malloc(3) in spawn.c
135b98
135b98
From: Ian Kent <raven@themaw.net>
135b98
135b98
Use malloc(3) in spawn.c functions instead of alloca(3) as a failure
135b98
return for this function is undefined.
135b98
135b98
Signed-off-by: Ian Kent <raven@themaw.net>
135b98
---
135b98
 CHANGELOG      |    1 +
135b98
 daemon/spawn.c |   50 ++++++++++++++++++++++++++++++++++++++++++++------
135b98
 2 files changed, 45 insertions(+), 6 deletions(-)
135b98
135b98
--- autofs-5.1.4.orig/CHANGELOG
135b98
+++ autofs-5.1.4/CHANGELOG
135b98
@@ -46,6 +46,7 @@ xx/xx/2018 autofs-5.1.5
135b98
 - add systemd service command line option.
135b98
 - support strictexpire mount option.
135b98
 - add NULL check for get_addr_string() return.
135b98
+- use malloc(3) in spawn.c.
135b98
 
135b98
 19/12/2017 autofs-5.1.4
135b98
 - fix spec file url.
135b98
--- autofs-5.1.4.orig/daemon/spawn.c
135b98
+++ autofs-5.1.4/daemon/spawn.c
135b98
@@ -521,22 +521,33 @@ int spawnv(unsigned logopt, const char *
135b98
 int spawnl(unsigned logopt, const char *prog, ...)
135b98
 {
135b98
 	va_list arg;
135b98
-	int argc;
135b98
+	int argc, ret;
135b98
 	char **argv, **p;
135b98
+	unsigned int argv_len;
135b98
 
135b98
 	va_start(arg, prog);
135b98
 	for (argc = 1; va_arg(arg, char *); argc++);
135b98
 	va_end(arg);
135b98
 
135b98
-	if (!(argv = alloca(sizeof(char *) * argc)))
135b98
+	argv_len = sizeof(char *) * (argc + 1);
135b98
+	argv = malloc(argv_len);
135b98
+	if (!argv) {
135b98
+		char buf[MAX_ERR_BUF];
135b98
+		char *estr = strerror_r(errno, buf, sizeof(buf));
135b98
+		crit(logopt, "malloc: %s", estr);
135b98
 		return -1;
135b98
+	}
135b98
+	memset(argv, 0, argv_len);
135b98
 
135b98
 	va_start(arg, prog);
135b98
 	p = argv;
135b98
 	while ((*p++ = va_arg(arg, char *)));
135b98
 	va_end(arg);
135b98
 
135b98
-	return do_spawn(logopt, -1, SPAWN_OPT_NONE, prog, (const char **) argv);
135b98
+	ret = do_spawn(logopt, -1, SPAWN_OPT_NONE, prog, (const char **) argv);
135b98
+	free(argv);
135b98
+
135b98
+	return ret;
135b98
 }
135b98
 
135b98
 int spawn_mount(unsigned logopt, ...)
135b98
@@ -554,6 +565,7 @@ int spawn_mount(unsigned logopt, ...)
135b98
 	int update_mtab = 1, ret, printed = 0;
135b98
 	unsigned int wait = defaults_get_mount_wait();
135b98
 	char buf[PATH_MAX + 1];
135b98
+	unsigned int argv_len;
135b98
 
135b98
 	/* If we use mount locking we can't validate the location */
135b98
 #ifdef ENABLE_MOUNT_LOCKING
135b98
@@ -579,8 +591,15 @@ int spawn_mount(unsigned logopt, ...)
135b98
 	}
135b98
 
135b98
 	/* Alloc 1 extra slot in case we need to use the "-f" option */
135b98
-	if (!(argv = alloca(sizeof(char *) * (argc + 2))))
135b98
+	argv_len = sizeof(char *) * (argc + 2);
135b98
+	argv = malloc(argv_len);
135b98
+	if (!argv) {
135b98
+		char buf[MAX_ERR_BUF];
135b98
+		char *estr = strerror_r(errno, buf, sizeof(buf));
135b98
+		crit(logopt, "malloc: %s", estr);
135b98
 		return -1;
135b98
+	}
135b98
+	memset(argv, 0, argv_len);
135b98
 
135b98
 	argv[0] = arg0;
135b98
 
135b98
@@ -655,6 +674,7 @@ int spawn_mount(unsigned logopt, ...)
135b98
 		umount(argv[argc]);
135b98
 		ret = MNT_FORCE_FAIL;
135b98
 	}
135b98
+	free(argv);
135b98
 
135b98
 	return ret;
135b98
 }
135b98
@@ -683,6 +703,7 @@ int spawn_bind_mount(unsigned logopt, ..
135b98
 	int update_mtab = 1, ret, printed = 0;
135b98
 	unsigned int wait = defaults_get_mount_wait();
135b98
 	char buf[PATH_MAX + 1];
135b98
+	unsigned int argv_len;
135b98
 
135b98
 	/* If we use mount locking we can't validate the location */
135b98
 #ifdef ENABLE_MOUNT_LOCKING
135b98
@@ -711,8 +732,15 @@ int spawn_bind_mount(unsigned logopt, ..
135b98
 		}
135b98
 	}
135b98
 
135b98
-	if (!(argv = alloca(sizeof(char *) * (argc + 2))))
135b98
+	argv_len = sizeof(char *) * (argc + 2);
135b98
+	argv = malloc(argv_len);
135b98
+	if (!argv) {
135b98
+		char buf[MAX_ERR_BUF];
135b98
+		char *estr = strerror_r(errno, buf, sizeof(buf));
135b98
+		crit(logopt, "malloc: %s", estr);
135b98
 		return -1;
135b98
+	}
135b98
+	memset(argv, 0, argv_len);
135b98
 
135b98
 	argv[0] = arg0;
135b98
 	argv[1] = bind;
135b98
@@ -774,6 +802,7 @@ int spawn_bind_mount(unsigned logopt, ..
135b98
 		umount(argv[argc]);
135b98
 		ret = MNT_FORCE_FAIL;
135b98
 	}
135b98
+	free(argv);
135b98
 
135b98
 	return ret;
135b98
 }
135b98
@@ -796,6 +825,7 @@ int spawn_umount(unsigned logopt, ...)
135b98
 	int update_mtab = 1, ret, printed = 0;
135b98
 	unsigned int wait = defaults_get_umount_wait();
135b98
 	char buf[PATH_MAX + 1];
135b98
+	unsigned int argv_len;
135b98
 
135b98
 #ifdef ENABLE_MOUNT_LOCKING
135b98
 	options = SPAWN_OPT_LOCK;
135b98
@@ -821,8 +851,15 @@ int spawn_umount(unsigned logopt, ...)
135b98
 	if (arg_c)
135b98
 		argc++;;
135b98
 
135b98
-	if (!(argv = alloca(sizeof(char *) * (argc + 1))))
135b98
+	argv_len = sizeof(char *) * (argc + 1);
135b98
+	argv = malloc(argv_len);
135b98
+	if (!argv) {
135b98
+		char buf[MAX_ERR_BUF];
135b98
+		char *estr = strerror_r(errno, buf, sizeof(buf));
135b98
+		crit(logopt, "malloc: %s", estr);
135b98
 		return -1;
135b98
+	}
135b98
+	memset(argv, 0, argv_len);
135b98
 
135b98
 	p = argv;
135b98
 	*p++ = arg0;
135b98
@@ -870,6 +907,7 @@ int spawn_umount(unsigned logopt, ...)
135b98
 		     "and /etc/mtab will differ");
135b98
 		ret = 0;
135b98
 	}
135b98
+	free(argv);
135b98
 
135b98
 	return ret;
135b98
 }