Subject: bin/9963: Program pac prints garbage characters.
To: None <gnats-bugs@gnats.netbsd.org>
From: None <bstark@uswest.net>
List: netbsd-bugs
Date: 04/23/2000 20:51:13
>Number:         9963
>Category:       bin
>Synopsis:       Program pac prints garbage characters.
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Apr 23 20:52:01 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     Brian Stark
>Release:        NetBSD 1.4X
>Organization:
	
>Environment:
	
System: NetBSD palomino.siemens-psc.com 1.4X NetBSD 1.4X (PALOMINO) #10: Sat Apr 22 10:49:53 CDT 2000 bstark@palomino.siemens-psc.com:/usr/src/sys/arch/i386/compile/PALOMINO i386


>Description:

The code inside the program pac to support the call to getopt() is not working properly,
and this is causing garbage characters to come out.
	
>How-To-Repeat:

The "-P" parameter to pac accepts a printer name to use for processing. When called using
this parameter, NetBSD 1.4X produces the following on my system:

  palomino:bstark$ pac -P ljet4 
  pac: unknown printer ÜÔ¿¿b
  palomino:bstark$


NOTE: In my xterm window, the characters that appear after the string 'unknown printer' appear
as garbage charcters (those above decimal 128 and below 255). However, here in this send-pr
form, those characters look like escape sequences of some type.

Now, let's take a look at the code to see what is going on:

        FILE *acct;
        char *cp;
        int opt;

        while ((opt = getopt(argc, argv, "P:p:scmr")) != -1) {
                switch(opt) { 
                case 'P':
                        /*
                         * Printer name. 
                         */ 
                        printer = cp;
                        continue;


The code fragement above from pac.c shows that while processing the 'P' parameter, the
program assigns the value of 'cp' to 'printer'. But, cp has not been initialized! This 
code section should really assign the value of 'optarg' to printer instead of cp.

As I am writing this, I am also looking at the code that processes the "-p" parameter,
and like the code for "-P", I see that it too is also assigning the value of cp to
a variable. That section of code will have to be corrected as well.

>Fix:

If possible, contact Jaromir Dolecek (jdolecek@netbsd.org) about this one. In November
of 1999 I submitted a pr about formatting problems in the pac program which he fixed. 
In one of the emails I sent him about the formatting problems I suggested that the 
program be updated to take advantage of the getopt() function call since it was parsing
the command line parameters in its own way. Since getopt() is now used by the program,
it appears that he thought this was a good idea as well.
>Release-Note:
>Audit-Trail:
>Unformatted: