6bbd11
autofs-5.0.8 - fix options compare
6bbd11
6bbd11
From: Ian Kent <raven@themaw.net>
6bbd11
6bbd11
When checking for options in mount locations incorrect matches
6bbd11
can occur when the length of the option string is not also used
6bbd11
for the check.
6bbd11
---
6bbd11
 CHANGELOG              |    1 +
6bbd11
 include/automount.h    |    1 +
6bbd11
 lib/cat_path.c         |    9 +++++++++
6bbd11
 modules/mount_autofs.c |   12 ++++++------
6bbd11
 modules/mount_bind.c   |    2 +-
6bbd11
 modules/mount_ext2.c   |    2 +-
6bbd11
 modules/mount_nfs.c    |   34 +++++++++++++++++-----------------
6bbd11
 modules/parse_sun.c    |   20 ++++++++++----------
6bbd11
 8 files changed, 46 insertions(+), 35 deletions(-)
6bbd11
6bbd11
--- autofs-5.0.7.orig/CHANGELOG
6bbd11
+++ autofs-5.0.7/CHANGELOG
6bbd11
@@ -73,6 +73,7 @@
6bbd11
 - fix negative status being reset on map read.
6bbd11
 - fix fix negative status being reset on map read.
6bbd11
 - check for non existent negative entries in lookup_ghost().
6bbd11
+- fix options compare.
6bbd11
 
6bbd11
 25/07/2012 autofs-5.0.7
6bbd11
 =======================
