mirror of
https://github.com/simonask/libyaml-safer
synced 2024-11-23 03:43:03 +00:00
Remove malloc null checks
This commit is contained in:
parent
5d421b89e9
commit
85bc4324fc
5 changed files with 180 additions and 260 deletions
21
src/api.rs
21
src/api.rs
|
@ -59,9 +59,6 @@ pub(crate) unsafe fn yaml_string_extend(
|
|||
*start as *mut libc::c_void,
|
||||
((*end).c_offset_from(*start) as libc::c_long * 2_i64) as size_t,
|
||||
) as *mut yaml_char_t;
|
||||
if new_start.is_null() {
|
||||
return FAIL;
|
||||
}
|
||||
memset(
|
||||
new_start.wrapping_offset((*end).c_offset_from(*start) as libc::c_long as isize)
|
||||
as *mut libc::c_void,
|
||||
|
@ -118,9 +115,6 @@ pub(crate) unsafe fn yaml_stack_extend(
|
|||
((*end as *mut libc::c_char).c_offset_from(*start as *mut libc::c_char) as libc::c_long
|
||||
* 2_i64) as size_t,
|
||||
);
|
||||
if new_start.is_null() {
|
||||
return FAIL;
|
||||
}
|
||||
*top = (new_start as *mut libc::c_char).wrapping_offset(
|
||||
(*top as *mut libc::c_char).c_offset_from(*start as *mut libc::c_char) as libc::c_long
|
||||
as isize,
|
||||
|
@ -145,9 +139,6 @@ pub(crate) unsafe fn yaml_queue_extend(
|
|||
((*end as *mut libc::c_char).c_offset_from(*start as *mut libc::c_char) as libc::c_long
|
||||
* 2_i64) as size_t,
|
||||
);
|
||||
if new_start.is_null() {
|
||||
return FAIL;
|
||||
}
|
||||
*head = (new_start as *mut libc::c_char).wrapping_offset(
|
||||
(*head as *mut libc::c_char).c_offset_from(*start as *mut libc::c_char) as libc::c_long
|
||||
as isize,
|
||||
|
@ -697,13 +688,9 @@ pub unsafe fn yaml_document_start_event_initialize(
|
|||
if !version_directive.is_null() {
|
||||
version_directive_copy = yaml_malloc(size_of::<yaml_version_directive_t>() as libc::c_ulong)
|
||||
as *mut yaml_version_directive_t;
|
||||
if version_directive_copy.is_null() {
|
||||
current_block = 14964981520188694172;
|
||||
} else {
|
||||
(*version_directive_copy).major = (*version_directive).major;
|
||||
(*version_directive_copy).minor = (*version_directive).minor;
|
||||
current_block = 1394248824506584008;
|
||||
}
|
||||
} else {
|
||||
current_block = 1394248824506584008;
|
||||
}
|
||||
|
@ -924,7 +911,6 @@ pub unsafe fn yaml_scalar_event_initialize(
|
|||
}
|
||||
if yaml_check_utf8(value, length as size_t).ok {
|
||||
value_copy = yaml_malloc((length + 1) as size_t) as *mut yaml_char_t;
|
||||
if !value_copy.is_null() {
|
||||
memcpy(
|
||||
value_copy as *mut libc::c_void,
|
||||
value as *const libc::c_void,
|
||||
|
@ -954,7 +940,6 @@ pub unsafe fn yaml_scalar_event_initialize(
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
yaml_free(anchor_copy as *mut libc::c_void);
|
||||
|
@ -1253,13 +1238,9 @@ pub unsafe fn yaml_document_initialize(
|
|||
version_directive_copy =
|
||||
yaml_malloc(size_of::<yaml_version_directive_t>() as libc::c_ulong)
|
||||
as *mut yaml_version_directive_t;
|
||||
if version_directive_copy.is_null() {
|
||||
current_block = 8142820162064489797;
|
||||
} else {
|
||||
(*version_directive_copy).major = (*version_directive).major;
|
||||
(*version_directive_copy).minor = (*version_directive).minor;
|
||||
current_block = 7746791466490516765;
|
||||
}
|
||||
} else {
|
||||
current_block = 7746791466490516765;
|
||||
}
|
||||
|
@ -1480,7 +1461,6 @@ pub unsafe fn yaml_document_add_scalar(
|
|||
}
|
||||
if yaml_check_utf8(value, length as size_t).ok {
|
||||
value_copy = yaml_malloc((length + 1) as size_t) as *mut yaml_char_t;
|
||||
if !value_copy.is_null() {
|
||||
memcpy(
|
||||
value_copy as *mut libc::c_void,
|
||||
value as *const libc::c_void,
|
||||
|
@ -1506,7 +1486,6 @@ pub unsafe fn yaml_document_add_scalar(
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
yaml_free(tag_copy as *mut libc::c_void);
|
||||
yaml_free(value_copy as *mut libc::c_void);
|
||||
0
|
||||
|
|
|
@ -119,14 +119,12 @@ pub unsafe fn yaml_emitter_dump(
|
|||
.wrapping_mul((*document).nodes.top.c_offset_from((*document).nodes.start)
|
||||
as libc::c_long as libc::c_ulong),
|
||||
) as *mut yaml_anchors_t;
|
||||
if !(*emitter).anchors.is_null() {
|
||||
memset(
|
||||
(*emitter).anchors as *mut libc::c_void,
|
||||
0,
|
||||
(size_of::<yaml_anchors_t>() as libc::c_ulong).wrapping_mul(
|
||||
(*document).nodes.top.c_offset_from((*document).nodes.start)
|
||||
as libc::c_long as libc::c_ulong,
|
||||
),
|
||||
(size_of::<yaml_anchors_t>() as libc::c_ulong)
|
||||
.wrapping_mul((*document).nodes.top.c_offset_from((*document).nodes.start)
|
||||
as libc::c_long as libc::c_ulong),
|
||||
);
|
||||
memset(
|
||||
event as *mut libc::c_void,
|
||||
|
@ -139,8 +137,7 @@ pub unsafe fn yaml_emitter_dump(
|
|||
(*event).data.document_start.version_directive = (*document).version_directive;
|
||||
(*event).data.document_start.tag_directives.start =
|
||||
(*document).tag_directives.start;
|
||||
(*event).data.document_start.tag_directives.end =
|
||||
(*document).tag_directives.end;
|
||||
(*event).data.document_start.tag_directives.end = (*document).tag_directives.end;
|
||||
(*event).data.document_start.implicit = (*document).start_implicit;
|
||||
if yaml_emitter_emit(emitter, event).ok {
|
||||
yaml_emitter_anchor_node(emitter, 1);
|
||||
|
@ -162,7 +159,6 @@ pub unsafe fn yaml_emitter_dump(
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
yaml_emitter_delete_document_and_anchors(emitter);
|
||||
|
@ -261,9 +257,6 @@ unsafe fn yaml_emitter_generate_anchor(
|
|||
anchor_id: libc::c_int,
|
||||
) -> *mut yaml_char_t {
|
||||
let anchor: *mut yaml_char_t = yaml_malloc(16_u64) as *mut yaml_char_t;
|
||||
if anchor.is_null() {
|
||||
return ptr::null_mut::<yaml_char_t>();
|
||||
}
|
||||
write!(WriteToPtr::new(anchor), "id{:03}\0", anchor_id);
|
||||
anchor
|
||||
}
|
||||
|
@ -278,9 +271,6 @@ unsafe fn yaml_emitter_dump_node(emitter: *mut yaml_emitter_t, index: libc::c_in
|
|||
let mut anchor: *mut yaml_char_t = ptr::null_mut::<yaml_char_t>();
|
||||
if anchor_id != 0 {
|
||||
anchor = yaml_emitter_generate_anchor(emitter, anchor_id);
|
||||
if anchor.is_null() {
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
if (*(*emitter).anchors.wrapping_offset((index - 1) as isize)).serialized {
|
||||
return yaml_emitter_dump_alias(emitter, anchor);
|
||||
|
|
|
@ -2,7 +2,6 @@ macro_rules! BUFFER_INIT {
|
|||
($context:expr, $buffer:expr, $size:expr) => {{
|
||||
let start = addr_of_mut!($buffer.start);
|
||||
*start = yaml_malloc($size as size_t) as *mut yaml_char_t;
|
||||
if !(*start).is_null() {
|
||||
let pointer = addr_of_mut!($buffer.pointer);
|
||||
*pointer = $buffer.start;
|
||||
let last = addr_of_mut!($buffer.last);
|
||||
|
@ -10,10 +9,6 @@ macro_rules! BUFFER_INIT {
|
|||
let end = addr_of_mut!($buffer.end);
|
||||
*end = $buffer.start.wrapping_add($size as usize);
|
||||
OK
|
||||
} else {
|
||||
(*$context).error = YAML_MEMORY_ERROR;
|
||||
FAIL
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
|
@ -42,15 +37,10 @@ macro_rules! STRING_ASSIGN {
|
|||
macro_rules! STRING_INIT {
|
||||
($context:expr, $string:expr) => {{
|
||||
$string.start = yaml_malloc(16) as *mut yaml_char_t;
|
||||
if !$string.start.is_null() {
|
||||
$string.pointer = $string.start;
|
||||
$string.end = $string.start.wrapping_add(16);
|
||||
memset($string.start as *mut libc::c_void, 0, 16);
|
||||
OK
|
||||
} else {
|
||||
(*$context).error = YAML_MEMORY_ERROR;
|
||||
FAIL
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
|
@ -374,14 +364,9 @@ macro_rules! COPY {
|
|||
macro_rules! STACK_INIT {
|
||||
($context:expr, $stack:expr, $type:ty) => {{
|
||||
$stack.start = yaml_malloc(16 * size_of::<$type>() as libc::c_ulong) as *mut $type;
|
||||
if !$stack.start.is_null() {
|
||||
$stack.top = $stack.start;
|
||||
$stack.end = $stack.start.offset(16_isize);
|
||||
OK
|
||||
} else {
|
||||
(*$context).error = YAML_MEMORY_ERROR;
|
||||
FAIL
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
|
@ -448,15 +433,10 @@ macro_rules! POP {
|
|||
macro_rules! QUEUE_INIT {
|
||||
($context:expr, $queue:expr, $type:ty) => {{
|
||||
$queue.start = yaml_malloc(16 * size_of::<$type>() as libc::c_ulong) as *mut $type;
|
||||
if !$queue.start.is_null() {
|
||||
$queue.tail = $queue.start;
|
||||
$queue.head = $queue.tail;
|
||||
$queue.end = $queue.start.offset(16_isize);
|
||||
OK
|
||||
} else {
|
||||
(*$context).error = YAML_MEMORY_ERROR;
|
||||
FAIL
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
|
|
|
@ -519,19 +519,13 @@ unsafe fn yaml_parser_parse_node(
|
|||
tag = yaml_malloc(
|
||||
prefix_len.wrapping_add(suffix_len).wrapping_add(1_u64),
|
||||
) as *mut yaml_char_t;
|
||||
if tag.is_null() {
|
||||
(*parser).error = YAML_MEMORY_ERROR;
|
||||
current_block = 17786380918591080555;
|
||||
break;
|
||||
} else {
|
||||
memcpy(
|
||||
tag as *mut libc::c_void,
|
||||
(*tag_directive).prefix as *const libc::c_void,
|
||||
prefix_len,
|
||||
);
|
||||
memcpy(
|
||||
tag.wrapping_offset(prefix_len as isize)
|
||||
as *mut libc::c_void,
|
||||
tag.wrapping_offset(prefix_len as isize) as *mut libc::c_void,
|
||||
tag_suffix as *const libc::c_void,
|
||||
suffix_len,
|
||||
);
|
||||
|
@ -544,7 +538,6 @@ unsafe fn yaml_parser_parse_node(
|
|||
tag_handle = tag_suffix;
|
||||
current_block = 17728966195399430138;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
tag_directive = tag_directive.wrapping_offset(1);
|
||||
}
|
||||
|
@ -705,9 +698,6 @@ unsafe fn yaml_parser_parse_node(
|
|||
return OK;
|
||||
} else if !anchor.is_null() || !tag.is_null() {
|
||||
let value: *mut yaml_char_t = yaml_malloc(1_u64) as *mut yaml_char_t;
|
||||
if value.is_null() {
|
||||
(*parser).error = YAML_MEMORY_ERROR;
|
||||
} else {
|
||||
*value = b'\0';
|
||||
(*parser).state = POP!((*parser).states);
|
||||
memset(
|
||||
|
@ -729,7 +719,6 @@ unsafe fn yaml_parser_parse_node(
|
|||
(*event).data.scalar.quoted_implicit = false;
|
||||
(*event).data.scalar.style = YAML_PLAIN_SCALAR_STYLE;
|
||||
return OK;
|
||||
}
|
||||
} else {
|
||||
yaml_parser_set_parser_error_context(
|
||||
parser,
|
||||
|
@ -1257,15 +1246,11 @@ unsafe fn yaml_parser_parse_flow_mapping_value(
|
|||
}
|
||||
|
||||
unsafe fn yaml_parser_process_empty_scalar(
|
||||
mut parser: *mut yaml_parser_t,
|
||||
_parser: *mut yaml_parser_t,
|
||||
mut event: *mut yaml_event_t,
|
||||
mark: yaml_mark_t,
|
||||
) -> Success {
|
||||
let value: *mut yaml_char_t = yaml_malloc(1_u64) as *mut yaml_char_t;
|
||||
if value.is_null() {
|
||||
(*parser).error = YAML_MEMORY_ERROR;
|
||||
return FAIL;
|
||||
}
|
||||
*value = b'\0';
|
||||
memset(
|
||||
event as *mut libc::c_void,
|
||||
|
@ -1359,15 +1344,9 @@ unsafe fn yaml_parser_process_directives(
|
|||
version_directive =
|
||||
yaml_malloc(size_of::<yaml_version_directive_t>() as libc::c_ulong)
|
||||
as *mut yaml_version_directive_t;
|
||||
if version_directive.is_null() {
|
||||
(*parser).error = YAML_MEMORY_ERROR;
|
||||
current_block = 17143798186130252483;
|
||||
break;
|
||||
} else {
|
||||
(*version_directive).major = (*token).data.version_directive.major;
|
||||
(*version_directive).minor = (*token).data.version_directive.minor;
|
||||
}
|
||||
}
|
||||
} else if (*token).type_ == YAML_TAG_DIRECTIVE_TOKEN {
|
||||
let value = yaml_tag_directive_t {
|
||||
handle: (*token).data.tag_directive.handle,
|
||||
|
|
|
@ -1173,7 +1173,7 @@ unsafe fn yaml_parser_scan_directive(
|
|||
}
|
||||
|
||||
unsafe fn yaml_parser_scan_directive_name(
|
||||
mut parser: *mut yaml_parser_t,
|
||||
parser: *mut yaml_parser_t,
|
||||
start_mark: yaml_mark_t,
|
||||
name: *mut *mut yaml_char_t,
|
||||
) -> Success {
|
||||
|
@ -1405,7 +1405,7 @@ unsafe fn yaml_parser_scan_tag_directive_value(
|
|||
}
|
||||
|
||||
unsafe fn yaml_parser_scan_anchor(
|
||||
mut parser: *mut yaml_parser_t,
|
||||
parser: *mut yaml_parser_t,
|
||||
mut token: *mut yaml_token_t,
|
||||
type_: yaml_token_type_t,
|
||||
) -> Success {
|
||||
|
@ -1505,9 +1505,6 @@ unsafe fn yaml_parser_scan_tag(
|
|||
if CACHE(parser, 2_u64).ok {
|
||||
if CHECK_AT!((*parser).buffer, b'<', 1) {
|
||||
handle = yaml_malloc(1_u64) as *mut yaml_char_t;
|
||||
if handle.is_null() {
|
||||
current_block = 17708497480799081542;
|
||||
} else {
|
||||
*handle = b'\0';
|
||||
SKIP(parser);
|
||||
SKIP(parser);
|
||||
|
@ -1534,7 +1531,6 @@ unsafe fn yaml_parser_scan_tag(
|
|||
SKIP(parser);
|
||||
current_block = 4488286894823169796;
|
||||
}
|
||||
}
|
||||
} else if yaml_parser_scan_tag_handle(parser, false, start_mark, addr_of_mut!(handle)).fail
|
||||
{
|
||||
current_block = 17708497480799081542;
|
||||
|
@ -1572,9 +1568,6 @@ unsafe fn yaml_parser_scan_tag(
|
|||
} else {
|
||||
yaml_free(handle as *mut libc::c_void);
|
||||
handle = yaml_malloc(2_u64) as *mut yaml_char_t;
|
||||
if handle.is_null() {
|
||||
current_block = 17708497480799081542;
|
||||
} else {
|
||||
*handle = b'!';
|
||||
*handle.wrapping_offset(1_isize) = b'\0';
|
||||
if *suffix == b'\0' {
|
||||
|
@ -1584,7 +1577,6 @@ unsafe fn yaml_parser_scan_tag(
|
|||
}
|
||||
current_block = 4488286894823169796;
|
||||
}
|
||||
}
|
||||
match current_block {
|
||||
17708497480799081542 => {}
|
||||
_ => {
|
||||
|
@ -1634,7 +1626,7 @@ unsafe fn yaml_parser_scan_tag(
|
|||
}
|
||||
|
||||
unsafe fn yaml_parser_scan_tag_handle(
|
||||
mut parser: *mut yaml_parser_t,
|
||||
parser: *mut yaml_parser_t,
|
||||
directive: bool,
|
||||
start_mark: yaml_mark_t,
|
||||
handle: *mut *mut yaml_char_t,
|
||||
|
|
Loading…
Reference in a new issue