Skip to content

Commit

Permalink
Update fuzzing
Browse files Browse the repository at this point in the history
  • Loading branch information
romainthomas committed Nov 9, 2023
1 parent a975999 commit fcf5dae
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
7 changes: 5 additions & 2 deletions src/ELF/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,11 +562,14 @@ std::unique_ptr<Note> Parser::get_note(uint32_t type, std::string name,

ok_error_t Parser::parse_notes(uint64_t offset, uint64_t size) {
LIEF_DEBUG("== Parsing note segment ==");

stream_->setpos(offset);
uint64_t last_offset = offset + size;

while(stream_->pos() < last_offset) {
if (!*stream_) {
return make_error_code(lief_errors::read_error);
}

while (*stream_ && stream_->pos() < last_offset) {
const auto current_pos = static_cast<int64_t>(stream_->pos());
std::unique_ptr<Note> note = Note::create(
*stream_,
Expand Down
17 changes: 9 additions & 8 deletions tests/elf/fuzzing.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,19 @@ def fuzz(melkor, seed, nb):
outputdir: Path = generate_samples(melkor, seed, nb)
print(outputdir)
for file in outputdir.iterdir():

if not lief.is_elf(file.as_posix()):
continue

print(f"Tring to parse {file!s}")
lief.parse(file.as_posix())

print(f"Trying to parse {file!s}")
subprocess.check_call(
(
sys.executable, "-c",
f"import lief;lief.logging.disable();lief.parse('{file.as_posix()}')"
),
env=os.environ.copy()
)

if __name__ == '__main__':

if not is_linux() and not is_x86_64():
print("Melkor fuzzing is currently only supported on Linux x86-64",
file=sys.stderr)
Expand All @@ -67,6 +70,4 @@ def fuzz(melkor, seed, nb):

args = parser.parse_args()
fuzz(args.melkor, args.input_seed, args.nb_samples)
print(lief)


sys.exit(0)

0 comments on commit fcf5dae

Please sign in to comment.