diff options
author | Ingy döt Net <ingy@ingy.net> | 2014-11-28 08:37:00 -0800 |
---|---|---|
committer | Ingy döt Net <ingy@ingy.net> | 2014-11-28 08:37:00 -0800 |
commit | eebdd8b84defa1166f9fd0fc4b46258a47d94576 (patch) | |
tree | 6f158b453290c6644a8d6a62f412b4820162cd4c | |
parent | a472774ad1550307ef7bcf396f99d0d72ffa3dc5 (diff) | |
download | libyaml-git-eebdd8b84defa1166f9fd0fc4b46258a47d94576.tar.gz |
Sync to head of https://bitbucket.org/xi/libyaml
-rw-r--r-- | CMakeLists.txt | 16 | ||||
-rw-r--r-- | Makefile.am | 4 | ||||
-rw-r--r-- | configure.ac | 4 | ||||
-rw-r--r-- | src/api.c | 7 | ||||
-rw-r--r-- | src/loader.c | 12 | ||||
-rw-r--r-- | src/reader.c | 4 | ||||
-rw-r--r-- | src/scanner.c | 82 | ||||
-rw-r--r-- | src/yaml_private.h | 24 | ||||
-rw-r--r-- | win32/config.h | 4 |
9 files changed, 84 insertions, 73 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..e84c28c --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,16 @@ +# Minimal CMake project for building a static library under Windows. + +cmake_minimum_required (VERSION 2.8) +project (yaml C) + +set (YAML_VERSION_MAJOR 0) +set (YAML_VERSION_MINOR 1) +set (YAML_VERSION_PATCH 6) +set (YAML_VERSION_STRING "${YAML_VERSION_MAJOR}.${YAML_VERSION_MINOR}.${YAML_VERSION_PATCH}") + +file (GLOB SRC src/*.c) + +include_directories (include win32) +add_definitions (-DHAVE_CONFIG_H -DYAML_DECLARE_STATIC) +add_library (yaml STATIC ${SRC}) + diff --git a/Makefile.am b/Makefile.am index 891f54a..de2a3cd 100644 --- a/Makefile.am +++ b/Makefile.am @@ -3,7 +3,7 @@ SUBDIRS = include src . tests win32 -EXTRA_DIST = README LICENSE doc/doxygen.cfg +EXTRA_DIST = README LICENSE CMakeLists.txt doc/doxygen.cfg pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = yaml-0.1.pc @@ -16,5 +16,3 @@ maintainer-clean-local: bootstrap: maintainer-clean ./bootstrap -test: - make -C tests check-TESTS diff --git a/configure.ac b/configure.ac index f0fa397..dd1aca0 100644 --- a/configure.ac +++ b/configure.ac @@ -3,7 +3,7 @@ # Define the package version numbers and the bug reporting link. m4_define([YAML_MAJOR], 0) m4_define([YAML_MINOR], 1) -m4_define([YAML_PATCH], 4) +m4_define([YAML_PATCH], 6) m4_define([YAML_BUGS], [http://pyyaml.org/newticket?component=libyaml]) # Define the libtool version numbers; check the Autobook, Section 11.4. @@ -19,7 +19,7 @@ m4_define([YAML_BUGS], [http://pyyaml.org/newticket?component=libyaml]) # YAML_AGE = 0 m4_define([YAML_RELEASE], 0) m4_define([YAML_CURRENT], 2) -m4_define([YAML_REVISION], 2) +m4_define([YAML_REVISION], 4) m4_define([YAML_AGE], 0) # Initialize autoconf & automake. @@ -117,12 +117,7 @@ yaml_string_join( YAML_DECLARE(int) yaml_stack_extend(void **start, void **top, void **end) { - void *new_start; - - if ((char *)*end - (char *)*start >= INT_MAX / 2) - return 0; - - new_start = yaml_realloc(*start, ((char *)*end - (char *)*start)*2); + void *new_start = yaml_realloc(*start, ((char *)*end - (char *)*start)*2); if (!new_start) return 0; diff --git a/src/loader.c b/src/loader.c index 9d3d912..871149a 100644 --- a/src/loader.c +++ b/src/loader.c @@ -286,6 +286,8 @@ yaml_parser_load_scalar(yaml_parser_t *parser, yaml_event_t *first_event) int index; yaml_char_t *tag = first_event->data.scalar.tag; + if (!STACK_LIMIT(parser, parser->document->nodes, INT_MAX-1)) goto error; + if (!tag || strcmp((char *)tag, "!") == 0) { yaml_free(tag); tag = yaml_strdup((yaml_char_t *)YAML_DEFAULT_SCALAR_TAG); @@ -329,6 +331,8 @@ yaml_parser_load_sequence(yaml_parser_t *parser, yaml_event_t *first_event) int index, item_index; yaml_char_t *tag = first_event->data.sequence_start.tag; + if (!STACK_LIMIT(parser, parser->document->nodes, INT_MAX-1)) goto error; + if (!tag || strcmp((char *)tag, "!") == 0) { yaml_free(tag); tag = yaml_strdup((yaml_char_t *)YAML_DEFAULT_SEQUENCE_TAG); @@ -351,6 +355,9 @@ yaml_parser_load_sequence(yaml_parser_t *parser, yaml_event_t *first_event) if (!yaml_parser_parse(parser, &event)) return 0; while (event.type != YAML_SEQUENCE_END_EVENT) { + if (!STACK_LIMIT(parser, + parser->document->nodes.start[index-1].data.sequence.items, + INT_MAX-1)) return 0; item_index = yaml_parser_load_node(parser, &event); if (!item_index) return 0; if (!PUSH(parser, @@ -387,6 +394,8 @@ yaml_parser_load_mapping(yaml_parser_t *parser, yaml_event_t *first_event) yaml_node_pair_t pair; yaml_char_t *tag = first_event->data.mapping_start.tag; + if (!STACK_LIMIT(parser, parser->document->nodes, INT_MAX-1)) goto error; + if (!tag || strcmp((char *)tag, "!") == 0) { yaml_free(tag); tag = yaml_strdup((yaml_char_t *)YAML_DEFAULT_MAPPING_TAG); @@ -409,6 +418,9 @@ yaml_parser_load_mapping(yaml_parser_t *parser, yaml_event_t *first_event) if (!yaml_parser_parse(parser, &event)) return 0; while (event.type != YAML_MAPPING_END_EVENT) { + if (!STACK_LIMIT(parser, + parser->document->nodes.start[index-1].data.mapping.pairs, + INT_MAX-1)) return 0; pair.key = yaml_parser_load_node(parser, &event); if (!pair.key) return 0; if (!yaml_parser_parse(parser, &event)) return 0; diff --git a/src/reader.c b/src/reader.c index 829e32d..d47921c 100644 --- a/src/reader.c +++ b/src/reader.c @@ -460,6 +460,10 @@ yaml_parser_update_buffer(yaml_parser_t *parser, size_t length) } + if (parser->offset >= PTRDIFF_MAX) + return yaml_parser_set_reader_error(parser, "input is too long", + PTRDIFF_MAX, -1); + return 1; } diff --git a/src/scanner.c b/src/scanner.c index 71e8e3d..88d4fa5 100644 --- a/src/scanner.c +++ b/src/scanner.c @@ -615,14 +615,11 @@ yaml_parser_decrease_flow_level(yaml_parser_t *parser); */ static int -yaml_parser_roll_indent(yaml_parser_t *parser, size_t column, - int number, yaml_token_type_t type, yaml_mark_t mark); +yaml_parser_roll_indent(yaml_parser_t *parser, ptrdiff_t column, + ptrdiff_t number, yaml_token_type_t type, yaml_mark_t mark); static int -yaml_parser_unroll_indent(yaml_parser_t *parser, size_t column); - -static int -yaml_parser_reset_indent(yaml_parser_t *parser); +yaml_parser_unroll_indent(yaml_parser_t *parser, ptrdiff_t column); /* * Token fetchers. @@ -1106,7 +1103,7 @@ yaml_parser_save_simple_key(yaml_parser_t *parser) */ int required = (!parser->flow_level - && parser->indent == (int)parser->mark.column); + && parser->indent == (ptrdiff_t)parser->mark.column); /* * A simple key is required only when it is the first token in the current @@ -1179,6 +1176,11 @@ yaml_parser_increase_flow_level(yaml_parser_t *parser) /* Increase the flow level. */ + if (parser->flow_level == INT_MAX) { + parser->error = YAML_MEMORY_ERROR; + return 0; + } + parser->flow_level++; return 1; @@ -1209,8 +1211,8 @@ yaml_parser_decrease_flow_level(yaml_parser_t *parser) */ static int -yaml_parser_roll_indent(yaml_parser_t *parser, size_t column, - int number, yaml_token_type_t type, yaml_mark_t mark) +yaml_parser_roll_indent(yaml_parser_t *parser, ptrdiff_t column, + ptrdiff_t number, yaml_token_type_t type, yaml_mark_t mark) { yaml_token_t token; @@ -1219,7 +1221,7 @@ yaml_parser_roll_indent(yaml_parser_t *parser, size_t column, if (parser->flow_level) return 1; - if (parser->indent == -1 || parser->indent < column) + if (parser->indent < column) { /* * Push the current indentation level to the stack and set the new @@ -1229,6 +1231,11 @@ yaml_parser_roll_indent(yaml_parser_t *parser, size_t column, if (!PUSH(parser, parser->indents, parser->indent)) return 0; + if (column > INT_MAX) { + parser->error = YAML_MEMORY_ERROR; + return 0; + } + parser->indent = column; /* Create a token and insert it into the queue. */ @@ -1257,7 +1264,7 @@ yaml_parser_roll_indent(yaml_parser_t *parser, size_t column, static int -yaml_parser_unroll_indent(yaml_parser_t *parser, size_t column) +yaml_parser_unroll_indent(yaml_parser_t *parser, ptrdiff_t column) { yaml_token_t token; @@ -1266,15 +1273,6 @@ yaml_parser_unroll_indent(yaml_parser_t *parser, size_t column) if (parser->flow_level) return 1; - /* - * column is unsigned and parser->indent is signed, so if - * parser->indent is less than zero the conditional in the while - * loop below is incorrect. Guard against that. - */ - - if (parser->indent < 0) - return 1; - /* Loop through the intendation levels in the stack. */ while (parser->indent > column) @@ -1295,41 +1293,6 @@ yaml_parser_unroll_indent(yaml_parser_t *parser, size_t column) } /* - * Pop indentation levels from the indents stack until the current - * level resets to -1. For each intendation level, append the - * BLOCK-END token. - */ - -static int -yaml_parser_reset_indent(yaml_parser_t *parser) -{ - yaml_token_t token; - - /* In the flow context, do nothing. */ - - if (parser->flow_level) - return 1; - - /* Loop through the intendation levels in the stack. */ - - while (parser->indent > -1) - { - /* Create a token and append it to the queue. */ - - TOKEN_INIT(token, YAML_BLOCK_END_TOKEN, parser->mark, parser->mark); - - if (!ENQUEUE(parser, parser->tokens, token)) - return 0; - - /* Pop the indentation level. */ - - parser->indent = POP(parser, parser->indents); - } - - return 1; -} - -/* * Initialize the scanner and produce the STREAM-START token. */ @@ -1385,7 +1348,7 @@ yaml_parser_fetch_stream_end(yaml_parser_t *parser) /* Reset the indentation level. */ - if (!yaml_parser_reset_indent(parser)) + if (!yaml_parser_unroll_indent(parser, -1)) return 0; /* Reset simple keys. */ @@ -1416,7 +1379,7 @@ yaml_parser_fetch_directive(yaml_parser_t *parser) /* Reset the indentation level. */ - if (!yaml_parser_reset_indent(parser)) + if (!yaml_parser_unroll_indent(parser, -1)) return 0; /* Reset simple keys. */ @@ -1454,7 +1417,7 @@ yaml_parser_fetch_document_indicator(yaml_parser_t *parser, /* Reset the indentation level. */ - if (!yaml_parser_reset_indent(parser)) + if (!yaml_parser_unroll_indent(parser, -1)) return 0; /* Reset simple keys. */ @@ -2666,6 +2629,9 @@ yaml_parser_scan_tag_uri(yaml_parser_t *parser, int directive, /* Check if it is a URI-escape sequence. */ if (CHECK(parser->buffer, '%')) { + if (!STRING_EXTEND(parser, string)) + goto error; + if (!yaml_parser_scan_uri_escapes(parser, directive, start_mark, &string)) goto error; } diff --git a/src/yaml_private.h b/src/yaml_private.h index ed5ea66..f0e1001 100644 --- a/src/yaml_private.h +++ b/src/yaml_private.h @@ -7,6 +7,17 @@ #include <assert.h> #include <limits.h> +#include <stddef.h> + +#ifndef _MSC_VER +#include <stdint.h> +#else +#ifdef _WIN64 +#define PTRDIFF_MAX _I64_MAX +#else +#define PTRDIFF_MAX INT_MAX +#endif +#endif /* * Memory management. @@ -132,9 +143,12 @@ yaml_string_join( (string).start = (string).pointer = (string).end = 0) #define STRING_EXTEND(context,string) \ - (((string).pointer+5 < (string).end) \ + ((((string).pointer+5 < (string).end) \ || yaml_string_extend(&(string).start, \ - &(string).pointer, &(string).end)) + &(string).pointer, &(string).end)) ? \ + 1 : \ + ((context)->error = YAML_MEMORY_ERROR, \ + 0)) #define CLEAR(context,string) \ ((string).pointer = (string).start, \ @@ -421,6 +435,12 @@ yaml_queue_extend(void **start, void **head, void **tail, void **end); #define STACK_EMPTY(context,stack) \ ((stack).start == (stack).top) +#define STACK_LIMIT(context,stack,size) \ + ((stack).top - (stack).start < (size) ? \ + 1 : \ + ((context)->error = YAML_MEMORY_ERROR, \ + 0)) + #define PUSH(context,stack,value) \ (((stack).top != (stack).end \ || yaml_stack_extend((void **)&(stack).start, \ diff --git a/win32/config.h b/win32/config.h index 731b62d..2459f49 100644 --- a/win32/config.h +++ b/win32/config.h @@ -1,4 +1,4 @@ #define YAML_VERSION_MAJOR 0 #define YAML_VERSION_MINOR 1 -#define YAML_VERSION_PATCH 4 -#define YAML_VERSION_STRING "0.1.4" +#define YAML_VERSION_PATCH 6 +#define YAML_VERSION_STRING "0.1.6" |