summaryrefslogtreecommitdiff
path: root/src/env-inl.h
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2019-03-18 12:13:29 +0100
committerRuben Bridgewater <ruben@bridgewater.de>2019-03-22 00:47:15 +0100
commitd117e41e50667d7a36259bfc69416216bdf74eae (patch)
treeb988b9ba944a41e3b53c8bbe93bf92f0f925890c /src/env-inl.h
parentbca23f2ee71ddaf4f4393652de75dbb7fbc27f1d (diff)
downloadandroid-node-v8-d117e41e50667d7a36259bfc69416216bdf74eae.tar.gz
android-node-v8-d117e41e50667d7a36259bfc69416216bdf74eae.tar.bz2
android-node-v8-d117e41e50667d7a36259bfc69416216bdf74eae.zip
src: do not make `Resize(0)`’d buffers base `nullptr`
This fixes issues in which APIs that accept pointers created this way treat `nullptr` and a zero-length buffer differently. We already do something similar for our `Malloc()` implementation. PR-URL: https://github.com/nodejs/node/pull/26731 Fixes: https://github.com/nodejs/node/issues/26514 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Diffstat (limited to 'src/env-inl.h')
-rw-r--r--src/env-inl.h6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/env-inl.h b/src/env-inl.h
index ffba6a2843..79c9312e66 100644
--- a/src/env-inl.h
+++ b/src/env-inl.h
@@ -759,8 +759,10 @@ inline AllocatedBuffer::AllocatedBuffer(Environment* env, uv_buf_t buf)
: env_(env), buffer_(buf) {}
inline void AllocatedBuffer::Resize(size_t len) {
- char* new_data = env_->Reallocate(buffer_.base, buffer_.len, len);
- CHECK_IMPLIES(len > 0, new_data != nullptr);
+ // The `len` check is to make sure we don't end up with `nullptr` as our base.
+ char* new_data = env_->Reallocate(buffer_.base, buffer_.len,
+ len > 0 ? len : 1);
+ CHECK_NOT_NULL(new_data);
buffer_ = uv_buf_init(new_data, len);
}