From 75eddf785fedc2aeb9bf96db5a9bee97f7e4e72e Mon Sep 17 00:00:00 2001 From: Reini Urban Date: Wed, 4 May 2016 08:53:47 +0200 Subject: [PATCH 1/6] fix C++-compat error we cannot malloc to an anon struct in C++. typedef yaml_anchors_t --- include/yaml.h | 21 +++++++++++++-------- src/dumper.c | 2 +- src/emitter.c | 2 +- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/include/yaml.h b/include/yaml.h index 97f655a0..c225908d 100644 --- a/include/yaml.h +++ b/include/yaml.h @@ -1517,6 +1517,18 @@ typedef enum yaml_emitter_state_e { YAML_EMIT_END_STATE } yaml_emitter_state_t; + +/* This is needed for C++ */ + +typedef struct yaml_anchors_s { + /** The number of references. */ + int references; + /** The anchor id. */ + int anchor; + /** If the node has been emitted? */ + int serialized; +} yaml_anchors_t; + /** * The emitter structure. * @@ -1742,14 +1754,7 @@ typedef struct yaml_emitter_s { int closed; /** The information associated with the document nodes. */ - struct { - /** The number of references. */ - int references; - /** The anchor id. */ - int anchor; - /** If the node has been emitted? */ - int serialized; - } *anchors; + yaml_anchors_t *anchors; /** The last assigned anchor id. */ int last_anchor_id; diff --git a/src/dumper.c b/src/dumper.c index 29fb9c07..1fe940b6 100644 --- a/src/dumper.c +++ b/src/dumper.c @@ -131,7 +131,7 @@ yaml_emitter_dump(yaml_emitter_t *emitter, yaml_document_t *document) assert(emitter->opened); /* Emitter should be opened. */ - emitter->anchors = yaml_malloc(sizeof(*(emitter->anchors)) + emitter->anchors = (yaml_anchors_t*)yaml_malloc(sizeof(*(emitter->anchors)) * (document->nodes.top - document->nodes.start)); if (!emitter->anchors) goto error; memset(emitter->anchors, 0, sizeof(*(emitter->anchors)) diff --git a/src/emitter.c b/src/emitter.c index 1400df1c..9dc27cb9 100644 --- a/src/emitter.c +++ b/src/emitter.c @@ -16,7 +16,7 @@ #define PUT(emitter,value) \ (FLUSH(emitter) \ && (*(emitter->buffer.pointer++) = (yaml_char_t)(value), \ - emitter->column ++, \ + emitter->column++, \ 1)) /* From 551ad48994360f994af0649686885aa3946e029f Mon Sep 17 00:00:00 2001 From: Reini Urban Date: Tue, 13 Sep 2016 15:37:56 +0200 Subject: [PATCH 2/6] fix clang -Wlogical-op warnings Commit amended by @perlpunk after suggestion from @tlsa --- src/scanner.c | 2 +- src/yaml_private.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/scanner.c b/src/scanner.c index cbe5c6fd..ceee7496 100644 --- a/src/scanner.c +++ b/src/scanner.c @@ -2860,7 +2860,7 @@ yaml_parser_scan_block_scalar(yaml_parser_t *parser, yaml_token_t *token, if (!CACHE(parser, 1)) goto error; - while ((int)parser->mark.column == indent && !IS_Z(parser->buffer)) + while ((int)parser->mark.column == indent && !(IS_Z(parser->buffer))) { /* * We are at the beginning of a non-empty line. diff --git a/src/yaml_private.h b/src/yaml_private.h index eb722077..d2971b8c 100644 --- a/src/yaml_private.h +++ b/src/yaml_private.h @@ -171,14 +171,14 @@ yaml_string_join( * Check the octet at the specified position. */ -#define CHECK_AT(string,octet,offset) \ +#define CHECK_AT(string,octet,offset) \ ((string).pointer[offset] == (yaml_char_t)(octet)) /* * Check the current octet in the buffer. */ -#define CHECK(string,octet) CHECK_AT((string),(octet),0) +#define CHECK(string,octet) (CHECK_AT((string),(octet),0)) /* * Check if the character at the specified position is an alphabetical From 5b8859f728655747e01f202f71d52d863d18079e Mon Sep 17 00:00:00 2001 From: Reini Urban Date: Sun, 20 Nov 2016 17:55:52 +0100 Subject: [PATCH 3/6] fix C++ g++-6 errors yaml_emitter_write_indicator const char *indicator --- src/emitter.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/emitter.c b/src/emitter.c index 9dc27cb9..b9392e40 100644 --- a/src/emitter.c +++ b/src/emitter.c @@ -221,7 +221,7 @@ yaml_emitter_write_indent(yaml_emitter_t *emitter); static int yaml_emitter_write_indicator(yaml_emitter_t *emitter, - char *indicator, int need_whitespace, + const char *indicator, int need_whitespace, int is_whitespace, int is_indention); static int @@ -1777,7 +1777,7 @@ yaml_emitter_write_indent(yaml_emitter_t *emitter) static int yaml_emitter_write_indicator(yaml_emitter_t *emitter, - char *indicator, int need_whitespace, + const char *indicator, int need_whitespace, int is_whitespace, int is_indention) { size_t indicator_length; @@ -2174,7 +2174,7 @@ yaml_emitter_write_block_scalar_hints(yaml_emitter_t *emitter, yaml_string_t string) { char indent_hint[2]; - char *chomp_hint = NULL; + const char *chomp_hint = NULL; if (IS_SPACE(string) || IS_BREAK(string)) { From 96a49a1d9c771b1f7f29e8021abbb49c59f9b9a7 Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Mon, 3 Feb 2014 16:48:01 -0800 Subject: [PATCH 4/6] yaml_stack_extend: guard against integer overflow --- src/api.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/api.c b/src/api.c index b0afd1f5..e793b085 100644 --- a/src/api.c +++ b/src/api.c @@ -118,7 +118,12 @@ yaml_string_join( YAML_DECLARE(int) yaml_stack_extend(void **start, void **top, void **end) { - void *new_start = yaml_realloc(*start, ((char *)*end - (char *)*start)*2); + void *new_start; + + if ((char *)*end - (char *)*start >= INT_MAX / 2) + return 0; + + new_start = yaml_realloc(*start, ((char *)*end - (char *)*start)*2); if (!new_start) return 0; From f0330018390eb73ae2dead53467a59ad76d67d5e Mon Sep 17 00:00:00 2001 From: Reini Urban Date: Thu, 30 Mar 2017 09:49:15 +0200 Subject: [PATCH 5/6] fix version_directive memory leak detected by coverity --- src/parser.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/parser.c b/src/parser.c index 621f676b..6e3918ed 100644 --- a/src/parser.c +++ b/src/parser.c @@ -1316,6 +1316,7 @@ yaml_parser_process_directives(yaml_parser_t *parser, STACK_DEL(parser, tag_directives); } + yaml_free(version_directive); return 1; error: From df5c05e12080c6f710da54b6e3348288f3506d46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tina=20M=C3=BCller?= Date: Wed, 18 Jul 2018 23:36:05 +0200 Subject: [PATCH 6/6] Fix unconditional yaml_free() Thanks to @tlsa for spotting this --- src/parser.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/parser.c b/src/parser.c index 6e3918ed..1198c737 100644 --- a/src/parser.c +++ b/src/parser.c @@ -1316,7 +1316,8 @@ yaml_parser_process_directives(yaml_parser_t *parser, STACK_DEL(parser, tag_directives); } - yaml_free(version_directive); + if (!version_directive_ref) + yaml_free(version_directive); return 1; error: