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

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