diff options
author | Eugene Ostroukhov <eostroukhov@chromium.org> | 2016-08-23 19:40:40 -0700 |
---|---|---|
committer | Ali Ijaz Sheikh <ofrobots@google.com> | 2016-08-31 09:01:46 -0700 |
commit | b6db963915ca8e1443d1157a5844e8947fb6933c (patch) | |
tree | a0022de8d77f2ce7f0d0c352b9a70db6da10b481 /test/cctest | |
parent | b1bbc68fb1c04780a9820a5c0e4e939e5b30058a (diff) | |
download | android-node-v8-b6db963915ca8e1443d1157a5844e8947fb6933c.tar.gz android-node-v8-b6db963915ca8e1443d1157a5844e8947fb6933c.tar.bz2 android-node-v8-b6db963915ca8e1443d1157a5844e8947fb6933c.zip |
inspector: simplify buffer management
This change simplifies buffer management to address a number of issues
that original implementation had.
Original implementation was trying to reduce the number of allocations
by providing regions of the internal buffer to libuv IO code. This
introduced some potential use after free issues if the buffer grows
(or shrinks) while there's a pending read. It also had some confusing
math that resulted in issues on Windows version of the libuv.
PR-URL: https://github.com/nodejs/node/pull/8257
Fixes: https://github.com/nodejs/node/issues/8155
Reviewed-By: bnoordhuis - Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'test/cctest')
-rw-r--r-- | test/cctest/test_inspector_socket.cc | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/test/cctest/test_inspector_socket.cc b/test/cctest/test_inspector_socket.cc index 6f8cd25486..23d382ebe6 100644 --- a/test/cctest/test_inspector_socket.cc +++ b/test/cctest/test_inspector_socket.cc @@ -178,7 +178,7 @@ struct expectations { static void grow_expects_buffer(uv_handle_t* stream, size_t size, uv_buf_t* b) { expectations* expects = static_cast<expectations*>( - (static_cast<inspector_socket_t*>(stream->data))->data); + inspector_from_stream(stream)->data); size_t end = expects->actual_end; // Grow the buffer in chunks of 64k. size_t new_length = (end + size + 65535) & ~((size_t) 0xFFFF); @@ -213,7 +213,7 @@ static void grow_expects_buffer(uv_handle_t* stream, size_t size, uv_buf_t* b) { static void save_read_data(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf) { expectations* expects =static_cast<expectations*>( - (static_cast<inspector_socket_t*>(stream->data))->data); + inspector_from_stream(stream)->data); expects->err_code = nread < 0 ? nread : 0; if (nread > 0) { expects->actual_end += nread; @@ -254,8 +254,7 @@ static void expect_on_server(const char* data, size_t len) { static void inspector_record_error_code(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf) { - inspector_socket_t *inspector = - reinterpret_cast<inspector_socket_t*>(stream->data); + inspector_socket_t *inspector = inspector_from_stream(stream); // Increment instead of assign is to ensure the function is only called once *(static_cast<int *>(inspector->data)) += nread; } @@ -760,8 +759,7 @@ static void CleanupSocketAfterEOF_close_cb(inspector_socket_t* inspector, static void CleanupSocketAfterEOF_read_cb(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf) { EXPECT_EQ(UV_EOF, nread); - inspector_socket_t* insp = - reinterpret_cast<inspector_socket_t*>(stream->data); + inspector_socket_t* insp = inspector_from_stream(stream); inspector_close(insp, CleanupSocketAfterEOF_close_cb); } |