unix,win: return EINVAL on nullptr args in uv_fs_{read,write}

PR-URL: https://github.com/libuv/libuv/pull/470
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
This commit is contained in:
Karl Skomski 2015-08-11 12:38:57 +02:00 committed by Saúl Ibarra Corretgé
parent c2e6f3bad1
commit 939ea06f45
5 changed files with 39 additions and 2 deletions

View File

@ -1071,6 +1071,9 @@ int uv_fs_read(uv_loop_t* loop, uv_fs_t* req,
unsigned int nbufs,
int64_t off,
uv_fs_cb cb) {
if (bufs == NULL || nbufs == 0)
return -EINVAL;
INIT(READ);
req->file = file;
@ -1193,6 +1196,9 @@ int uv_fs_write(uv_loop_t* loop,
unsigned int nbufs,
int64_t off,
uv_fs_cb cb) {
if (bufs == NULL || nbufs == 0)
return -EINVAL;
INIT(WRITE);
req->file = file;

View File

@ -1831,6 +1831,9 @@ int uv_fs_read(uv_loop_t* loop,
unsigned int nbufs,
int64_t offset,
uv_fs_cb cb) {
if (bufs == NULL || nbufs == 0)
return UV_EINVAL;
uv_fs_req_init(loop, req, UV_FS_READ, cb);
req->file.fd = fd;
@ -1864,6 +1867,9 @@ int uv_fs_write(uv_loop_t* loop,
unsigned int nbufs,
int64_t offset,
uv_fs_cb cb) {
if (bufs == NULL || nbufs == 0)
return UV_EINVAL;
uv_fs_req_init(loop, req, UV_FS_WRITE, cb);
req->file.fd = fd;

View File

@ -2514,3 +2514,24 @@ TEST_IMPL(fs_write_alotof_bufs_with_offset) {
MAKE_VALGRIND_HAPPY();
return 0;
}
TEST_IMPL(fs_read_write_null_arguments) {
int r;
r = uv_fs_read(NULL, NULL, 0, NULL, 0, -1, NULL);
ASSERT(r == UV_EINVAL);
r = uv_fs_write(NULL, NULL, 0, NULL, 0, -1, NULL);
ASSERT(r == UV_EINVAL);
iov = uv_buf_init(NULL, 0);
r = uv_fs_read(NULL, NULL, 0, &iov, 0, -1, NULL);
ASSERT(r == UV_EINVAL);
iov = uv_buf_init(NULL, 0);
r = uv_fs_write(NULL, NULL, 0, &iov, 0, -1, NULL);
ASSERT(r == UV_EINVAL);
return 0;
}

View File

@ -275,6 +275,7 @@ TEST_DECLARE (fs_scandir_file)
TEST_DECLARE (fs_open_dir)
TEST_DECLARE (fs_rename_to_existing_file)
TEST_DECLARE (fs_write_multiple_bufs)
TEST_DECLARE (fs_read_write_null_arguments)
TEST_DECLARE (fs_write_alotof_bufs)
TEST_DECLARE (fs_write_alotof_bufs_with_offset)
TEST_DECLARE (threadpool_queue_work_simple)
@ -690,6 +691,7 @@ TASK_LIST_START
TEST_ENTRY (fs_write_multiple_bufs)
TEST_ENTRY (fs_write_alotof_bufs)
TEST_ENTRY (fs_write_alotof_bufs_with_offset)
TEST_ENTRY (fs_read_write_null_arguments)
TEST_ENTRY (threadpool_queue_work_simple)
TEST_ENTRY (threadpool_queue_work_einval)
TEST_ENTRY (threadpool_multiple_event_loops)

View File

@ -279,10 +279,12 @@ TEST_IMPL(threadpool_cancel_fs) {
uv_fs_t reqs[25];
uv_loop_t* loop;
unsigned n;
uv_buf_t iov;
INIT_CANCEL_INFO(&ci, reqs);
loop = uv_default_loop();
saturate_threadpool();
iov = uv_buf_init(NULL, 0);
/* Needs to match ARRAY_SIZE(fs_reqs). */
n = 0;
@ -300,7 +302,7 @@ TEST_IMPL(threadpool_cancel_fs) {
ASSERT(0 == uv_fs_lstat(loop, reqs + n++, "/", fs_cb));
ASSERT(0 == uv_fs_mkdir(loop, reqs + n++, "/", 0, fs_cb));
ASSERT(0 == uv_fs_open(loop, reqs + n++, "/", 0, 0, fs_cb));
ASSERT(0 == uv_fs_read(loop, reqs + n++, 0, NULL, 0, 0, fs_cb));
ASSERT(0 == uv_fs_read(loop, reqs + n++, 0, &iov, 1, 0, fs_cb));
ASSERT(0 == uv_fs_scandir(loop, reqs + n++, "/", 0, fs_cb));
ASSERT(0 == uv_fs_readlink(loop, reqs + n++, "/", fs_cb));
ASSERT(0 == uv_fs_rename(loop, reqs + n++, "/", "/", fs_cb));
@ -310,7 +312,7 @@ TEST_IMPL(threadpool_cancel_fs) {
ASSERT(0 == uv_fs_symlink(loop, reqs + n++, "/", "/", 0, fs_cb));
ASSERT(0 == uv_fs_unlink(loop, reqs + n++, "/", fs_cb));
ASSERT(0 == uv_fs_utime(loop, reqs + n++, "/", 0, 0, fs_cb));
ASSERT(0 == uv_fs_write(loop, reqs + n++, 0, NULL, 0, 0, fs_cb));
ASSERT(0 == uv_fs_write(loop, reqs + n++, 0, &iov, 1, 0, fs_cb));
ASSERT(n == ARRAY_SIZE(reqs));
ASSERT(0 == uv_timer_init(loop, &ci.timer_handle));