Whamcloud - gitweb
LU-12513 utils: add handling YAML_NO_TOKEN 28/35428/5
authorBen Evans <bevans@cray.com>
Sat, 6 Jul 2019 23:23:42 +0000 (19:23 -0400)
committerOleg Drokin <green@whamcloud.com>
Wed, 17 Jul 2019 06:21:57 +0000 (06:21 +0000)
YAML_NO_TOKEN is something that is not a key value pair, either
an entry or exit into a sub-structure. The parser equates it to
an error. This flaw makes a YAML format that is valid be treated
as invalid. Add handling YAML_NO_TOKEN as a valid setting. This
flaw was discovered in the patch for the LU-6081 work.

Test-Parameters: trivial

Change-Id: Ibe0c0a2bea22b26a0dd2d900b7a4a5957b96e3da
Signed-off-by: Ben Evans <bevans@cray.com>
Reviewed-on: https://review.whamcloud.com/35428
Tested-by: jenkins <devops@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lnet/utils/lnetconfig/cyaml.c

index ae5205f..0dcae12 100644 (file)
@@ -107,7 +107,7 @@ struct cYAML_tree_node {
 typedef enum cYAML_handler_error (*yaml_token_handler)(yaml_token_t *token,
                                                struct cYAML_tree_node *);
 
-static enum cYAML_handler_error yaml_parse_error(yaml_token_t *token,
+static enum cYAML_handler_error yaml_no_token(yaml_token_t *token,
                                        struct cYAML_tree_node *tree);
 static enum cYAML_handler_error yaml_stream_start(yaml_token_t *token,
                                        struct cYAML_tree_node *tree);
@@ -136,7 +136,7 @@ static enum cYAML_handler_error yaml_entry_token(yaml_token_t *token,
 
 /* dispatch table */
 static yaml_token_handler dispatch_tbl[] = {
-       [YAML_NO_TOKEN] = yaml_parse_error,
+       [YAML_NO_TOKEN] = yaml_no_token,
        [YAML_STREAM_START_TOKEN] = yaml_stream_start,
        [YAML_STREAM_END_TOKEN] = yaml_stream_end,
        [YAML_VERSION_DIRECTIVE_TOKEN] = yaml_not_supported,
@@ -460,10 +460,11 @@ static int assign_type_value(struct cYAML *obj, const char *value)
  * else state = VALUE
  *
  */
-static enum cYAML_handler_error yaml_parse_error(yaml_token_t *token,
-                                                struct cYAML_tree_node *tree)
+
+static enum cYAML_handler_error yaml_no_token(yaml_token_t *token,
+                                             struct cYAML_tree_node *tree)
 {
-       return CYAML_ERROR_PARSE;
+       return CYAML_ERROR_NONE;
 }
 
 static enum cYAML_handler_error yaml_stream_start(yaml_token_t *token,
@@ -545,7 +546,8 @@ static enum cYAML_handler_error yaml_scalar(yaml_token_t *token,
                  strdup((const char *)token->data.scalar.value);
 
                tree->state = TREE_STATE_KEY_FILLED;
-       } else if (tree->state == TREE_STATE_VALUE) {
+       } else if (tree->state == TREE_STATE_VALUE ||
+                  tree->state == TREE_STATE_SEQ_START) {
                if (assign_type_value(tree->cur,
                                      (char *)token->data.scalar.value))
                        /* failed to assign a value */
@@ -1205,17 +1207,17 @@ struct cYAML *cYAML_build_tree(char *yaml_file,
                rc = dispatch_tbl[token.type](&token, &tree);
                if (rc != CYAML_ERROR_NONE) {
                        snprintf(err_str, sizeof(err_str),
-                               "Failed to handle token:%d "
+                               "Failed to handle token:%d %s"
                                "[state=%d, rc=%d]",
-                               token.type, tree.state, rc);
+                                token.type, token_type_string[token.type],
+                                tree.state, rc);
                        cYAML_build_error(-1, -1, "yaml", "builder",
                                          err_str,
                                          err_rc);
                }
                /* Are we finished? */
                done = (rc != CYAML_ERROR_NONE ||
-                       token.type == YAML_STREAM_END_TOKEN ||
-                       token.type == YAML_NO_TOKEN);
+                       token.type == YAML_STREAM_END_TOKEN);
 
                token_type = token.type;