From 441f7b7fabe2d5edd5fc66bfeb8192767e5c7aec Mon Sep 17 00:00:00 2001 From: Stefan Siegl Date: Sat, 1 Aug 2015 19:54:23 +0200 Subject: [PATCH] v8js_commonjs_split_terms: use pointer comparison instead of strlen The strlen usage on term obviously was wrong here, since the term string is not null-terminated at that place. --- tests/commonjs_normalise_003.phpt | 2 ++ v8js_commonjs.cc | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/commonjs_normalise_003.phpt b/tests/commonjs_normalise_003.phpt index e8a95ff..7f752d4 100644 --- a/tests/commonjs_normalise_003.phpt +++ b/tests/commonjs_normalise_003.phpt @@ -8,6 +8,7 @@ Test V8Js::setModuleLoader : Path normalisation #003 $JS = <<< EOT var foo = require("foo/test"); var foo = require("foo/bar/baz/test"); +var foo = require("foo//bar//baz//blub"); EOT; $v8 = new V8Js(); @@ -22,4 +23,5 @@ $v8->executeString($JS, 'module.js'); --EXPECT-- setModuleLoader called for foo/test setModuleLoader called for foo/bar/baz/test +setModuleLoader called for foo/bar/baz/blub ===EOF=== diff --git a/v8js_commonjs.cc b/v8js_commonjs.cc index 80a8a3b..e0e09b0 100644 --- a/v8js_commonjs.cc +++ b/v8js_commonjs.cc @@ -31,7 +31,7 @@ static void v8js_commonjs_split_terms(const char *identifier, std::vector 0) { if (*identifier == '/') { - if (strlen(term) > 0) { + if (ptr > term) { // Terminate term string and add to terms vector *ptr++ = 0; terms.push_back(estrdup(term)); @@ -47,7 +47,7 @@ static void v8js_commonjs_split_terms(const char *identifier, std::vector 0) { + if (ptr > term) { // Terminate term string and add to terms vector *ptr++ = 0; terms.push_back(estrdup(term));