From nobody  Sun Aug 24 09:09:38 1997
Received: (from nobody@localhost)
          by hub.freebsd.org (8.8.7/8.8.7) id JAA06611;
          Sun, 24 Aug 1997 09:09:38 -0700 (PDT)
Message-Id: <199708241609.JAA06611@hub.freebsd.org>
Date: Sun, 24 Aug 1997 09:09:38 -0700 (PDT)
From: sumii@is.s.u-tokyo.ac.jp
To: freebsd-gnats-submit@freebsd.org
Subject: Getty(8) Parses 'ic' and 'ac' Fields in Gettytab(5) INCORRECTLY
X-Send-Pr-Version: www-1.0

>Number:         4370
>Category:       bin
>Synopsis:       Getty(8) Parses 'ic' and 'ac' Fields in Gettytab(5) INCORRECTLY
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:
>Keywords:
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Aug 24 09:10:01 PDT 1997
>Closed-Date:    Mon Sep 1 20:09:24 EST 1997
>Last-Modified:  Mon Sep  1 20:19:04 EST 1997
>Originator:     Eijiro Sumii
>Release:        2.2.2-RELEASE
>Organization:
Department of Information Science, Facility of Science, University of Tokyo
>Environment:
FreeBSD proside.sumii.or.jp 2.2.2-RELEASE FreeBSD 2.2.2-RELEASE #0: Sat Aug  2 11:21:48 JST 1997     sumii@proside.sumii.or.jp:/usr/src/sys/compile/PROSIDE+ACVC  i386
>Description:
Getty (8) parses 'ic' and 'ac' fields in gettytab(5) INCORRECTLY,
when some escape characters are included in them.
That is known by the debugging messages of getty(8) itself.
The cause of this problem is two simple mistakes in the program.
I think they are not corrected in FreeBSD-current now.

>How-To-Repeat:
An Example:

1. Edit /etc/syslog.conf to print debugging messages of getty(8).

  *.notice;*.debug;lpr.info;mail.crit;news.err    /var/log/messages
           ^^^^^^^

2. Add an entry like this to /etc/gettytab.

  mymodem:\
          :hw:np:sp#38400:de#1:dc#255:ic="" \pATZ\r OK\r:ac=RING\r \pATA\r CONNECT:

3. Use it from init(8).

  % grep mymodem /etc/ttys
  ttyd1   "/usr/libexec/getty mymodem"    dialup on insecure

4. Read the debugging messages in /var/log/messages.

  Aug 24 21:47:30 proside getty[491]: getty_chat script='"" pATZ^M OK'
  Aug 24 21:47:30 proside getty[491]: chat_expect ''
  Aug 24 21:47:30 proside getty[491]: chat_expect OK
  Aug 24 21:47:30 proside getty[491]: chat_send 'pATZ^M'
                                                 ^ Here!

>Fix:
% diff -c /usr/src/libexec/getty/chat.c{~,}
*** /usr/src/libexec/getty/chat.c~      Sat Feb 22 23:21:36 1997
--- /usr/src/libexec/getty/chat.c       Sun Aug 24 22:49:51 1997
***************
*** 223,229 ****
                                                }
                                        } else {
                                                /* copy standard character */
!                                               *r++ == *q;
                                        }
                                }
  
--- 223,229 ----
                                                }
                                        } else {
                                                /* copy standard character */
!                                               *r++ = *q;
                                        }
                                }
  
% diff -c /usr/src/libexec/getty/subr.c{~,}
*** /usr/src/libexec/getty/subr.c~      Sun May 11 14:28:54 1997
--- /usr/src/libexec/getty/subr.c       Sun Aug 24 22:24:56 1997
***************
*** 79,85 ****
                return;
  
        for (sp = gettystrs; sp->field; sp++)
!               cgetstr(buf, (char*)sp->field, &sp->value);
        for (np = gettynums; np->field; np++) {
                if (cgetnum(buf, (char*)np->field, &n) == -1)
                        np->set = 0;
--- 79,85 ----
                return;
  
        for (sp = gettystrs; sp->field; sp++)
!               cgetustr(buf, (char*)sp->field, &sp->value);
        for (np = gettynums; np->field; np++) {
                if (cgetnum(buf, (char*)np->field, &n) == -1)
                        np->set = 0;
***************
*** 99,105 ****
  #ifdef DEBUG
        printf("name=\"%s\", buf=\"%s\"\r\n", name, buf);
        for (sp = gettystrs; sp->field; sp++)
!               printf("cgetstr: %s=%s\r\n", sp->field, sp->value);
        for (np = gettynums; np->field; np++)
                printf("cgetnum: %s=%d\r\n", np->field, np->value);
        for (fp = gettyflags; fp->field; fp++)
--- 99,105 ----
  #ifdef DEBUG
        printf("name=\"%s\", buf=\"%s\"\r\n", name, buf);
        for (sp = gettystrs; sp->field; sp++)
!               printf("cgetustr: %s=%s\r\n", sp->field, sp->value);
        for (np = gettynums; np->field; np++)
                printf("cgetnum: %s=%d\r\n", np->field, np->value);
        for (fp = gettyflags; fp->field; fp++)

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: davidn 
State-Changed-When: Mon Sep 1 20:09:24 EST 1997 
State-Changed-Why:  
Suggested fixes applied. Thanks! 
/home/ncvs/src/libexec/getty/chat.c,v  <--  chat.c 
new revision: 1.4; previous revision: 1.3 
/home/ncvs/src/libexec/getty/subr.c,v  <--  subr.c 
new revision: 1.11; previous revision: 1.10 
/home/ncvs/src/libexec/getty/chat.c,v  <--  chat.c 
new revision: 1.3.2.1; previous revision: 1.3 
/home/ncvs/src/libexec/getty/subr.c,v  <--  subr.c 
new revision: 1.6.2.3; previous revision: 1.6.2.2 
>Unformatted:
