Subject: Re: HEADS UP: Merge the gehenna-devsw branch.
To: None <tsutsui@ceres.dti.ne.jp>
From: MAEKAWA Masahide <bishop@rr.iij4u.or.jp>
List: current-users
Date: 09/15/2002 22:13:46
Izumi Tsutsui <tsutsui@ceres.dti.ne.jp> wrote:
>> I have merged the gehenna-devsw branch into the trunk.
>
>I've updated my CATS' kernel to 1.6H, and it no longer
>recognizes boot device.
>
>It seems that devsw_name2blk() (which is called from
>cats/autoconf.c:get_device()) copies wrong strings into
>devname arg for the device name. Is the attached patch correct?

it seems to be still wrong. how about this?

--- MAEKAWA Masahide
--- Key fingerprint = BC5E D8CB 816C 2CB5 8560  FDE3 6CB8 BF5D 8D50 F2EE

--- subr_devsw.c.orig	Sun Sep 15 22:09:24 2002
+++ subr_devsw.c	Sun Sep 15 22:09:27 2002
@@ -373,7 +373,7 @@
 devsw_name2blk(const char *name, char *devname, size_t devnamelen)
 {
 	struct devsw_conv *conv;
-	int bmajor, i;
+	int bmajor, len, i;
 
 	if (name == NULL)
 		return (-1);
@@ -382,7 +382,8 @@
 		conv = &devsw_conv[i];
 		if (conv->d_name == NULL)
 			continue;
-		if (strncmp(conv->d_name, name, strlen(conv->d_name)) != 0)
+		len = strlen(conv->d_name);
+		if (strncmp(conv->d_name, name, len) != 0)
 			continue;
 		bmajor = conv->d_bmajor;
 		if (bmajor < 0 || bmajor >= max_bdevsws ||
@@ -390,11 +391,11 @@
 			return (-1);
 		if (devname != NULL) {
 #ifdef DEVSW_DEBUG
-			if (strlen(conv->d_name) >= devnamelen)
+			if (len >= devnamelen)
 				printf("devsw_name2blk: too short buffer");
 #endif /* DEVSW_DEBUG */
-			strncpy(devname, name, devnamelen);
-			devname[devnamelen - 1] = '\0';
+			strncpy(devname, conv->d_name, len);
+			devname[len] = '\0';
 		}
 		return (bmajor);
 	}