Re: [PATCH 06/26] statd: Introduce common routines to handle persistent storage

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On Oct 16, 2009, at 11:05 PM, Jeff Layton wrote:

On Tue, 13 Oct 2009 10:55:06 -0400
Chuck Lever <chuck.lever@xxxxxxxxxx> wrote:
+
+/*
+ * Stuff a 'struct mon' with callback data, and call @func.
+ *
+ * Returns the count of in-core records created.
+ */
+static unsigned int
+nsm_parse_line(const char *hostname, const time_t timestamp, char *line,
+		nsm_populate_t func)
+{
+	struct sockaddr_in sin = {
+		.sin_family	= AF_INET,
+	};
+	struct mon mon;
+	int count, i;
+	char *c;
+
+	c = strchr(line, '\n');
+	if (c)
+		*c = '\0';
+
+	count = sscanf(line, "%8x %8x %8x %8x ",
+			&sin.sin_addr.s_addr,
+			&mon.mon_id.my_id.my_prog,
+			&mon.mon_id.my_id.my_vers,
+			&mon.mon_id.my_id.my_proc);
+	if (count != 4)
+		return 0;
+
+	c = line + 36;
+	for (i = 0; i < SM_PRIV_SIZE; i++) {
+		unsigned int tmp;
+		if (sscanf(c, "%2x", &tmp) != 1)
+			return 0;
+		mon.priv[i] = tmp;
+		c += 2;
+	}
+

^^^
I think we need some bounds checking here. There doesn't seem to be any
guarantee that the line we read in from the "db" is a particular
length. A check to verify that before trying to convert the cookie
would be good.

You mean the line read from the file is possibly not long enough? I think sscanf(3) will bail and we'll hit the "return 0;" if it can't find enough bytes in the cookie. It would be worth adding a specific test or two for short db lines in the nascent statd regression/unit test suite.

However, any new checks we want in this particular spot should probably be added by subsequent patches (ie after the IPv6 support series is committed), so we can verify that the IPv6 changes don't alter the existing on-disk format logic -- they only copy it to a new location. No telling what kind of odd side effects other code outside of nfs-utils may depend on here.

+	c++;
+	mon.mon_id.mon_name = c;
+	while (*c && *c != ' ')
+		c++;
+	if (*c)
+		*c++ = '\0';
+	while (*c == ' ')
+		c++;
+	mon.mon_id.my_id.my_name = c;
+
+	return func(hostname, (struct sockaddr *)&sin, &mon, timestamp);
+}

--
Chuck Lever
chuck[dot]lever[at]oracle[dot]com



--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Filesystem Development]     [Linux USB Development]     [Linux Media Development]     [Video for Linux]     [Linux NILFS]     [Linux Audio Users]     [Yosemite Info]     [Linux SCSI]

  Powered by Linux