From: Timo Sirainen Date: Thu, 12 Aug 2010 15:29:15 +0000 (+0100) Subject: i_stream_create_fd(): If opening a directory, set stream_errno=EISDIR X-Git-Tag: 2.0.rc6~10 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=331b4805d76c0b3a5a38a560276f3cf110f55ba0;p=thirdparty%2Fdovecot%2Fcore.git i_stream_create_fd(): If opening a directory, set stream_errno=EISDIR --- diff --git a/src/lib/istream-file.c b/src/lib/istream-file.c index ef79173393..9d7ecbd416 100644 --- a/src/lib/istream-file.c +++ b/src/lib/istream-file.c @@ -172,6 +172,7 @@ i_stream_create_file_common(int fd, size_t max_buffer_size, bool autoclose_fd) { struct file_istream *fstream; struct stat st; + bool is_file; fstream = i_new(struct file_istream, 1); fstream->autoclose_fd = autoclose_fd; @@ -184,7 +185,21 @@ i_stream_create_file_common(int fd, size_t max_buffer_size, bool autoclose_fd) fstream->istream.stat = i_stream_file_stat; /* if it's a file, set the flags properly */ - if (fd == -1 || (fstat(fd, &st) == 0 && S_ISREG(st.st_mode))) { + if (fd == -1) + is_file = TRUE; + else if (fstat(fd, &st) < 0) + is_file = FALSE; + else if (S_ISREG(st.st_mode)) + is_file = TRUE; + else if (!S_ISDIR(st.st_mode)) + is_file = FALSE; + else { + /* we're trying to open a directory. + we're not designed for it. */ + fstream->istream.istream.stream_errno = EISDIR; + is_file = FALSE; + } + if (is_file) { fstream->file = TRUE; fstream->istream.istream.blocking = TRUE; fstream->istream.istream.seekable = TRUE;