From 2af7ab3b168e5239b65858251da93670357a8312 Mon Sep 17 00:00:00 2001 From: Alastair Donaldson Date: Thu, 29 Sep 2022 14:36:08 +0000 Subject: [PATCH] Add missing operator to regex fuzzer Fixes a problem where the regex fuzzer would identify '==' as a candidate operator for replacement, but where the replacement code did not actually handle the '==' case. Fixes http://crbug.com/1367902 Change-Id: I9a3bda9e7bae5e42872f17427419ab690d477533 Change-Id: If9cbb2db779c6873ff7a02d132981e8ee3410bb1 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/104200 Commit-Queue: Ben Clayton Kokoro: Kokoro Reviewed-by: Ben Clayton Auto-Submit: Alastair Donaldson --- .../fuzzers/tint_regex_fuzzer/wgsl_mutator.cc | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/tint/fuzzers/tint_regex_fuzzer/wgsl_mutator.cc b/src/tint/fuzzers/tint_regex_fuzzer/wgsl_mutator.cc index c5125a4143..7d16aadc72 100644 --- a/src/tint/fuzzers/tint_regex_fuzzer/wgsl_mutator.cc +++ b/src/tint/fuzzers/tint_regex_fuzzer/wgsl_mutator.cc @@ -416,7 +416,7 @@ std::string WgslMutator::ChooseRandomReplacementForOperator(const std::string& e "=", "+=", "-=", "*=", "/=", "%=", "&=", "|=", "^=", "<<=", ">>="}; std::vector expression_operators{"+", "-", "*", "/", "%", "&&", "||", "&", "|", "^", "<<", ">>", "<", ">", - "<=", ">=", "!", "!=", "~"}; + "<=", ">=", "!", "==", "!=", "~"}; std::vector increment_operators{"++", "--"}; for (auto operators : {assignment_operators, expression_operators, increment_operators}) { auto it = std::find(operators.begin(), operators.end(), existing_operator); @@ -471,6 +471,12 @@ std::optional> WgslMutator::FindOperatorOccurrence switch (first_character) { case '!': case '^': + case '*': + case '/': + case '%': + case '=': + // The above cases are all stand-alone operators, and if followed by '=' are also + // operators. switch (second_character) { case '=': return {{current_index, 2}}; @@ -481,26 +487,15 @@ std::optional> WgslMutator::FindOperatorOccurrence case '&': case '+': case '-': + // The above cases are all stand-alone operators, and if repeated or followed by '=' + // are also operators. if (second_character == first_character || second_character == '=') { return {{current_index, 2}}; } return {{current_index, 1}}; - case '*': - case '/': - case '%': - switch (second_character) { - case '=': - return {{current_index, 2}}; - default: - return {{current_index, 1}}; - } - case '=': - if (second_character == '=') { - return {{current_index, 2}}; - } - return {{current_index, 1}}; case '<': case '>': + // The following caters for '<', '<=', '<<', '<<=', '>', '>=', '>>' and '>>='. if (second_character == '=') { return {{current_index, 2}}; }