summaryrefslogtreecommitdiffstats
path: root/js/src/shell/jsoptparse.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 05:35:37 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 05:35:37 +0000
commita90a5cba08fdf6c0ceb95101c275108a152a3aed (patch)
tree532507288f3defd7f4dcf1af49698bcb76034855 /js/src/shell/jsoptparse.cpp
parentAdding debian version 126.0.1-1. (diff)
downloadfirefox-a90a5cba08fdf6c0ceb95101c275108a152a3aed.tar.xz
firefox-a90a5cba08fdf6c0ceb95101c275108a152a3aed.zip
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/shell/jsoptparse.cpp')
-rw-r--r--js/src/shell/jsoptparse.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/js/src/shell/jsoptparse.cpp b/js/src/shell/jsoptparse.cpp
index 5632598d7d..b2805fb415 100644
--- a/js/src/shell/jsoptparse.cpp
+++ b/js/src/shell/jsoptparse.cpp
@@ -44,6 +44,12 @@ void OptionParser::setArgTerminatesOptions(const char* name, bool enabled) {
findArgument(name)->setTerminatesOptions(enabled);
}
+void OptionParser::setIgnoresUnknownOptions(const char* name, bool enabled) {
+ auto* opt = findOption(name);
+ MOZ_ASSERT(opt);
+ opt->setIgnoresUnknownOptions(enabled);
+}
+
void OptionParser::setArgCapturesRest(const char* name) {
MOZ_ASSERT(restArgument == -1,
"only one argument may be set to capture the rest");
@@ -349,10 +355,15 @@ OptionParser::Result OptionParser::handleArg(size_t argc, char** argv,
OptionParser::Result OptionParser::parseArgs(int inputArgc, char** argv) {
MOZ_ASSERT(inputArgc >= 0);
size_t argc = inputArgc;
+
// Permit a "no more options" capability, like |--| offers in many shell
// interfaces.
bool optionsAllowed = true;
+ // Whether unknown options should report a warning instead of an error. This
+ // is enabled by setIgnoresUnknownOptions and used for --fuzzing-safe.
+ bool ignoreUnknownOptions = false;
+
for (size_t i = 1; i < argc; ++i) {
char* arg = argv[i];
Result r;
@@ -370,6 +381,11 @@ OptionParser::Result OptionParser::parseArgs(int inputArgc, char** argv) {
/* Long option. */
opt = findOption(arg + 2);
if (!opt) {
+ if (ignoreUnknownOptions) {
+ fprintf(stderr, "Warning: Ignoring unknown shell flag: %s\n",
+ arg);
+ continue;
+ }
return error("Invalid long option: %s", arg);
}
}
@@ -384,6 +400,10 @@ OptionParser::Result OptionParser::parseArgs(int inputArgc, char** argv) {
}
}
+ if (opt->getIgnoresUnknownOptions()) {
+ ignoreUnknownOptions = true;
+ }
+
r = handleOption(opt, argc, argv, &i, &optionsAllowed);
} else {
/* Argument. */