Blame SOURCES/autofs-5.0.7-fix-several-off-by-one-errors.patch

304803
autofs-5.0.7 - fix several off by one errors
304803
304803
From: Ian Kent <raven@themaw.net>
304803
304803
Fix several off-by-one array reference errors and a couple of short allocation
304803
errors.
304803
---
304803
 daemon/spawn.c         |   10 +++++-----
304803
 lib/defaults.c         |    2 +-
304803
 modules/lookup_ldap.c  |    8 ++++----
304803
 modules/parse_hesiod.c |    2 +-
304803
 modules/parse_sun.c    |    2 +-
304803
 5 files changed, 12 insertions(+), 12 deletions(-)
304803
304803
diff --git a/daemon/spawn.c b/daemon/spawn.c
304803
index 3b4a009..9b8d5a2 100644
304803
--- a/daemon/spawn.c
304803
+++ b/daemon/spawn.c
304803
@@ -320,7 +320,7 @@ int spawn_mount(unsigned logopt, ...)
304803
 	unsigned int retries = MTAB_LOCK_RETRIES;
304803
 	int update_mtab = 1, ret, printed = 0;
304803
 	unsigned int wait = defaults_get_mount_wait();
304803
-	char buf[PATH_MAX];
304803
+	char buf[PATH_MAX + 1];
304803
 
304803
 	/* If we use mount locking we can't validate the location */
304803
 #ifdef ENABLE_MOUNT_LOCKING
304803
@@ -346,7 +346,7 @@ int spawn_mount(unsigned logopt, ...)
304803
 	}
304803
 
304803
 	/* Alloc 1 extra slot in case we need to use the "-f" option */
304803
-	if (!(argv = alloca(sizeof(char *) * argc + 2)))
304803
+	if (!(argv = alloca(sizeof(char *) * (argc + 2))))
304803
 		return -1;
304803
 
304803
 	argv[0] = arg0;
304803
@@ -448,7 +448,7 @@ int spawn_bind_mount(unsigned logopt, ...)
304803
 	unsigned int options;
304803
 	unsigned int retries = MTAB_LOCK_RETRIES;
304803
 	int update_mtab = 1, ret, printed = 0;
304803
-	char buf[PATH_MAX];
304803
+	char buf[PATH_MAX + 1];
304803
 
304803
 	/* If we use mount locking we can't validate the location */
304803
 #ifdef ENABLE_MOUNT_LOCKING
304803
@@ -477,7 +477,7 @@ int spawn_bind_mount(unsigned logopt, ...)
304803
 		}
304803
 	}
304803
 
304803
-	if (!(argv = alloca(sizeof(char *) * argc + 2)))
304803
+	if (!(argv = alloca(sizeof(char *) * (argc + 2))))
304803
 		return -1;
304803
 
304803
 	argv[0] = arg0;
304803
@@ -556,7 +556,7 @@ int spawn_umount(unsigned logopt, ...)
304803
 	unsigned int retries = MTAB_LOCK_RETRIES;
304803
 	int update_mtab = 1, ret, printed = 0;
304803
 	unsigned int wait = defaults_get_umount_wait();
304803
-	char buf[PATH_MAX];
304803
+	char buf[PATH_MAX + 1];
304803
 
304803
 #ifdef ENABLE_MOUNT_LOCKING
304803
 	options = SPAWN_OPT_LOCK;
304803
diff --git a/lib/defaults.c b/lib/defaults.c
304803
index ae1162f..1e89509 100644
304803
--- a/lib/defaults.c
304803
+++ b/lib/defaults.c
304803
@@ -227,7 +227,7 @@ void defaults_free_uris(struct list_head *list)
304803
 static unsigned int add_uris(char *value, struct list_head *list)
304803
 {
304803
 	char *str, *tok, *ptr = NULL;
304803
-	size_t len = strlen(value);
304803
+	size_t len = strlen(value) + 1;
304803
 
304803
 	str = alloca(len);
304803
 	if (!str)
304803
diff --git a/modules/lookup_ldap.c b/modules/lookup_ldap.c
304803
index 83e3215..17cbe9a 100644
304803
--- a/modules/lookup_ldap.c
304803
+++ b/modules/lookup_ldap.c
304803
@@ -2234,8 +2234,8 @@ static int do_get_entries(struct ldap_search_params *sp, struct map_source *sour
304803
 					mapent = new_me;
304803
 					strcat(mapent, " ");
304803
 					strncat(mapent, v_val, v_len);
304803
-					mapent[new_size] = '\0';
304803
-					mapent_len = new_size;
304803
+					mapent[new_size - 1] = '\0';
304803
+					mapent_len = new_size - 1;
304803
 				} else {
304803
 					char *estr;
304803
 					estr = strerror_r(errno, buf, sizeof(buf));
304803
@@ -2723,8 +2723,8 @@ static int lookup_one(struct autofs_point *ap,
304803
 					mapent = new_me;
304803
 					strcat(mapent, " ");
304803
 					strncat(mapent, v_val, v_len);
304803
-					mapent[new_size] = '\0';
304803
-					mapent_len = new_size;
304803
+					mapent[new_size - 1] = '\0';
304803
+					mapent_len = new_size - 1;
304803
 				} else {
304803
 					char *estr;
304803
 					estr = strerror_r(errno, buf, sizeof(buf));
304803
diff --git a/modules/parse_hesiod.c b/modules/parse_hesiod.c
304803
index 7a6a57d..237fd50 100644
304803
--- a/modules/parse_hesiod.c
304803
+++ b/modules/parse_hesiod.c
304803
@@ -117,7 +117,7 @@ static int parse_nfs(struct autofs_point *ap,
304803
 		p++;
304803
 
304803
 	/* Isolate the remote mountpoint for this NFS fs. */
304803
-	for (i = 0; (!isspace(p[i]) && i < (int) sizeof(mount)); i++) {
304803
+	for (i = 0; (!isspace(p[i]) && i < ((int) sizeof(mount) - 1)); i++) {
304803
 		if (!p[i]) {
304803
 			error(ap->logopt, MODPREFIX
304803
 			      "unexpeced end of input looking for NFS "
304803
diff --git a/modules/parse_sun.c b/modules/parse_sun.c
304803
index ae1caf7..c1fc528 100644
304803
--- a/modules/parse_sun.c
304803
+++ b/modules/parse_sun.c
304803
@@ -1135,7 +1135,7 @@ static int mount_subtree(struct autofs_point *ap, struct mapent *me,
304803
 			}
304803
 			ro_len = strlen(ro_loc);
304803
 
304803
-			tmp = alloca(mnt_root_len + 1);
304803
+			tmp = alloca(mnt_root_len + 2);
304803
 			strcpy(tmp, mnt_root);
304803
 			tmp[mnt_root_len] = '/';
304803
 			tmp[mnt_root_len + 1] = '\0';