Blob Blame History Raw
# HG changeset patch
# User Kirill Simonov <xi@resolvent.net>
# Date 1391406104 21600
#      Sun Feb 02 23:41:44 2014 -0600
# Node ID f859ed1eb757a3562b98a28a8ce69274bfd4b3f2
# Parent  da9bc6f12781a583076c7b60d057df5d7b50f96f
Guard against overflows in indent and flow_level.

diff -r da9bc6f12781 -r f859ed1eb757 src/scanner.c
--- a/src/scanner.c	Sun Feb 02 20:54:05 2014 -0600
+++ b/src/scanner.c	Sun Feb 02 23:41:44 2014 -0600
@@ -615,11 +615,11 @@
  */
 
 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 @@
      */
 
     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 @@
 
     /* Increase the flow level. */
 
+    if (parser->flow_level == INT_MAX)
+        return 0;
+
     parser->flow_level++;
 
     return 1;
@@ -1206,8 +1209,8 @@
  */
 
 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 @@
         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 @@
 
 
 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;
 
diff -r da9bc6f12781 -r f859ed1eb757 src/yaml_private.h
--- a/src/yaml_private.h	Sun Feb 02 20:54:05 2014 -0600
+++ b/src/yaml_private.h	Sun Feb 02 23:41:44 2014 -0600
@@ -7,6 +7,7 @@
 
 #include <assert.h>
 #include <limits.h>
+#include <stddef.h>
 
 /*
  * Memory management.