diff --git a/src/unix/fs.c b/src/unix/fs.c index 626d6c05..2f4ab871 100644 --- a/src/unix/fs.c +++ b/src/unix/fs.c @@ -1476,6 +1476,9 @@ int uv_fs_copyfile(uv_loop_t* loop, const char* new_path, int flags, uv_fs_cb cb) { + if (flags & ~UV_FS_COPYFILE_EXCL) + return -EINVAL; + INIT(COPYFILE); PATH2; req->flags = flags; diff --git a/src/win/fs.c b/src/win/fs.c index 9ef29fea..5edfee88 100644 --- a/src/win/fs.c +++ b/src/win/fs.c @@ -2434,6 +2434,9 @@ int uv_fs_copyfile(uv_loop_t* loop, uv_fs_cb cb) { int err; + if (flags & ~UV_FS_COPYFILE_EXCL) + return UV_EINVAL; + uv_fs_req_init(loop, req, UV_FS_COPYFILE, cb); err = fs__capture_path(req, path, new_path, cb != NULL); diff --git a/test/test-fs-copyfile.c b/test/test-fs-copyfile.c index 746cd94b..a973e86a 100644 --- a/test/test-fs-copyfile.c +++ b/test/test-fs-copyfile.c @@ -96,6 +96,10 @@ TEST_IMPL(fs_copyfile) { loop = uv_default_loop(); + /* Fails with EINVAL if bad flags are passed. */ + r = uv_fs_copyfile(NULL, &req, src, dst, -1, NULL); + ASSERT(r == UV_EINVAL); + /* Fails with ENOENT if source does not exist. */ unlink(src); unlink(dst);