Skip to content

Commit

Permalink
Update newling handling in fuzzing CLI tools (#7428)
Browse files Browse the repository at this point in the history
* Fuzzing initcode fix

Make sure each response has a newline

Signed-off-by: Danno Ferrin <[email protected]>

* correct blank line handling

Signed-off-by: Danno Ferrin <[email protected]>

* correct blank line handling

Signed-off-by: Danno Ferrin <[email protected]>

---------

Signed-off-by: Danno Ferrin <[email protected]>
  • Loading branch information
shemnon authored Aug 6, 2024
1 parent 541aacd commit 7433c8c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand All @@ -142,15 +149,15 @@ 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 "";
}

EOFLayout layout = evm.parseEOF(codeBytes);
if (!layout.isValid()) {
return "err: layout - " + layout.invalidReason() + "\n";
return "err: layout - " + layout.invalidReason();
}

Code code = evm.getCodeUncached(codeBytes);
Expand All @@ -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(","));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit 7433c8c

Please sign in to comment.