Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 30 Jun 1998 06:40:01 -0700 (PDT)
From:      smoergrd@oslo.geco-prakla.slb.com (Dag-Erling Coidan Smørgrav)
To:        freebsd-bugs@FreeBSD.ORG
Subject:   Re: misc/7124: MAKEDEV vty<xy> doesn't check if the number <xy> is valid
Message-ID:  <199806301340.GAA28067@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
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<xy> doesn't check if the number <xy> 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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199806301340.GAA28067>