From eb927fac38a50252e11ebe0da1764e85294f95f0 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 10 Sep 2016 16:43:08 +0200 Subject: src: add Malloc() size param + overflow detection Adds an optional second parameter to `node::Malloc()` and an optional third parameter to `node::Realloc()` giving the size/number of items to be allocated, in the style of `calloc(3)`. Use a proper overflow check using division; the previous `CHECK_GE(n * size, n);` would not detect all cases of overflow (e.g. `size == SIZE_MAX / 2 && n == 3`). PR-URL: https://github.com/nodejs/node/pull/8482 Reviewed-By: Ben Noordhuis Reviewed-By: James M Snell Reviewed-By: Michael Dawson Reviewed-By: Ilkka Myller --- src/string_bytes.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/string_bytes.cc') diff --git a/src/string_bytes.cc b/src/string_bytes.cc index fa641af746..fddf61de63 100644 --- a/src/string_bytes.cc +++ b/src/string_bytes.cc @@ -54,7 +54,7 @@ class ExternString: public ResourceType { return scope.Escape(String::Empty(isolate)); TypeName* new_data = - static_cast(node::Malloc(length * sizeof(*new_data))); + static_cast(node::Malloc(length, sizeof(*new_data))); if (new_data == nullptr) { return Local(); } -- cgit v1.2.3