From afd02b2579235dd743946f00028c3bf17c189e84 Mon Sep 17 00:00:00 2001 From: Christopher Beeson Date: Sun, 19 Apr 2020 12:48:12 -0400 Subject: [PATCH] src: relax assertion in operator[] of MaybeStackBuffer Setting environment variables on Windows was causing an abort because the assertion did not account for the null-terminator at the end of the buffer. --- src/node_env_var.cc | 2 +- src/util.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/node_env_var.cc b/src/node_env_var.cc index b4358e99c2c3f1..5f543a5e76a1f9 100644 --- a/src/node_env_var.cc +++ b/src/node_env_var.cc @@ -121,7 +121,7 @@ void RealEnvStore::Set(Isolate* isolate, node::Utf8Value val(isolate, value); #ifdef _WIN32 - if (key.length() > 0 && key[0] == L'=') return; + if (key[0] == L'=') return; #endif uv_os_setenv(*key, *val); DateTimeConfigurationChangeNotification(isolate, key); diff --git a/src/util.h b/src/util.h index 5eaa20b760168b..02c99bd648f10b 100644 --- a/src/util.h +++ b/src/util.h @@ -351,12 +351,12 @@ class MaybeStackBuffer { } T& operator[](size_t index) { - CHECK_LT(index, length()); + CHECK_LT(index, length() + 1); return buf_[index]; } const T& operator[](size_t index) const { - CHECK_LT(index, length()); + CHECK_LT(index, length() + 1); return buf_[index]; }