find -print0 (was Re: svn commit: trunk/busybox )

Paul Fox pgf at brightstareng.com
Thu May 11 21:58:34 UTC 2006


 > IMO the -print0 option exists for administrators wanting to guard
 > their scripts against exploits involving filenames with embedded
 > newlines, ...

and embedded whitespace.  have you never had to process a tree
full of filenames that were generated on a windows machine or a
mac?

i suppose there are alternate solutions, but find's -print0 and
xargs' -0 handle it trivially.  if you have another technique
that works well, i'd be interested in learning it.

for my own amusement, i did a rough patch.  it's not
configurable, doesn't have a usage etc etc.

paul
=---------------------
 paul fox, pgf at brightstareng.com

Index: findutils/find.c
===================================================================
--- findutils/find.c	(revision 15073)
+++ findutils/find.c	(working copy)
@@ -38,6 +38,7 @@
 static const char msg_invalid_arg[] = "invalid argument `%s' to `%s'";
 
 static char *pattern;
+static char printsep = '\n';
 
 #ifdef CONFIG_FEATURE_FIND_TYPE
 static int type_mask = 0;
@@ -159,7 +160,7 @@
 	}
 #endif
 
-	puts(fileName);
+	printf("%s%c", fileName, printsep);
 no_match:
 	return (TRUE);
 }
@@ -217,6 +218,8 @@
 		else if (strcmp(argv[i], "-print") == 0) {
 			;
 			}
+		else if (strcmp(argv[i], "-print0") == 0)
+			printsep = '\0';
 		else if (strcmp(argv[i], "-name") == 0) {
 			if (++i == argc)
 				bb_error_msg_and_die(msg_req_arg, "-name");



More information about the busybox mailing list