6bbd11
--- autofs-5.0.7.orig/include/automount.h
6bbd11
+++ autofs-5.0.7/include/automount.h
6bbd11
@@ -335,6 +335,7 @@ size_t _strlen(const char *str, size_t m
6bbd11
 int cat_path(char *buf, size_t len, const char *dir, const char *base);
6bbd11
 int ncat_path(char *buf, size_t len,
6bbd11
               const char *dir, const char *base, size_t blen);
6bbd11
+int _strncmp(const char *s1, const char *s2, size_t n);
6bbd11
 
6bbd11
 /* Core automount definitions */
6bbd11
 
6bbd11
--- autofs-5.0.7.orig/lib/cat_path.c
6bbd11
+++ autofs-5.0.7/lib/cat_path.c
6bbd11
@@ -87,3 +87,12 @@ int ncat_path(char *buf, size_t len,
6bbd11
 	return cat_path(buf, len, dir, name);
6bbd11
 }
6bbd11
 
6bbd11
+/* Compare first n bytes of s1 and s2 and that n == strlen(s1) */
6bbd11
+int _strncmp(const char *s1, const char *s2, size_t n)
6bbd11
+{
6bbd11
+	size_t len = strlen(s1);
6bbd11
+
6bbd11
+	if (n != len)
6bbd11
+		return n - len;
6bbd11
+	return strncmp(s1, s2, n);
6bbd11
+}
6bbd11
--- autofs-5.0.7.orig/modules/mount_autofs.c
6bbd11
+++ autofs-5.0.7/modules/mount_autofs.c
6bbd11
@@ -116,17 +116,17 @@ int mount_mount(struct autofs_point *ap,
6bbd11
 			while (*comma != '\0' && *comma != ',')
6bbd11
 				comma++;
6bbd11
 
6bbd11
-			if (strncmp(cp, "nobrowse", 8) == 0)
6bbd11
+			if (_strncmp(cp, "nobrowse", 8) == 0)
6bbd11
 				ghost = 0;
6bbd11
-			else if (strncmp(cp, "nobind", 6) == 0)
6bbd11
+			else if (_strncmp(cp, "nobind", 6) == 0)
6bbd11
 				nobind = 1;
6bbd11
-			else if (strncmp(cp, "browse", 6) == 0)
6bbd11
+			else if (_strncmp(cp, "browse", 6) == 0)
6bbd11
 				ghost = 1;
6bbd11
-			else if (strncmp(cp, "symlink", 7) == 0)
6bbd11
+			else if (_strncmp(cp, "symlink", 7) == 0)
6bbd11
 				symlnk = 1;
6bbd11
-			else if (strncmp(cp, "hosts", 5) == 0)
6bbd11
+			else if (_strncmp(cp, "hosts", 5) == 0)
6bbd11
 				hosts = 1;
6bbd11
-			else if (strncmp(cp, "timeout=", 8) == 0) {
6bbd11
+			else if (_strncmp(cp, "timeout=", 8) == 0) {
6bbd11
 				char *val = strchr(cp, '=');
6bbd11
 				unsigned tout;
6bbd11
 				if (val) {
6bbd11
--- autofs-5.0.7.orig/modules/mount_bind.c
6bbd11
+++ autofs-5.0.7/modules/mount_bind.c
6bbd11
@@ -107,7 +107,7 @@ int mount_mount(struct autofs_point *ap,
6bbd11
 				end--;
6bbd11
 
6bbd11
 			o_len = end - cp + 1;
6bbd11
-			if (strncmp("symlink", cp, o_len) == 0)
6bbd11
+			if (_strncmp("symlink", cp, o_len) == 0)
6bbd11
 				symlnk = 1;
6bbd11
 		}
6bbd11
 	}
6bbd11
--- autofs-5.0.7.orig/modules/mount_ext2.c
6bbd11
+++ autofs-5.0.7/modules/mount_ext2.c
6bbd11
@@ -77,7 +77,7 @@ int mount_mount(struct autofs_point *ap,
6bbd11
 
6bbd11
 	if (options && options[0]) {
6bbd11
 		for (p = options; (p1 = strchr(p, ',')); p = p1)
6bbd11
-			if (!strncmp(p, "ro", p1 - p) && ++p1 - p == sizeof("ro"))
6bbd11
+			if (!_strncmp(p, "ro", p1 - p) && ++p1 - p == sizeof("ro"))
6bbd11
 				ro = 1;
6bbd11
 		if (!strcmp(p, "ro"))
6bbd11
 			ro = 1;
6bbd11
--- autofs-5.0.7.orig/modules/mount_nfs.c
6bbd11
+++ autofs-5.0.7/modules/mount_nfs.c
6bbd11
@@ -126,32 +126,32 @@ int mount_mount(struct autofs_point *ap,
6bbd11
 
6bbd11
 			o_len = end - cp + 1;
6bbd11
 
6bbd11
-			if (strncmp("proto=rdma", cp, o_len) == 0 ||
6bbd11
-				   strncmp("rdma", cp, o_len) == 0)
6bbd11
+			if (_strncmp("proto=rdma", cp, o_len) == 0 ||
6bbd11
+				   _strncmp("rdma", cp, o_len) == 0)
6bbd11
 				rdma = 1;
6bbd11
 
6bbd11
-			if (strncmp("nosymlink", cp, o_len) == 0) {
6bbd11
+			if (_strncmp("nosymlink", cp, o_len) == 0) {
6bbd11
 				warn(ap->logopt, MODPREFIX
6bbd11
 				     "the \"nosymlink\" option is depricated "
6bbd11
 				     "and will soon be removed, "
6bbd11
 				     "use the \"nobind\" option instead");
6bbd11
 				nosymlink = 1;
6bbd11
-			} else if (strncmp("nobind", cp, o_len) == 0) {
6bbd11
+			} else if (_strncmp("nobind", cp, o_len) == 0) {
6bbd11
 				nobind = 1;
6bbd11
-			} else if (strncmp("no-use-weight-only", cp, o_len) == 0) {
6bbd11
+			} else if (_strncmp("no-use-weight-only", cp, o_len) == 0) {
6bbd11
 				flags &= ~MOUNT_FLAG_USE_WEIGHT_ONLY;
6bbd11
-			} else if (strncmp("use-weight-only", cp, o_len) == 0) {
6bbd11
+			} else if (_strncmp("use-weight-only", cp, o_len) == 0) {
6bbd11
 				flags |= MOUNT_FLAG_USE_WEIGHT_ONLY;
6bbd11
 			} else {
6bbd11
-				if (strncmp("vers=4", cp, o_len) == 0 ||
6bbd11
-				    strncmp("nfsvers=4", cp, o_len) == 0)
6bbd11
+				if (_strncmp("vers=4", cp, o_len) == 0 ||
6bbd11
+				    _strncmp("nfsvers=4", cp, o_len) == 0)
6bbd11
 					vers = NFS4_VERS_MASK | TCP_SUPPORTED;
6bbd11
-				else if (strncmp("vers=3", cp, o_len) == 0 ||
6bbd11
-					 strncmp("nfsvers=3", cp, o_len) == 0) {
6bbd11
+				else if (_strncmp("vers=3", cp, o_len) == 0 ||
6bbd11
+					 _strncmp("nfsvers=3", cp, o_len) == 0) {
6bbd11
 					vers &= ~(NFS4_VERS_MASK | NFS_VERS_MASK);
6bbd11
 					vers |= NFS3_REQUESTED;
6bbd11
-				} else if (strncmp("vers=2", cp, o_len) == 0 ||
6bbd11
-					 strncmp("nfsvers=2", cp, o_len) == 0) {
6bbd11
+				} else if (_strncmp("vers=2", cp, o_len) == 0 ||
6bbd11
+					 _strncmp("nfsvers=2", cp, o_len) == 0) {
6bbd11
 					vers &= ~(NFS4_VERS_MASK | NFS_VERS_MASK);
6bbd11
 					vers |= NFS2_REQUESTED;
6bbd11
 				} else if (strstr(cp, "port=") == cp &&
6bbd11
@@ -164,16 +164,16 @@ int mount_mount(struct autofs_point *ap,
6bbd11
 					if (port < 0)
6bbd11
 						port = 0;
6bbd11
 					port_opt = cp;
6bbd11
-				} else if (strncmp("proto=udp", cp, o_len) == 0 ||
6bbd11
-					   strncmp("udp", cp, o_len) == 0) {
6bbd11
+				} else if (_strncmp("proto=udp", cp, o_len) == 0 ||
6bbd11
+					   _strncmp("udp", cp, o_len) == 0) {
6bbd11
 					vers &= ~TCP_SUPPORTED;
6bbd11
-				} else if (strncmp("proto=tcp", cp, o_len) == 0 ||
6bbd11
-					   strncmp("tcp", cp, o_len) == 0) {
6bbd11
+				} else if (_strncmp("proto=tcp", cp, o_len) == 0 ||
6bbd11
+					   _strncmp("tcp", cp, o_len) == 0) {
6bbd11
 					vers &= ~UDP_SUPPORTED;
6bbd11
 				}
6bbd11
 				/* Check for options that also make sense
6bbd11
 				   with bind mounts */
6bbd11
-				else if (strncmp("ro", cp, o_len) == 0)
6bbd11
+				else if (_strncmp("ro", cp, o_len) == 0)
6bbd11
 					ro = 1;
6bbd11
 				/* and jump over trailing white space */
6bbd11
 				memcpy(nfsp, cp, comma - cp + 1);
6bbd11
--- autofs-5.0.7.orig/modules/parse_sun.c
6bbd11
+++ autofs-5.0.7/modules/parse_sun.c
6bbd11
@@ -549,29 +549,29 @@ static int sun_mount(struct autofs_point
6bbd11
 			while (*comma != '\0' && *comma != ',')
6bbd11
 				comma++;
6bbd11
 
6bbd11
-			if (strncmp("fstype=", cp, 7) == 0) {
6bbd11
+			if (_strncmp("fstype=", cp, 7) == 0) {
6bbd11
 				int typelen = comma - (cp + 7);
6bbd11
 				fstype = alloca(typelen + 1);
6bbd11
 				memcpy(fstype, cp + 7, typelen);
6bbd11
 				fstype[typelen] = '\0';
6bbd11
-			} else if (strncmp("nonstrict", cp, 9) == 0) {
6bbd11
+			} else if (_strncmp("nonstrict", cp, 9) == 0) {
6bbd11
 				nonstrict = 1;
6bbd11
-			} else if (strncmp("strict", cp, 6) == 0) {
6bbd11
+			} else if (_strncmp("strict", cp, 6) == 0) {
6bbd11
 				nonstrict = 0;
6bbd11
-			} else if (strncmp("nobrowse", cp, 8) == 0 ||
6bbd11
-				   strncmp("browse", cp, 6) == 0 ||
6bbd11
-				   strncmp("timeout=", cp, 8) == 0) {
6bbd11
+			} else if (_strncmp("nobrowse", cp, 8) == 0 ||
6bbd11
+				   _strncmp("browse", cp, 6) == 0 ||
6bbd11
+				   _strncmp("timeout=", cp, 8) == 0) {
6bbd11
 				if (strcmp(fstype, "autofs") == 0 ||
6bbd11
 				    strstr(cp, "fstype=autofs")) {
6bbd11
 					memcpy(np, cp, comma - cp + 1);
6bbd11
 					np += comma - cp + 1;
6bbd11
 				}
6bbd11
-			} else if (strncmp("no-use-weight-only", cp, 18) == 0) {
6bbd11
+			} else if (_strncmp("no-use-weight-only", cp, 18) == 0) {
6bbd11
 				use_weight_only = -1;
6bbd11
-			} else if (strncmp("use-weight-only", cp, 15) == 0) {
6bbd11
+			} else if (_strncmp("use-weight-only", cp, 15) == 0) {
6bbd11
 				use_weight_only = MOUNT_FLAG_USE_WEIGHT_ONLY;
6bbd11
-			} else if (strncmp("bg", cp, 2) == 0 ||
6bbd11
-				   strncmp("nofg", cp, 4) == 0) {
6bbd11
+			} else if (_strncmp("bg", cp, 2) == 0 ||
6bbd11
+				   _strncmp("nofg", cp, 4) == 0) {
6bbd11
 				continue;
6bbd11
 			} else {
6bbd11
 				memcpy(np, cp, comma - cp + 1);