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