Subject: bin/16565: asa(1) segfaults when it cannot open a specified file
To: None <gnats-bugs@gnats.netbsd.org>
From: None <ryany@pobox.com>
List: netbsd-bugs
Date: 04/29/2002 20:36:53
>Number:         16565
>Category:       bin
>Synopsis:       asa(1) segfaults when it cannot open a specified file
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Apr 29 17:37:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Ryan Younce
>Release:        NetBSD 1.5ZC
>Organization:
none
>Environment:
NetBSD jay 1.5ZC NetBSD 1.5ZC (JAY) #0: Mon Apr 29 13:02:29 EDT 2002     root@jay:/root/kernel/compile/JAY i386
>Description:
	asa(1) accepts a list of filenames (or none for stdin operation).
	If asa cannot open a specified file, it issues a diagnostic.
	However, if asa cannot open the file specified by the _last_ filename
	on the command line (whatever the reason; that is, the fopen() fails
	on that file), it additionally segfaults.

	It is a problem with the argv loop logic in main().

	This problem only occurs when a file which cannot be opened is at
	the end of the command line.
>How-To-Repeat:
	asa a_bogus_file
	or
	asa valid_file another_valid_file a_bogus_file
>Fix:
This is a working patch for /usr/src/usr.bin/asa/asa.c which corrects asa's
main() argv-processing loop.

(BTW, as a side note, there is some whitespace variation in main() (spaces
instead of tabs).  It's mostly restricted to the do-while loop.  The committer
may want to clean this up if/when the patch gets committed, as the following
patch does not clean it up).

--- asa.c.orig	Tue Apr 30 01:22:26 2002
+++ asa.c	Tue Apr 30 01:30:40 2002
@@ -57,13 +57,15 @@
                 if (*argv) {
                         if (!(fp = fopen(*argv, "r"))) {
 				warn ("%s", *argv);
+				++argv;
 				continue;
                         }
+			++argv;
                 }
                 asa (fp);
                 if (fp != stdin)
                         (void)fclose(fp);
-        } while (*argv++);
+        } while (*argv);
 
 	exit (0);
 }
>Release-Note:
>Audit-Trail:
>Unformatted: