autofs/SOURCES/autofs-5.1.4-add-error-hand...

122 lines
3.6 KiB
Diff

autofs-5.1.4 - add error handling for ext_mount_add()
From: Ian Kent <raven@themaw.net>
Add error handling (memory allocation failures) for ext_mount_add().
Signed-off-by: Ian Kent <raven@themaw.net>
---
CHANGELOG | 1 +
lib/mounts.c | 5 +----
modules/parse_amd.c | 42 ++++++++++++++++++++++++++++++------------
3 files changed, 32 insertions(+), 16 deletions(-)
diff --git a/CHANGELOG b/CHANGELOG
index d0cfa19b..9d19c0a7 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -7,6 +7,7 @@ xx/xx/2018 autofs-5.1.5
- fix prefix option handling in expand_entry().
- fix sublink option not set from defaults.
- fix error return in do_nfs_mount().
+- add error handling for ext_mount_add().
19/12/2017 autofs-5.1.4
- fix spec file url.
diff --git a/lib/mounts.c b/lib/mounts.c
index 6fa304aa..f46fab2b 100644
--- a/lib/mounts.c
+++ b/lib/mounts.c
@@ -715,15 +715,12 @@ int ext_mount_add(struct list_head *entry, const char *path, unsigned int umount
}
em = malloc(sizeof(struct ext_mount));
- if (!em) {
- ret = -1;
+ if (!em)
goto done;
- }
em->mountpoint = strdup(path);
if (!em->mountpoint) {
free(em);
- ret = -1;
goto done;
}
em->umount = umount;
diff --git a/modules/parse_amd.c b/modules/parse_amd.c
index 2a5d9a30..e7debc56 100644
--- a/modules/parse_amd.c
+++ b/modules/parse_amd.c
@@ -1080,7 +1080,14 @@ static int do_generic_mount(struct autofs_point *ap, const char *name,
umount = 1;
}
/* We have an external mount */
- ext_mount_add(&entry->ext_mount, entry->fs, umount);
+ if (!ext_mount_add(&entry->ext_mount, entry->fs, umount)) {
+ umount_ent(ap, entry->fs);
+ error(ap->logopt, MODPREFIX
+ "error: could not add external mount %s",
+ entry->fs);
+ ret = 1;
+ goto out;
+ }
ret = do_link_mount(ap, name, entry, flags);
}
out:
@@ -1124,7 +1131,13 @@ static int do_nfs_mount(struct autofs_point *ap, const char *name,
umount = 1;
}
/* We might be using an external mount */
- ext_mount_add(&entry->ext_mount, entry->fs, umount);
+ if (!ext_mount_add(&entry->ext_mount, entry->fs, umount)) {
+ umount_ent(ap, entry->fs);
+ error(ap->logopt, MODPREFIX
+ "error: could not add external mount %s", entry->fs);
+ ret = 1;
+ goto out;
+ }
ret = do_link_mount(ap, name, entry, flags);
}
out:
@@ -1309,6 +1322,9 @@ static int do_program_mount(struct autofs_point *ap,
*/
if (ext_mount_inuse(entry->fs)) {
rv = 0;
+ /* An external mount with path entry->fs exists
+ * so ext_mount_add() won't fail.
+ */
ext_mount_add(&entry->ext_mount, entry->fs, 1);
} else {
rv = mkdir_path(entry->fs, mp_mode);
@@ -1325,17 +1341,19 @@ static int do_program_mount(struct autofs_point *ap,
rv = spawnv(ap->logopt, prog, (const char * const *) argv);
if (WIFEXITED(rv) && !WEXITSTATUS(rv)) {
- rv = 0;
- ext_mount_add(&entry->ext_mount, entry->fs, 1);
- debug(ap->logopt, MODPREFIX
- "%s: mounted %s", entry->type, entry->fs);
- } else {
- if (!ext_mount_inuse(entry->fs))
- rmdir_path(ap, entry->fs, ap->dev);
- error(ap->logopt, MODPREFIX
- "%s: failed to mount using: %s",
- entry->type, entry->mount);
+ if (ext_mount_add(&entry->ext_mount, entry->fs, 1)) {
+ rv = 0;
+ debug(ap->logopt, MODPREFIX
+ "%s: mounted %s", entry->type, entry->fs);
+ goto do_free;
+ }
+ umount_ent(ap, entry->fs);
}
+
+ if (!ext_mount_inuse(entry->fs))
+ rmdir_path(ap, entry->fs, ap->dev);
+ error(ap->logopt, MODPREFIX
+ "%s: failed to mount using %s", entry->type, entry->mount);
}
do_free:
free_argv(argc, (const char **) argv);