[PATCH] catv wrong behaviour when no arguments passed

Alex Landau landau_alex at yahoo.com
Mon Aug 6 04:50:43 PDT 2007


Hi,

When catv gets no files on the command line (argv[0] == NULL after getopt), after doing
its work it increments argv to point to the next argument, but since argv is already
NULL, catv tries to open files whose names are the environment strings (e.g.
"HOME=/home/user", "PATH=...").
The fix/workaround below is to pre-decrement argv in this case, so that when it is
incremented later it will be NULL and the loop will break.

Alex

Index: coreutils/catv.c
===================================================================
--- coreutils/catv.c	(revision 19409)
+++ coreutils/catv.c	(working copy)
@@ -27,8 +27,10 @@
 
 	/* Read from stdin if there's nothing else to do. */
 	fd = 0;
-	if (!argv[0])
+	if (!argv[0]) {
+		argv--;
 		goto jump_in;
+	}
 	do {
 		fd = open_or_warn(*argv, O_RDONLY);
 		if (fd < 0) {



       
____________________________________________________________________________________
Be a better Heartthrob. Get better relationship answers from someone who knows. Yahoo! Answers - Check it out. 
http://answers.yahoo.com/dir/?link=list&sid=396545433


More information about the busybox mailing list