|
| 1 | +From 0360b25ae53f9398cfca462f91698d1887a1ae76 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Pawel Winogrodzki <pawelwi@microsoft.com> |
| 3 | +Date: Mon, 1 Jul 2024 16:33:53 -0700 |
| 4 | +Subject: [PATCH] Port CVE-2022-3064 fix from go-yaml to zclconf. |
| 5 | + |
| 6 | +This patch is ported from go-yaml's fix for CVE-2022-3064: |
| 7 | +https://github.com/go-yaml/yaml/commit/f221b8435cfb71e54062f6c6e99e9ade30b124d5 |
| 8 | + |
| 9 | +The patch only applies to "scannerc.go", which seems to have been |
| 10 | +copied from go-yaml by zclconf. |
| 11 | +--- |
| 12 | + .../github.com/zclconf/go-cty-yaml/scannerc.go | 16 ++++++++++++++++ |
| 13 | + 1 file changed, 16 insertions(+) |
| 14 | + |
| 15 | +diff --git a/vendor/github.com/zclconf/go-cty-yaml/scannerc.go b/vendor/github.com/zclconf/go-cty-yaml/scannerc.go |
| 16 | +index ea82e3e..8eb8303 100644 |
| 17 | +--- a/vendor/github.com/zclconf/go-cty-yaml/scannerc.go |
| 18 | ++++ b/vendor/github.com/zclconf/go-cty-yaml/scannerc.go |
| 19 | +@@ -906,6 +906,9 @@ func yaml_parser_remove_simple_key(parser *yaml_parser_t) bool { |
| 20 | + return true |
| 21 | + } |
| 22 | + |
| 23 | ++// max_flow_level limits the flow_level |
| 24 | ++const max_flow_level = 10000 |
| 25 | ++ |
| 26 | + // Increase the flow level and resize the simple key list if needed. |
| 27 | + func yaml_parser_increase_flow_level(parser *yaml_parser_t) bool { |
| 28 | + // Reset the simple key on the next level. |
| 29 | +@@ -913,6 +916,11 @@ func yaml_parser_increase_flow_level(parser *yaml_parser_t) bool { |
| 30 | + |
| 31 | + // Increase the flow level. |
| 32 | + parser.flow_level++ |
| 33 | ++ if parser.flow_level > max_flow_level { |
| 34 | ++ return yaml_parser_set_scanner_error(parser, |
| 35 | ++ "while increasing flow level", parser.simple_keys[len(parser.simple_keys)-1].mark, |
| 36 | ++ fmt.Sprintf("exceeded max depth of %d", max_flow_level)) |
| 37 | ++ } |
| 38 | + return true |
| 39 | + } |
| 40 | + |
| 41 | +@@ -925,6 +933,9 @@ func yaml_parser_decrease_flow_level(parser *yaml_parser_t) bool { |
| 42 | + return true |
| 43 | + } |
| 44 | + |
| 45 | ++// max_indents limits the indents stack size |
| 46 | ++const max_indents = 10000 |
| 47 | ++ |
| 48 | + // Push the current indentation level to the stack and set the new level |
| 49 | + // the current column is greater than the indentation level. In this case, |
| 50 | + // append or insert the specified token into the token queue. |
| 51 | +@@ -939,6 +950,11 @@ func yaml_parser_roll_indent(parser *yaml_parser_t, column, number int, typ yaml |
| 52 | + // indentation level. |
| 53 | + parser.indents = append(parser.indents, parser.indent) |
| 54 | + parser.indent = column |
| 55 | ++ if len(parser.indents) > max_indents { |
| 56 | ++ return yaml_parser_set_scanner_error(parser, |
| 57 | ++ "while increasing indent level", parser.simple_keys[len(parser.simple_keys)-1].mark, |
| 58 | ++ fmt.Sprintf("exceeded max depth of %d", max_indents)) |
| 59 | ++ } |
| 60 | + |
| 61 | + // Create a token and insert it into the queue. |
| 62 | + token := yaml_token_t{ |
| 63 | +-- |
| 64 | +2.34.1 |
| 65 | + |
0 commit comments