From owner-freebsd-bugs Tue Jun 30 06:41:20 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id GAA22016 for freebsd-bugs-outgoing; Tue, 30 Jun 1998 06:41:20 -0700 (PDT) (envelope-from owner-freebsd-bugs@FreeBSD.ORG) Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.21]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id GAA21982 for ; Tue, 30 Jun 1998 06:41:01 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.8.8/8.8.5) id GAA28067; Tue, 30 Jun 1998 06:40:01 -0700 (PDT) Date: Tue, 30 Jun 1998 06:40:01 -0700 (PDT) Message-Id: <199806301340.GAA28067@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.ORG From: smoergrd@oslo.geco-prakla.slb.com (Dag-Erling Coidan Smørgrav) Subject: Re: misc/7124: MAKEDEV vty doesn't check if the number is valid Reply-To: smoergrd@oslo.geco-prakla.slb.com (Dag-Erling Coidan Smørgrav) Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org The following reply was made to PR misc/7124; it has been noted by GNATS. From: smoergrd@oslo.geco-prakla.slb.com (Dag-Erling Coidan Smørgrav) To: nick@taronga.com Cc: freebsd-gnats-submit@freebsd.org Subject: Re: misc/7124: MAKEDEV vty doesn't check if the number is valid Date: 30 Jun 1998 15:37:50 +0200 nick@taronga.com writes: > The bug appears to occur just below line 719 in MAKEDEV where > > units=`expr $i : 'vty\(.*\)'` > eval `echo ${chr} ${units} | awk ' { c=$1; n=$2 } END { > for (i = 0; i < n; i++) > printf("rm -f ttyv%01x; mknod ttyv%01x c %d %d; \ > chown root.wheel ttyv%01x;", \ > i, i, c, i, i); }'` > ln -fs ttyv0 vga # XXX X still needs this pccons relic > ;; > > > splits off the number of devices to make and passes that to awk. I'm > not to keen with awk, but I'm under the impression that it can't deal > with a non-hexadecimal number where a hexadecimal number is supposed > to be. The number supplied after "vty"in 'MAKEDEV vtyxx'is decimal, not hexadecimal. For instance, 'MAKEDEV vty16' will create device nodes for 16 vtys, named /dev/ttyv0 thru /dev/ttyvf. Anyway, the bug is due to the for loop never terminating because i < n is always true when n is a string: smoergrd@sunw132 ~$ echo | awk '{ if (1 < "one") { print "yes"; } }' yes The fix is to add 0 to n to force conversion to an integer: smoergrd@sunw132 ~$ echo | awk ' { if (1 < ("one"+0)) { print "yes"; } else { print "no"; } }' no In MAKEDEV, you'd replace the line with the eval with: eval `echo ${chr} ${units} | awk ' { c=$1; n=0+$2 } END { Below is a patch which (hopefully) fixes this problem in the two places I've been able to identify it in MAKEDEV. Due to the suckiness of my current Internet connection and my not having a FreeBSD box at hand (argh... why did I have to leave my laptop at home today?), I'll leave it to Somebody Else (tm) to test and commit it. The patch is against the following version of MAKEDEV: $Id: MAKEDEV,v 1.127.2.19 1998/03/01 22:20:11 steve Exp $ which should be the most recent revision in the RELENG_2_2 branch. Adaptation to -current is left as an exercise to the reader. --- MAKEDEV.orig Tue Jun 30 15:30:53 1998 +++ MAKEDEV Tue Jun 30 15:30:17 1998 @@ -550,7 +550,7 @@ case $class in 0|1|2|3|4|5|6|7) umask 0 - eval `echo $offset $name | awk ' { b=$1; n=$2 } END { \ + eval `echo $offset $name | awk ' { b=0+$1; n=0+$2 } END { \ for (i = 0; i < 32; i++) { c = substr("0123456789abcdefghijklmnopqrstuv", i + 1, 1); \ printf("mknod tty%s%s c 5 %d; \ @@ -712,7 +712,7 @@ vty*) chr=12 units=`expr $i : 'vty\(.*\)'` - eval `echo ${chr} ${units} | awk ' { c=$1; n=$2 } END { + eval `echo ${chr} ${units} | awk ' { c=0+$1; n=0+$2 } END { for (i = 0; i < n; i++) printf("mknod ttyv%01x c %d %d;", i, c, i); }'` ln -fs ttyv0 vga # XXX X still needs this pccons relic DES -- Dag-Erling Smørgrav - smoergrd@oslo.geco-prakla.slb.com To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message