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