From 7433c8c25a5c73440c668553befa5fc6363b0c6f Mon Sep 17 00:00:00 2001 From: Danno Ferrin Date: Tue, 6 Aug 2024 01:23:01 -0600 Subject: [PATCH] Update newling handling in fuzzing CLI tools (#7428) * Fuzzing initcode fix Make sure each response has a newline Signed-off-by: Danno Ferrin * correct blank line handling Signed-off-by: Danno Ferrin * correct blank line handling Signed-off-by: Danno Ferrin --------- Signed-off-by: Danno Ferrin --- .../besu/evmtool/CodeValidateSubCommand.java | 18 ++++++++++++------ .../besu/evmtool/code-validate/initcode.json | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/CodeValidateSubCommand.java b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/CodeValidateSubCommand.java index 3bc2d41d02c..962fc2804b7 100644 --- a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/CodeValidateSubCommand.java +++ b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/CodeValidateSubCommand.java @@ -39,6 +39,7 @@ 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 void run() { } } 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 void run() { 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 String considerCode(final String hexCode) { 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 String considerCode(final String hexCode) { 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 String considerCode(final String hexCode) { .mapToObj(code::getCodeSection) .map(cs -> code.getBytes().slice(cs.getEntryPoint(), cs.getLength())) .map(Bytes::toUnprefixedHexString) - .collect(Collectors.joining(",")) - + "\n"; + .collect(Collectors.joining(",")); } } } diff --git a/ethereum/evmtool/src/test/resources/org/hyperledger/besu/evmtool/code-validate/initcode.json b/ethereum/evmtool/src/test/resources/org/hyperledger/besu/evmtool/code-validate/initcode.json index c119235cdc1..5ecd5511a50 100644 --- a/ethereum/evmtool/src/test/resources/org/hyperledger/besu/evmtool/code-validate/initcode.json +++ b/ethereum/evmtool/src/test/resources/org/hyperledger/besu/evmtool/code-validate/initcode.json @@ -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" }