bin/144411: [patch] mtree(8) doesn't reject non-regular files for -X

Bruce Evans brde at optusnet.com.au
Wed Oct 13 04:02:17 UTC 2010


On Sun, 10 Oct 2010, Garrett Cooper wrote:

> ...
>    I've been sitting on this PR for a while and I'd like to wrap it
> up and move on, if that's ok. Here's a patch with a more suitable
> comment above the stat(2) call.

% Index: usr.sbin/mtree/excludes.c
% ===================================================================
% --- usr.sbin/mtree/excludes.c	(revision 213667)
% +++ usr.sbin/mtree/excludes.c	(working copy)
% @@ -30,9 +30,10 @@
%  #include <sys/cdefs.h>
%  __FBSDID("$FreeBSD$");
% 
% +#include <sys/queue.h>
% +#include <sys/stat.h>
% +#include <sys/time.h>		/* XXX for mtree.h */
%  #include <sys/types.h>
% -#include <sys/time.h>		/* XXX for mtree.h */
% -#include <sys/queue.h>
% 
%  #include <err.h>
%  #include <fnmatch.h>
% @@ -63,11 +64,22 @@
%  void
%  read_excludes_file(const char *name)
%  {
% +	struct stat exclude_stat;
% +	struct exclude *e;
%  	FILE *fp;
%  	char *line, *str;
% -	struct exclude *e;
%  	size_t len;
% 
% +	/* 
% +	 * Make sure that the path we're dealing with points to a regular file,
% +	 * because the exclude list should be a regular file, not a directory,
% +	 * etc.
% +	 */
% +	if (stat(name, &exclude_stat) != 0)
% +		err(EXIT_FAILURE, "stat: %s", name);
% +	if (!S_ISREG(exclude_stat.st_mode))
% +		errx(EXIT_FAILURE, "invalid exclude file: %s", name);
% +
%  	fp = fopen(name, "r");
%  	if (fp == 0)
%  		err(1, "%s", name);

I like the main part of the patch.

The reordering of the includes may be premature or incomplete.  Old
sources include <sys/types.h> first since it was a prerequisite for
all POSIX headers, and most FreeBSD man pages and style(9) still say
to do this although POSIX dropped this requirement in 2001 or earlier
and FreeBSD mostly removed this requirement in ~2002-2003.  So now,
the include of <sys/types.h> might not be needed at all, but it is
hard to tell since there is so much pollution in other headers.  I
would keep the include of <sys/types.h> first if it is kept.

Bruce


More information about the freebsd-bugs mailing list