From 037291e31f3d7eb86dc0997bd612e2ab4dd962d3 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Thu, 2 Jun 2016 02:13:04 +0200 Subject: [PATCH] src: make sure Utf8Value always zero-terminates Make sure dereferencing a `Utf8Value` instance always returns a zero-terminated string, even if the conversion to string failed. The corresponding bugfix in the master branch happened in 44a40325da40 (https://github.com/nodejs/node/pull/6357). Ref: https://github.com/nodejs/node/pull/6357 PR-URL: https://github.com/nodejs/node/pull/7101 Reviewed-By: Ben Noordhuis Reviewed-By: Ben Noordhuis Reviewed-By: James M Snell Reviewed-By: Myles Borins --- src/util.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/util.cc b/src/util.cc index 903fbbba134bd9..858e4b396534b3 100644 --- a/src/util.cc +++ b/src/util.cc @@ -5,6 +5,10 @@ namespace node { Utf8Value::Utf8Value(v8::Isolate* isolate, v8::Local value) : length_(0), str_(str_st_) { + // Make sure result is always zero-terminated, even if conversion to string + // fails. + str_st_[0] = '\0'; + if (value.IsEmpty()) return;