diff options
author | Daniel Stenberg <daniel@haxx.se> | 2020-12-30 17:26:47 +0100 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2020-12-30 17:26:47 +0100 |
commit | cb6ede535ee1816dac5fe43bdde9e8ed93bfb105 (patch) | |
tree | 05f47d52350c242d71616c9dc00238a070e9b984 | |
parent | a6d20b89db8ee79b1a5f8188a680fea8047b145e (diff) | |
download | curl-bagder/file-dir.tar.gz |
file: refuse "getting" a directorybagder/file-dir
Make non-windows platforms also return error if the given path is a
directory. curl can't transfer a directory and doing a "-I" on it would
return a "bogus" Content-Length on it.
Reported-by: Kevin Ushey
Fixes #6379
-rw-r--r-- | lib/file.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/file.c b/lib/file.c index a65eb7798..21ef7d457 100644 --- a/lib/file.c +++ b/lib/file.c @@ -181,6 +181,7 @@ static CURLcode file_connect(struct connectdata *conn, bool *done) return CURLE_URL_MALFORMAT; } + /* Windows open fails on directories */ fd = open_readonly(actual_path, O_RDONLY|O_BINARY); file->path = actual_path; #else @@ -190,7 +191,17 @@ static CURLcode file_connect(struct connectdata *conn, bool *done) return CURLE_URL_MALFORMAT; } + /* non-Windows allow a plain open() of a directory ... */ fd = open_readonly(real_path, O_RDONLY); + if(fd != -1) { + struct stat st; + fstat(fd, &st); + /* ... but since we can "transfer" a directory, we fail */ + if(st.st_mode & S_IFDIR) { + close(fd); + fd = -1; + } + } file->path = real_path; #endif file->freepath = real_path; /* free this when done */ |