[BusyBox] no argument hang patches

robotti at metconnect.com robotti at metconnect.com
Tue Aug 29 07:56:39 UTC 2000


These are some patches to make a few programs
return usage info, rather than just hang
when called without arguments.

I know the gnu find also outputs the current
directory when called without a argument,
but i think it should only do that when
you call it like this 'find .'.

These are for the latest cvs bb.

--- find.c.orig	Thu Aug 24 23:29:39 2000
+++ find.c	Tue Aug 29 07:05:24 2000
@@ -55,6 +55,10 @@
 	argc--;
 	argv++;
 
+	if (argc < 1) {
+	   usage(find_usage);
+	}
+
 	if (argc > 0 && **argv != '-') {
 		directory = *argv;
 		argc--;

--- mt.c.orig	Thu Aug 24 23:30:57 2000
+++ mt.c	Tue Aug 29 07:11:43 2000
@@ -54,9 +54,9 @@
 	const struct mt_opcodes *code = opcodes;
 	struct mtop op;
 	int fd;
-	
-	if ((argc != 2 && argc != 3) && **(argv + 1) != '-') {
-		usage(mt_usage);
+
+	if (argc < 2) {
+	   usage(mt_usage);
 	}
 
 	if (strcmp(argv[1], "-f") == 0) {

--- tee.c.orig	Mon Aug 28 04:55:54 2000
+++ tee.c	Tue Aug 29 07:02:58 2000
@@ -32,6 +32,10 @@
 	int c, i, status = 0, nfiles = 0;
 	FILE **files;
 
+	if (argc < 2) {
+	   usage(tee_usage);
+	}
+
 	while ((c = getopt(argc, argv, "a")) != EOF) {
 		switch (c) {
 		case 'a': 

--- wc.c.orig	Thu Aug 24 23:31:56 2000
+++ wc.c	Tue Aug 29 06:59:59 2000
@@ -110,6 +110,10 @@
 	total_lines = total_words = total_chars = max_length = 0;
 	print_lines = print_words = print_chars = print_length = 0;
 
+	if (argc < 2) {
+	   usage(wc_usage);
+	}
+
 	while ((opt = getopt(argc, argv, "clLw")) > 0) {
 			switch (opt) {
 			case 'c':





More information about the busybox mailing list