on master help sign in
Update libyaml to 0.1.5
commit26c86baa5894d92488d1cb27e5e86fdddcf9e216 authorMichael Snoyman <michael@snoyman.com> dateThu 13 Feb 2014, 09:40 (13 years ago) parent932a36a
5 files changed+54−11
libyaml/loader.c+12 libyaml/reader.c+4 libyaml/scanner.c+18−8 libyaml/yaml_private.h+19−2 yaml.cabal+1−1
libyaml/loader.c+12
@@ -286,6 +286,8 @@ yaml_parser_load_scalar(yaml_parser_t *parser, yaml_event_t *first_event)
286286 int index;
287287 yaml_char_t *tag = first_event->data.scalar.tag;
288288
289+ if (!STACK_LIMIT(parser, parser->document->nodes, INT_MAX-1)) goto error;
290+
289291 if (!tag || strcmp((char *)tag, "!") == 0) {
290292 yaml_free(tag);
291293 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)
329331 int index, item_index;
330332 yaml_char_t *tag = first_event->data.sequence_start.tag;
331333
334+ if (!STACK_LIMIT(parser, parser->document->nodes, INT_MAX-1)) goto error;
335+
332336 if (!tag || strcmp((char *)tag, "!") == 0) {
333337 yaml_free(tag);
334338 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)
351355 if (!yaml_parser_parse(parser, &event)) return 0;
352356
353357 while (event.type != YAML_SEQUENCE_END_EVENT) {
358+ if (!STACK_LIMIT(parser,
359+ parser->document->nodes.start[index-1].data.sequence.items,
360+ INT_MAX-1)) return 0;
354361 item_index = yaml_parser_load_node(parser, &event);
355362 if (!item_index) return 0;
356363 if (!PUSH(parser,
@@ -387,6 +394,8 @@ yaml_parser_load_mapping(yaml_parser_t *parser, yaml_event_t *first_event)
387394 yaml_node_pair_t pair;
388395 yaml_char_t *tag = first_event->data.mapping_start.tag;
389396
397+ if (!STACK_LIMIT(parser, parser->document->nodes, INT_MAX-1)) goto error;
398+
390399 if (!tag || strcmp((char *)tag, "!") == 0) {
391400 yaml_free(tag);
392401 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)
409418 if (!yaml_parser_parse(parser, &event)) return 0;
410419
411420 while (event.type != YAML_MAPPING_END_EVENT) {
421+ if (!STACK_LIMIT(parser,
422+ parser->document->nodes.start[index-1].data.mapping.pairs,
423+ INT_MAX-1)) return 0;
412424 pair.key = yaml_parser_load_node(parser, &event);
413425 if (!pair.key) return 0;
414426 if (!yaml_parser_parse(parser, &event)) return 0;
libyaml/reader.c+4
@@ -460,6 +460,10 @@ yaml_parser_update_buffer(yaml_parser_t *parser, size_t length)
460460
461461 }
462462
463+ if (parser->offset >= PTRDIFF_MAX)
464+ return yaml_parser_set_reader_error(parser, "input is too long",
465+ PTRDIFF_MAX, -1);
466+
463467 return 1;
464468}
465469
libyaml/scanner.c+18−8
@@ -615,11 +615,11 @@ yaml_parser_decrease_flow_level(yaml_parser_t *parser);
615615 */
616616
617617static int
618−yaml_parser_roll_indent(yaml_parser_t *parser, int column,
619− int number, yaml_token_type_t type, yaml_mark_t mark);
618+yaml_parser_roll_indent(yaml_parser_t *parser, ptrdiff_t column,
619+ ptrdiff_t number, yaml_token_type_t type, yaml_mark_t mark);
620620
621621static int
622−yaml_parser_unroll_indent(yaml_parser_t *parser, int column);
622+yaml_parser_unroll_indent(yaml_parser_t *parser, ptrdiff_t column);
623623
624624/*
625625 * Token fetchers.
@@ -1103,7 +1103,7 @@ yaml_parser_save_simple_key(yaml_parser_t *parser)
11031103 */
11041104
11051105 int required = (!parser->flow_level
1106− && parser->indent == (int)parser->mark.column);
1106+ && parser->indent == (ptrdiff_t)parser->mark.column);
11071107
11081108 /*
11091109 * A simple key is required only when it is the first token in the current
@@ -1176,6 +1176,11 @@ yaml_parser_increase_flow_level(yaml_parser_t *parser)
11761176
11771177 /* Increase the flow level. */
11781178
1179+ if (parser->flow_level == INT_MAX) {
1180+ parser->error = YAML_MEMORY_ERROR;
1181+ return 0;
1182+ }
1183+
11791184 parser->flow_level++;
11801185
11811186 return 1;
@@ -1206,8 +1211,8 @@ yaml_parser_decrease_flow_level(yaml_parser_t *parser)
12061211 */
12071212
12081213static int
1209−yaml_parser_roll_indent(yaml_parser_t *parser, int column,
1210− int number, yaml_token_type_t type, yaml_mark_t mark)
1214+yaml_parser_roll_indent(yaml_parser_t *parser, ptrdiff_t column,
1215+ ptrdiff_t number, yaml_token_type_t type, yaml_mark_t mark)
12111216{
12121217 yaml_token_t token;
12131218
@@ -1226,6 +1231,11 @@ yaml_parser_roll_indent(yaml_parser_t *parser, int column,
12261231 if (!PUSH(parser, parser->indents, parser->indent))
12271232 return 0;
12281233
1234+ if (column > INT_MAX) {
1235+ parser->error = YAML_MEMORY_ERROR;
1236+ return 0;
1237+ }
1238+
12291239 parser->indent = column;
12301240
12311241 /* Create a token and insert it into the queue. */
@@ -1254,7 +1264,7 @@ yaml_parser_roll_indent(yaml_parser_t *parser, int column,
12541264
12551265
12561266static int
1257−yaml_parser_unroll_indent(yaml_parser_t *parser, int column)
1267+yaml_parser_unroll_indent(yaml_parser_t *parser, ptrdiff_t column)
12581268{
12591269 yaml_token_t token;
12601270
@@ -2574,7 +2584,7 @@ yaml_parser_scan_tag_uri(yaml_parser_t *parser, int directive,
25742584
25752585 /* Resize the string to include the head. */
25762586
2577− while (string.end - string.start <= (int)length) {
2587+ while ((size_t)(string.end - string.start) <= length) {
25782588 if (!yaml_string_extend(&string.start, &string.pointer, &string.end)) {
25792589 parser->error = YAML_MEMORY_ERROR;
25802590 goto error;
libyaml/yaml_private.h+19−2
@@ -7,6 +7,17 @@
77
88#include <assert.h>
99#include <limits.h>
10+#include <stddef.h>
11+
12+#ifndef _MSC_VER
13+#include <stdint.h>
14+#else
15+#ifdef _WIN64
16+#define PTRDIFF_MAX _I64_MAX
17+#else
18+#define PTRDIFF_MAX INT_MAX
19+#endif
20+#endif
1021
1122/*
1223 * Memory management.
@@ -421,6 +432,12 @@ yaml_queue_extend(void **start, void **head, void **tail, void **end);
421432#define STACK_EMPTY(context,stack) \
422433 ((stack).start == (stack).top)
423434
435+#define STACK_LIMIT(context,stack,size) \
436+ ((stack).top - (stack).start < (size) ? \
437+ 1 : \
438+ ((context)->error = YAML_MEMORY_ERROR, \
439+ 0))
440+
424441#define PUSH(context,stack,value) \
425442 (((stack).top != (stack).end \
426443 || yaml_stack_extend((void **)&(stack).start, \
@@ -638,7 +655,7 @@ yaml_queue_extend(void **start, void **head, void **tail, void **end);
638655 (node).data.mapping.pairs.top = (node_pairs_start), \
639656 (node).data.mapping.style = (node_style))
640657
641−#define YAML_VERSION_STRING "0.1.4"
658+#define YAML_VERSION_STRING "0.1.5"
642659#define YAML_VERSION_MAJOR 0
643660#define YAML_VERSION_MINOR 1
644−#define YAML_VERSION_PATCH 4
661+#define YAML_VERSION_PATCH 5
yaml.cabal+1−1
@@ -1,5 +1,5 @@
11name: yaml
2−version: 0.8.7.1
2+version: 0.8.7.2
33license: BSD3
44license-file: LICENSE
55author: Michael Snoyman <michael@snoyman.com>, Anton Ageev <antage@gmail.com>,Kirill Simonov