From 8a95c6b5c10392c3cfd38ececbee0343d57bc4f5 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sat, 19 Aug 2017 14:40:46 -0400 Subject: [PATCH] unix,win: check for bad flags in uv_fs_copyfile() Refs: https://github.com/libuv/libuv/pull/1465 PR-URL: https://github.com/libuv/libuv/pull/1493 Reviewed-By: Santiago Gimeno Reviewed-By: Ben Noordhuis --- src/unix/fs.c | 3 +++ src/win/fs.c | 3 +++ test/test-fs-copyfile.c | 4 ++++ 3 files changed, 10 insertions(+) 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);