Update newling handling in fuzzing CLI tools (#7428)

* Fuzzing initcode fix

Make sure each response has a newline

Signed-off-by: Danno Ferrin <danno@numisight.com>

* correct blank line handling

Signed-off-by: Danno Ferrin <danno@numisight.com>

* correct blank line handling

Signed-off-by: Danno Ferrin <danno@numisight.com>

---------

Signed-off-by: Danno Ferrin <danno@numisight.com>
pull/7430/head
Danno Ferrin 4 months ago committed by GitHub
parent 541aacd200
commit 7433c8c25a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 18
      ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/CodeValidateSubCommand.java
  2. 2
      ethereum/evmtool/src/test/resources/org/hyperledger/besu/evmtool/code-validate/initcode.json

@ -39,6 +39,7 @@ import java.util.stream.Collectors;
import java.util.stream.IntStream;
import org.apache.tuweni.bytes.Bytes;
import org.web3j.utils.Strings;
import picocli.CommandLine;
import picocli.CommandLine.ParentCommand;
@ -107,7 +108,10 @@ public class CodeValidateSubCommand implements Runnable {
}
} else {
for (String code : cliCode) {
parentCommand.out.print(considerCode(code));
String validation = considerCode(code);
if (!Strings.isBlank(validation)) {
parentCommand.out.println(validation);
}
}
}
parentCommand.out.flush();
@ -116,7 +120,10 @@ public class CodeValidateSubCommand implements Runnable {
private void checkCodeFromBufferedReader(final BufferedReader in) {
try {
for (String code = in.readLine(); code != null; code = in.readLine()) {
parentCommand.out.print(considerCode(code));
String validation = considerCode(code);
if (!Strings.isBlank(validation)) {
parentCommand.out.println(validation);
}
}
} catch (IOException e) {
throw new RuntimeException(e);
@ -142,7 +149,7 @@ public class CodeValidateSubCommand implements Runnable {
Bytes.fromHexString(
hexCode.replaceAll("(^|\n)#[^\n]*($|\n)", "").replaceAll("[^0-9A-Za-z]", ""));
} catch (RuntimeException re) {
return "err: hex string -" + re + "\n";
return "err: hex string -" + re;
}
if (codeBytes.isEmpty()) {
return "";
@ -150,7 +157,7 @@ public class CodeValidateSubCommand implements Runnable {
EOFLayout layout = evm.parseEOF(codeBytes);
if (!layout.isValid()) {
return "err: layout - " + layout.invalidReason() + "\n";
return "err: layout - " + layout.invalidReason();
}
Code code = evm.getCodeUncached(codeBytes);
@ -165,8 +172,7 @@ public class CodeValidateSubCommand implements Runnable {
.mapToObj(code::getCodeSection)
.map(cs -> code.getBytes().slice(cs.getEntryPoint(), cs.getLength()))
.map(Bytes::toUnprefixedHexString)
.collect(Collectors.joining(","))
+ "\n";
.collect(Collectors.joining(","));
}
}
}

@ -3,5 +3,5 @@
"code-validate"
],
"stdin": "ef000101000402000100060300010014040000000080000260006000ee00ef00010100040200010001040000000080000000",
"stdout": "err: code is valid initcode. Runtime code expected"
"stdout": "err: code is valid initcode. Runtime code expected\n"
}

Loading…
Cancel
Save