fts_open() requires that the list passed as argument to contain at least

one path.  When the list is empty (contain only a NULL pointer), return
EINVAL instead of pretending to succeed, which will cause a NULL pointer
deference in a later fts_read() call.

Noticed by:	Christoph Mallon (via rdivacky@)
MFC after:	2 weeks
This commit is contained in:
Xin LI 2009-10-05 21:11:04 +00:00
parent c01f2b8301
commit 8b8a820ded
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=197793
2 changed files with 8 additions and 2 deletions

View file

@ -28,7 +28,7 @@
.\" @(#)fts.3 8.5 (Berkeley) 4/16/94
.\" $FreeBSD$
.\"
.Dd January 26, 2008
.Dd October 5, 2009
.Dt FTS 3
.Os
.Sh NAME
@ -776,7 +776,7 @@ may fail and set
as follows:
.Bl -tag -width Er
.It Bq Er EINVAL
The options were invalid.
The options were invalid, or the list were empty.
.El
.Sh SEE ALSO
.Xr find 1 ,

View file

@ -124,6 +124,12 @@ fts_open(argv, options, compar)
return (NULL);
}
/* fts_open() requires at least one path */
if (*argv == NULL) {
errno = EINVAL;
return (NULL);
}
/* Allocate/initialize the stream. */
if ((priv = malloc(sizeof(*priv))) == NULL)
return (NULL);