Skip to contentSkip to conversation

check for a negative return from is_local_mount

PATCH New Jeff Moyer 1 participant 1 message Nov 2, 2006 Kernel automounter

lore
Share & tools
lore

Jeff Moyer

author
#0 lore raw

PATCH 1/1 check for a negative return from is_local_mount

Hi, Ian, list,

get_best_mount is documented as returning the following:

return -1 and what = '\0' on error,
1 and what = local mount path if local bind,
else 0 and what = remote mount path

However, we get the return values incorrect in one case:

get_best_mount():

		if (is_local_mount(p) > 0) {
			debug(MODPREFIX "host %s: is localhost", p);

			/* Strip off hostname and ':' */
			delim = strchr(p,':');
			while (delim && *delim != '\0') {
				delim++;
				*what = *delim;
				what++;
			}
			return 1;
		}

		return 0;

is_local_mount can return -1 if there is a host name lookup failure. However, we don't check for the negative return value, and hence return 0 (success) when we shouldn't. When using /net, this actually results in an attempt to perform a bind mount of the directory to itself! Before the kernel patch went in to prevent infinite recursions of this type, it would end up panicking the system.

The fix is much simpler than the explanation. Review/comments appreciated.

Thanks,

Jeff

modules/mount_nfs.c +8 -3
index 8bede48..7d46a86 100644
@@ -187,6 +187,8 @@ int get_best_mount(char *what, const cha
 	 *  do anything except strip whitespace from the end of the string.
 	 */
 	if (!strchr(p, ',') && (strchr(p,':') == strrchr(p,':'))) {
+		int ret;
+
 		for (pstrip = p+strlen(p) - 1; pstrip >= p; pstrip--) {
 			if (!isspace(*pstrip))
 				break;
@@ -194,7 +196,8 @@ int get_best_mount(char *what, const cha
 		}
 
 		/* Check if the host is the localhost */
-		if (is_local_mount(p) > 0) {
+		ret = is_local_mount(p);
+		if (ret > 0) {
 			debug(MODPREFIX "host %s: is localhost", p);
 
 			/* Strip off hostname and ':' */
@@ -205,8 +208,10 @@ int get_best_mount(char *what, const cha
 				what++;
 			}
 			return 1;
-		}
-		return 0;
+		} else if (ret < 0)
+			*what = '\0';
+
+		return ret;
 	}
 
 	while (p && *p) {