mirror of
https://github.com/simonask/libyaml-safer
synced 2024-11-22 03:13:10 +00:00
Clean up error checking in fuzzer and bins
This commit is contained in:
parent
093886f2d2
commit
a69723b2d8
5 changed files with 9 additions and 9 deletions
|
@ -21,7 +21,7 @@ unsafe fn fuzz_target(mut data: &[u8]) {
|
|||
|
||||
let mut document = MaybeUninit::<yaml_document_t>::uninit();
|
||||
let document = document.as_mut_ptr();
|
||||
while yaml_parser_load(parser, document) != 0 {
|
||||
while yaml_parser_load(parser, document).ok {
|
||||
let done = yaml_document_get_root_node(document).is_null();
|
||||
yaml_document_delete(document);
|
||||
if done {
|
||||
|
|
|
@ -21,7 +21,7 @@ unsafe fn fuzz_target(mut data: &[u8]) {
|
|||
|
||||
let mut event = MaybeUninit::<yaml_event_t>::uninit();
|
||||
let event = event.as_mut_ptr();
|
||||
while yaml_parser_parse(parser, event) != 0 {
|
||||
while yaml_parser_parse(parser, event).ok {
|
||||
let type_ = (*event).type_;
|
||||
yaml_event_delete(event);
|
||||
if type_ == YAML_STREAM_END_EVENT {
|
||||
|
|
|
@ -21,7 +21,7 @@ unsafe fn fuzz_target(mut data: &[u8]) {
|
|||
|
||||
let mut token = MaybeUninit::<yaml_token_t>::uninit();
|
||||
let token = token.as_mut_ptr();
|
||||
while yaml_parser_scan(parser, token) != 0 {
|
||||
while yaml_parser_scan(parser, token).ok {
|
||||
let type_ = (*token).type_;
|
||||
yaml_token_delete(token);
|
||||
if type_ == YAML_STREAM_END_TOKEN {
|
||||
|
|
|
@ -47,7 +47,7 @@ pub(crate) unsafe fn unsafe_main(
|
|||
) -> Result<(), Box<dyn Error>> {
|
||||
let mut emitter = MaybeUninit::<yaml_emitter_t>::uninit();
|
||||
let emitter = emitter.as_mut_ptr();
|
||||
if yaml_emitter_initialize(emitter) == 0 {
|
||||
if !yaml_emitter_initialize(emitter).ok {
|
||||
return Err("Could not initalize the emitter object".into());
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@ pub(crate) unsafe fn unsafe_main(
|
|||
|
||||
let mut anchor = [0u8; 256];
|
||||
let mut tag = [0u8; 256];
|
||||
let ok = if line.starts_with(b"+STR") {
|
||||
let result = if line.starts_with(b"+STR") {
|
||||
yaml_stream_start_event_initialize(event, YAML_UTF8_ENCODING)
|
||||
} else if line.starts_with(b"-STR") {
|
||||
yaml_stream_end_event_initialize(event)
|
||||
|
@ -133,10 +133,10 @@ pub(crate) unsafe fn unsafe_main(
|
|||
break Err(format!("Unknown event: '{}'", CStr::from_ptr(line)).into());
|
||||
};
|
||||
|
||||
if ok == 0 {
|
||||
if !result.ok {
|
||||
break Err("Memory error: Not enough memory for creating an event".into());
|
||||
}
|
||||
if yaml_emitter_emit(emitter, event) == 0 {
|
||||
if !yaml_emitter_emit(emitter, event).ok {
|
||||
break Err(match (*emitter).error {
|
||||
YAML_MEMORY_ERROR => "Memory error: Not enough memory for emitting".into(),
|
||||
YAML_WRITER_ERROR => {
|
||||
|
|
|
@ -40,7 +40,7 @@ pub(crate) unsafe fn unsafe_main(
|
|||
) -> Result<(), Box<dyn Error>> {
|
||||
let mut parser = MaybeUninit::<yaml_parser_t>::uninit();
|
||||
let parser = parser.as_mut_ptr();
|
||||
if yaml_parser_initialize(parser) == 0 {
|
||||
if !yaml_parser_initialize(parser).ok {
|
||||
return Err("Could not initialize the parser object".into());
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,7 @@ pub(crate) unsafe fn unsafe_main(
|
|||
let mut event = MaybeUninit::<yaml_event_t>::uninit();
|
||||
let event = event.as_mut_ptr();
|
||||
loop {
|
||||
if yaml_parser_parse(parser, event) == 0 {
|
||||
if !yaml_parser_parse(parser, event).ok {
|
||||
let mut error = format!("Parse error: {}", CStr::from_ptr((*parser).problem));
|
||||
if (*parser).problem_mark.line != 0 || (*parser).problem_mark.column != 0 {
|
||||
let _ = write!(
|
||||
|
|
Loading…
Reference in a new issue