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