summaryrefslogtreecommitdiff
path: root/src/node_api.cc
diff options
context:
space:
mode:
authorMichael Dawson <michael_dawson@ca.ibm.com>2017-09-25 11:37:18 -0400
committerMichael Dawson <michael_dawson@ca.ibm.com>2017-09-29 17:44:41 -0400
commitcec6e21668be70cbd18b4672c4c3d29d4f953ab8 (patch)
tree236c2f7cb987c76bd486e2db2fd4e7d946b9dc28 /src/node_api.cc
parent98077446f9ed2baeb434e616edac7f970c34941f (diff)
downloadandroid-node-v8-cec6e21668be70cbd18b4672c4c3d29d4f953ab8.tar.gz
android-node-v8-cec6e21668be70cbd18b4672c4c3d29d4f953ab8.tar.bz2
android-node-v8-cec6e21668be70cbd18b4672c4c3d29d4f953ab8.zip
n-api: add check for large strings
n-api uses size_t for the size of strings when specifying string lengths. V8 only supports a size of int. Add a check so that an error will be returned if the user passes in a string with a size larger than will fit into an int. PR-URL: https://github.com/nodejs/node/pull/15611 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Diffstat (limited to 'src/node_api.cc')
-rw-r--r--src/node_api.cc6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/node_api.cc b/src/node_api.cc
index fbf20878ab..94e4e57bb4 100644
--- a/src/node_api.cc
+++ b/src/node_api.cc
@@ -10,6 +10,7 @@
#include <node_buffer.h>
#include <node_object_wrap.h>
+#include <limits.h> // INT_MAX
#include <string.h>
#include <algorithm>
#include <cmath>
@@ -125,6 +126,9 @@ struct napi_env__ {
do { \
static_assert(static_cast<int>(NAPI_AUTO_LENGTH) == -1, \
"Casting NAPI_AUTO_LENGTH to int must result in -1"); \
+ RETURN_STATUS_IF_FALSE((env), \
+ (len == NAPI_AUTO_LENGTH) || len <= INT_MAX, \
+ napi_invalid_arg); \
auto str_maybe = v8::String::NewFromUtf8( \
(env)->isolate, (str), v8::NewStringType::kInternalized, \
static_cast<int>(len)); \
@@ -866,7 +870,7 @@ void napi_module_register(napi_module* mod) {
// Warning: Keep in-sync with napi_status enum
const char* error_messages[] = {nullptr,
- "Invalid pointer passed as argument",
+ "Invalid argument",
"An object was expected",
"A string was expected",
"A string or symbol was expected",