Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add guard code to prevent the use of NULL pointers in emitter.c #305

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/emitter.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,9 @@ yaml_emitter_append_tag_directive(yaml_emitter_t *emitter,

error:
yaml_free(copy.handle);
copy.handle = NULL;
yaml_free(copy.prefix);
copy.prefix = NULL;
return 0;
}

Expand Down Expand Up @@ -727,7 +729,9 @@ yaml_emitter_emit_document_end(yaml_emitter_t *emitter,
yaml_tag_directive_t tag_directive = POP(emitter,
emitter->tag_directives);
yaml_free(tag_directive.handle);
tag_directive.handle = NULL;
yaml_free(tag_directive.prefix);
tag_directive.prefix = NULL;
}

return 1;
Expand Down Expand Up @@ -1812,6 +1816,8 @@ yaml_emitter_write_indicator(yaml_emitter_t *emitter,
size_t indicator_length;
yaml_string_t string;

if (!indicator)
return 0;
indicator_length = strlen(indicator);
STRING_ASSIGN(string, (yaml_char_t *)indicator, indicator_length);

Expand All @@ -1834,6 +1840,9 @@ yaml_emitter_write_anchor(yaml_emitter_t *emitter,
yaml_char_t *value, size_t length)
{
yaml_string_t string;
if (!value || length < 1)
return 0;

STRING_ASSIGN(string, value, length);

while (string.pointer != string.end) {
Expand All @@ -1851,6 +1860,9 @@ yaml_emitter_write_tag_handle(yaml_emitter_t *emitter,
yaml_char_t *value, size_t length)
{
yaml_string_t string;

if (!value || length < 1)
return 0;
STRING_ASSIGN(string, value, length);

if (!emitter->whitespace) {
Expand All @@ -1873,6 +1885,9 @@ yaml_emitter_write_tag_content(yaml_emitter_t *emitter,
int need_whitespace)
{
yaml_string_t string;

if (!value || length < 1)
return 0;
STRING_ASSIGN(string, value, length);

if (need_whitespace && !emitter->whitespace) {
Expand Down Expand Up @@ -1923,6 +1938,9 @@ yaml_emitter_write_plain_scalar(yaml_emitter_t *emitter,
int spaces = 0;
int breaks = 0;

if (!value || length < 1)
return 0;

STRING_ASSIGN(string, value, length);

/**
Expand Down Expand Up @@ -1989,6 +2007,9 @@ yaml_emitter_write_single_quoted_scalar(yaml_emitter_t *emitter,
int spaces = 0;
int breaks = 0;

if (!value || length < 1)
return 0;

STRING_ASSIGN(string, value, length);

if (!yaml_emitter_write_indicator(emitter, "'", 1, 0, 0))
Expand Down Expand Up @@ -2054,6 +2075,8 @@ yaml_emitter_write_double_quoted_scalar(yaml_emitter_t *emitter,
yaml_string_t string;
int spaces = 0;

if (!value || length < 1)
return 0;
STRING_ASSIGN(string, value, length);

if (!yaml_emitter_write_indicator(emitter, "\"", 1, 0, 0))
Expand Down Expand Up @@ -2268,6 +2291,8 @@ yaml_emitter_write_literal_scalar(yaml_emitter_t *emitter,
yaml_string_t string;
int breaks = 1;

if (!value || length < 1)
return 0;
STRING_ASSIGN(string, value, length);

if (!yaml_emitter_write_indicator(emitter, "|", 1, 0, 0))
Expand Down Expand Up @@ -2308,6 +2333,8 @@ yaml_emitter_write_folded_scalar(yaml_emitter_t *emitter,
int breaks = 1;
int leading_spaces = 1;

if (!value || length < 1)
return 0;
STRING_ASSIGN(string, value, length);

if (!yaml_emitter_write_indicator(emitter, ">", 1, 0, 0))
Expand Down
Loading