summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSam Roberts <vieuxtech@gmail.com>2017-07-05 14:25:55 -0700
committerMyles Borins <mylesborins@google.com>2017-11-28 13:09:53 +0900
commitf659e498621164af42a7d7d2d7e3d33e846015f7 (patch)
tree4f061bc8d94117071035968b60978b3ffb0a6ef2 /src
parent79171e0c2f16fff17f5ab7a4899b2be0c2574c17 (diff)
downloadnode-new-f659e498621164af42a7d7d2d7e3d33e846015f7.tar.gz
src: whitelist v8 options with '_' or '-'
V8 options allow either '_' or '-' to be used in options as a seperator, such as "--abort-on_uncaught-exception". Allow these case variations when used with NODE_OPTIONS. PR-URL: https://github.com/nodejs/node/pull/14093 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/node.cc33
1 files changed, 26 insertions, 7 deletions
diff --git a/src/node.cc b/src/node.cc
index 98fde0dbbe..2fd6da0c6f 100644
--- a/src/node.cc
+++ b/src/node.cc
@@ -3786,15 +3786,34 @@ static void PrintHelp() {
}
+static bool ArgIsAllowed(const char* arg, const char* allowed) {
+ for (; *arg && *allowed; arg++, allowed++) {
+ // Like normal strcmp(), except that a '_' in `allowed` matches either a '-'
+ // or '_' in `arg`.
+ if (*allowed == '_') {
+ if (!(*arg == '_' || *arg == '-'))
+ return false;
+ } else {
+ if (*arg != *allowed)
+ return false;
+ }
+ }
+
+ // "--some-arg=val" is allowed for "--some-arg"
+ if (*arg == '=')
+ return true;
+
+ // Both must be null, or one string is just a prefix of the other, not a
+ // match.
+ return !*arg && !*allowed;
+}
+
+
static void CheckIfAllowedInEnv(const char* exe, bool is_env,
const char* arg) {
if (!is_env)
return;
- // Find the arg prefix when its --some_arg=val
- const char* eq = strchr(arg, '=');
- size_t arglen = eq ? eq - arg : strlen(arg);
-
static const char* whitelist[] = {
// Node options, sorted in `node --help` order for ease of comparison.
"--require", "-r",
@@ -3820,14 +3839,14 @@ static void CheckIfAllowedInEnv(const char* exe, bool is_env,
"--openssl-config",
"--icu-data-dir",
- // V8 options
- "--abort-on-uncaught-exception",
+ // V8 options (define with '_', which allows '-' or '_')
+ "--abort_on_uncaught_exception",
"--max_old_space_size",
};
for (unsigned i = 0; i < arraysize(whitelist); i++) {
const char* allowed = whitelist[i];
- if (strlen(allowed) == arglen && strncmp(allowed, arg, arglen) == 0)
+ if (ArgIsAllowed(arg, allowed))
return;
}