Skip to content

Commit

Permalink
src: throw ERR_BUFFER_OUT_OF_BOUNDS in node_buffer.cc
Browse files Browse the repository at this point in the history
PR-URL: #20121
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
  • Loading branch information
joyeecheung authored and jasnell committed Apr 19, 2018
1 parent 0fdf39a commit 02db891
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/node_buffer.cc
Expand Up @@ -668,8 +668,10 @@ void StringWrite(const FunctionCallbackInfo<Value>& args) {
size_t max_length;

THROW_AND_RETURN_IF_OOB(ParseArrayIndex(args[1], 0, &offset));
if (offset > ts_obj_length)
return env->ThrowRangeError("Offset is out of bounds");
if (offset > ts_obj_length) {
return node::THROW_ERR_BUFFER_OUT_OF_BOUNDS(
env, "\"offset\" is outside of buffer bounds");
}

THROW_AND_RETURN_IF_OOB(ParseArrayIndex(args[2], ts_obj_length - offset,
&max_length));
Expand Down
1 change: 1 addition & 0 deletions src/node_errors.h
Expand Up @@ -17,6 +17,7 @@ namespace node {
// a `Local<Value>` containing the TypeError with proper code and message

#define ERRORS_WITH_CODE(V) \
V(ERR_BUFFER_OUT_OF_BOUNDS, RangeError) \
V(ERR_INDEX_OUT_OF_RANGE, RangeError) \
V(ERR_INVALID_ARG_TYPE, TypeError) \
V(ERR_MEMORY_ALLOCATION_FAILED, Error) \
Expand Down

0 comments on commit 02db891

Please sign in to comment.