mirror of
https://github.com/yaml/libyaml
synced 2026-06-08 18:28:36 +00:00
Guard against overflows in indent and flow_level.
This commit is contained in:
+13
-7
@@ -615,11 +615,11 @@ yaml_parser_decrease_flow_level(yaml_parser_t *parser);
|
||||
*/
|
||||
|
||||
static int
|
||||
yaml_parser_roll_indent(yaml_parser_t *parser, int 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, int column);
|
||||
yaml_parser_unroll_indent(yaml_parser_t *parser, ptrdiff_t column);
|
||||
|
||||
/*
|
||||
* Token fetchers.
|
||||
@@ -1103,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
|
||||
@@ -1176,6 +1176,9 @@ yaml_parser_increase_flow_level(yaml_parser_t *parser)
|
||||
|
||||
/* Increase the flow level. */
|
||||
|
||||
if (parser->flow_level == INT_MAX)
|
||||
return 0;
|
||||
|
||||
parser->flow_level++;
|
||||
|
||||
return 1;
|
||||
@@ -1206,8 +1209,8 @@ yaml_parser_decrease_flow_level(yaml_parser_t *parser)
|
||||
*/
|
||||
|
||||
static int
|
||||
yaml_parser_roll_indent(yaml_parser_t *parser, int 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;
|
||||
|
||||
@@ -1226,6 +1229,9 @@ yaml_parser_roll_indent(yaml_parser_t *parser, int column,
|
||||
if (!PUSH(parser, parser->indents, parser->indent))
|
||||
return 0;
|
||||
|
||||
if (column > INT_MAX)
|
||||
return 0;
|
||||
|
||||
parser->indent = column;
|
||||
|
||||
/* Create a token and insert it into the queue. */
|
||||
@@ -1254,7 +1260,7 @@ yaml_parser_roll_indent(yaml_parser_t *parser, int column,
|
||||
|
||||
|
||||
static int
|
||||
yaml_parser_unroll_indent(yaml_parser_t *parser, int column)
|
||||
yaml_parser_unroll_indent(yaml_parser_t *parser, ptrdiff_t column)
|
||||
{
|
||||
yaml_token_t token;
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include <assert.h>
|
||||
#include <limits.h>
|
||||
#include <stddef.h>
|
||||
|
||||
/*
|
||||
* Memory management.
|
||||
|
||||
Reference in New Issue
Block a user