summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
Diffstat (limited to 'source3')
-rw-r--r--source3/lib/replace/repdir_getdents.c12
-rw-r--r--source3/lib/replace/repdir_getdirentries.c12
2 files changed, 24 insertions, 0 deletions
diff --git a/source3/lib/replace/repdir_getdents.c b/source3/lib/replace/repdir_getdents.c
index 07b9568dc1..3bf76ee858 100644
--- a/source3/lib/replace/repdir_getdents.c
+++ b/source3/lib/replace/repdir_getdents.c
@@ -68,6 +68,7 @@ struct dir_buf {
DIR *opendir(const char *dname)
{
struct dir_buf *d;
+ struct stat sb;
d = malloc(sizeof(*d));
if (d == NULL) {
errno = ENOMEM;
@@ -78,6 +79,17 @@ DIR *opendir(const char *dname)
free(d);
return NULL;
}
+ if (fstat(d->fd, &sb) < 0) {
+ close(d->fd);
+ free(d);
+ return NULL;
+ }
+ if (!S_ISDIR(sb.st_mode)) {
+ close(d->fd);
+ free(d);
+ errno = ENOTDIR;
+ return NULL;
+ }
d->ofs = 0;
d->seekpos = 0;
d->nbytes = 0;
diff --git a/source3/lib/replace/repdir_getdirentries.c b/source3/lib/replace/repdir_getdirentries.c
index 9e4b63145c..ee1d218456 100644
--- a/source3/lib/replace/repdir_getdirentries.c
+++ b/source3/lib/replace/repdir_getdirentries.c
@@ -70,6 +70,7 @@ struct dir_buf {
DIR *opendir(const char *dname)
{
struct dir_buf *d;
+ struct stat sb;
d = malloc(sizeof(*d));
if (d == NULL) {
errno = ENOMEM;
@@ -80,6 +81,17 @@ DIR *opendir(const char *dname)
free(d);
return NULL;
}
+ if (fstat(d->fd, &sb) < 0) {
+ close(d->fd);
+ free(d);
+ return NULL;
+ }
+ if (!S_ISDIR(sb.st_mode)) {
+ close(d->fd);
+ free(d);
+ errno = ENOTDIR;
+ return NULL;
+ }
d->ofs = 0;
d->seekpos = 0;
d->nbytes = 0;