summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2018-04-16 23:52:54 +0800
committerJoyee Cheung <joyeec9h3@gmail.com>2018-04-19 12:09:28 +0800
commit8b1b36bfc5914c9f481c3d450209c7d9231f94c9 (patch)
tree1963f44030c773038b8734f1e12359505f4ec0bf /src
parent2c23e31c317025f6064c194f8850a474f4b6bf53 (diff)
downloadandroid-node-v8-8b1b36bfc5914c9f481c3d450209c7d9231f94c9.tar.gz
android-node-v8-8b1b36bfc5914c9f481c3d450209c7d9231f94c9.tar.bz2
android-node-v8-8b1b36bfc5914c9f481c3d450209c7d9231f94c9.zip
src: throw ERR_BUFFER_OUT_OF_BOUNDS in node_buffer.cc
PR-URL: https://github.com/nodejs/node/pull/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>
Diffstat (limited to 'src')
-rw-r--r--src/node_buffer.cc6
-rw-r--r--src/node_errors.h1
2 files changed, 5 insertions, 2 deletions
diff --git a/src/node_buffer.cc b/src/node_buffer.cc
index 997e4fd229..b00886f5e6 100644
--- a/src/node_buffer.cc
+++ b/src/node_buffer.cc
@@ -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));
diff --git a/src/node_errors.h b/src/node_errors.h
index 1ebedc2fcb..fadbdbe374 100644
--- a/src/node_errors.h
+++ b/src/node_errors.h
@@ -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) \