Fix fuzzer

This commit is contained in:
Simon Ask Ulsnes 2024-02-04 14:27:19 +01:00
parent 9b41218d0f
commit 417a4baccc
3 changed files with 13 additions and 15 deletions

View file

@ -1,18 +1,16 @@
#![no_main] #![no_main]
use libfuzzer_sys::fuzz_target; use libfuzzer_sys::fuzz_target;
use libyaml_safer::{ use libyaml_safer::{Document, Parser};
yaml_document_get_root_node, yaml_parser_load, yaml_parser_new, yaml_parser_set_input,
};
fuzz_target!(|data: &[u8]| fuzz_target(data)); fuzz_target!(|data: &[u8]| fuzz_target(data));
fn fuzz_target(mut data: &[u8]) { fn fuzz_target(mut data: &[u8]) {
let mut parser = yaml_parser_new(); let mut parser = Parser::new();
yaml_parser_set_input(&mut parser, &mut data); parser.set_input(&mut data);
while let Ok(mut document) = yaml_parser_load(&mut parser) { while let Ok(mut document) = Document::load(&mut parser) {
let done = yaml_document_get_root_node(&mut document).is_none(); let done = document.get_root_node().is_none();
if done { if done {
break; break;
} }

View file

@ -1,15 +1,15 @@
#![no_main] #![no_main]
use libfuzzer_sys::fuzz_target; use libfuzzer_sys::fuzz_target;
use libyaml_safer::{yaml_parser_new, yaml_parser_parse, yaml_parser_set_input, EventData}; use libyaml_safer::{EventData, Parser};
fuzz_target!(|data: &[u8]| fuzz_target(data)); fuzz_target!(|data: &[u8]| fuzz_target(data));
fn fuzz_target(mut data: &[u8]) { fn fuzz_target(mut data: &[u8]) {
let mut parser = yaml_parser_new(); let mut parser = Parser::new();
yaml_parser_set_input(&mut parser, &mut data); parser.set_input(&mut data);
while let Ok(event) = yaml_parser_parse(&mut parser) { while let Ok(event) = parser.parse() {
let is_end = matches!(event.data, EventData::StreamEnd); let is_end = matches!(event.data, EventData::StreamEnd);
if is_end { if is_end {
break; break;

View file

@ -1,15 +1,15 @@
#![no_main] #![no_main]
use libfuzzer_sys::fuzz_target; use libfuzzer_sys::fuzz_target;
use libyaml_safer::{yaml_parser_new, yaml_parser_scan, yaml_parser_set_input, TokenData}; use libyaml_safer::{Scanner, TokenData};
fuzz_target!(|data: &[u8]| fuzz_target(data)); fuzz_target!(|data: &[u8]| fuzz_target(data));
fn fuzz_target(mut data: &[u8]) { fn fuzz_target(mut data: &[u8]) {
let mut parser = yaml_parser_new(); let mut scanner = Scanner::new();
yaml_parser_set_input(&mut parser, &mut data); scanner.set_input(&mut data);
while let Ok(token) = yaml_parser_scan(&mut parser) { while let Ok(token) = Scanner::scan(&mut scanner) {
let is_end = matches!(token.data, TokenData::StreamEnd); let is_end = matches!(token.data, TokenData::StreamEnd);
if is_end { if is_end {
break; break;