Subject: bin/27208: pax must call options() before using syswarn() or tty_warn()
To: None <gnats-bugs@gnats.netbsd.org>
From: Greg A. Woods <woods@weird.com>
List: netbsd-bugs
Date: 10/10/2004 14:12:46
>Number: 27208
>Category: bin
>Synopsis: pax must call options() before using syswarn() or tty_warn()
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: bin-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sun Oct 10 18:13:00 UTC 2004
>Closed-Date:
>Last-Modified:
>Originator: Greg A. Woods
>Release: NetBSD-current
>Organization:
Planix, Inc.; Toronto, Ontario; Canada
>Environment:
all
>Description:
In pax the tty_warn() and syswarn() functions assume the argv0
variable is set, but it is not set until options() is called.
>How-To-Repeat:
encounter weird open(".", O_RDONLY) errors and wonder why the
resulting error message reads funny with "(null)" in it:
(null): Can't open current working directory. (Bad address)
>Fix:
re-arrange the call to options() so that it is first and also
make sure cwdfd is initialized to an invalid FD value
Index: pax.c
===================================================================
RCS file: /cvs/master/m-NetBSD/main/src/bin/pax/pax.c,v
retrieving revision 1.35
diff -u -r1.35 pax.c
--- pax.c 20 Jun 2004 22:20:14 -0000 1.35
+++ pax.c 10 Oct 2004 18:06:44 -0000
@@ -75,7 +75,7 @@
int act = ERROR; /* read/write/append/copy */
FSUB *frmt = NULL; /* archive format type */
int cflag; /* match all EXCEPT pattern/file */
-int cwdfd; /* starting cwd */
+int cwdfd = -1; /* starting cwd */
int dflag; /* directory member match only */
int iflag; /* interactive file/archive rename */
int jflag; /* pass through bzip2 */
@@ -248,6 +248,17 @@
listf = stderr;
/*
+ * parse options, determine operational mode
+ */
+ options(argc, argv);
+
+ /*
+ * general init
+ */
+ if ((gen_init() < 0) || (tty_init() < 0))
+ return(exit_val);
+
+ /*
* Keep a reference to cwd, so we can always come back home.
*/
cwdfd = open(".", O_RDONLY);
@@ -273,13 +284,6 @@
memcpy(tempfile, tmpdir, tdlen);
tempbase = tempfile + tdlen;
*tempbase++ = '/';
-
- /*
- * parse options, determine operational mode, general init
- */
- options(argc, argv);
- if ((gen_init() < 0) || (tty_init() < 0))
- return(exit_val);
(void)time(&starttime);
#ifdef SIGINFO
>Release-Note:
>Audit-Trail:
>Unformatted: