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