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 <santiago.gimeno@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
cjihrig 2017-08-19 14:40:46 -04:00
parent 607dc073eb
commit 8a95c6b5c1
No known key found for this signature in database
GPG Key ID: 7434390BDBE9B9C5
3 changed files with 10 additions and 0 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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);