Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address Windows-shell fuzz crashes #478

Merged
merged 6 commits into from
Oct 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions test/fuzz/_common.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,17 @@ function prepareArg({ arg, quoted, shell }, disableExtraWindowsPreparations) {
if (isShellCmd(shell)) {
// ... in CMD, depending on if the argument is quotes ...
if (quoted) {
// ... interprets arguments with `\"` as `"` (even if there's a
// null character between `\` and `"`) so we escape the `\`.
arg = arg.replace(/(?<!\\)((?:\\\0*)+)(?="|$)/gu, "$1$1");
// ... interprets arguments with `\"` as `"` so we escape the `\`.
arg = arg.replace(
/(?<!\\)((?:\\[\0\u0008\u001B\u009B]*)+)(?="|$)/gu,
"$1$1"
);
} else {
// ... interprets arguments with `\"` as `"` so we escape the `\` ...
arg = arg.replace(/(?<!\\)((?:\\\0*)+)(?=")/gu, "$1$1");
arg = arg.replace(
/(?<!\\)((?:\\[\0\u0008\u001B\u009B]*)+)(?=")/gu,
"$1$1"
);

// ... interprets arguments with `"` as `` so we escape it with `\`.
arg = arg.replace(/"/gu, `\\"`);
Expand All @@ -136,14 +141,18 @@ function prepareArg({ arg, quoted, shell }, disableExtraWindowsPreparations) {
// extra double quotes as `""""` ...
arg = arg.replace(/"/gu, `""`);

// ... and interprets arguments with `\"` as `"` (even if there's a null
// character between `\` and `"`) so we escape the `\`.
arg = arg.replace(/(?<!\\)((?:\\\0*)+)(?="|\r?$)/gu, "$1$1");
// ... and interprets arguments with `\"` as `"` so we escape the `\`.
arg = arg.replace(
/(?<!\\)((?:\\(?:[\0\u0008\u001B\u009B]|\r(?!\n))*)+)(?="|$)/gu,
"$1$1"
);
} else {
// ... interprets arguments with `\"` as `"` (even if there's a null
// character between `\` and `"`) so we escape the `\`, except that the
// quote closing the argument cannot be escaped ...
arg = arg.replace(/(?<!\\)((?:\\\0*)+)(?=")/gu, "$1$1");
// ... interprets arguments with `\"` as `"` so we escape the `\`,
// except that the quote closing the argument cannot be escaped ...
arg = arg.replace(
/(?<!\\)((?:\\[\0\u0008\r\u001B\u009B]*)+)(?=")/gu,
"$1$1"
);

// ... and interprets arguments with `"` as nothing so we escape it
// with `\"`.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
L�\\\
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[9\\