Whamcloud - gitweb
LU-17000 utils: Check return value of yaml_parser_initialize 31/53331/2
authorArshad Hussain <arshad.hussain@aeoncomputing.com>
Tue, 5 Dec 2023 08:54:42 +0000 (14:24 +0530)
committerOleg Drokin <green@whamcloud.com>
Wed, 20 Dec 2023 01:59:27 +0000 (01:59 +0000)
This patch adds return value checks to function
yaml_parser_initialize() and fopen() under lustre_cfg.c
And funciton cYAML_build_tree() under cyaml.c

Test-Parameters: trivial
CoverityID: 410239 ("Unchecked return value")
CoverityID: 410238 ("Unchecked return value")
Fixes: 65062463 (LU-14359 hsm: support a flatter HSM archive format)
Fixes: 8961f2d8 (LU-4939 utils: allow configuration through yaml files)
Change-Id: I67a34adee3e4d25f97244487684a613426637a70
Signed-off-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/53331
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Chris Horn <chris.horn@hpe.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lnet/utils/lnetconfig/cyaml.c
lustre/utils/lustre_cfg.c

index 5d153c5..6600337 100644 (file)
@@ -1400,12 +1400,13 @@ struct cYAML *cYAML_build_tree(char *path,
                               bool debug)
 {
        yaml_parser_t parser;
-       struct cYAML *yaml;
+       struct cYAML *yaml = NULL;
        char err_str[256];
        FILE *input = NULL;
 
        /* Create the Parser object. */
-       yaml_parser_initialize(&parser);
+       if (yaml_parser_initialize(&parser) == 0)
+               goto out_init;
 
        /* file always takes precedence */
        if (path != NULL) {
@@ -1437,6 +1438,6 @@ struct cYAML *cYAML_build_tree(char *path,
 
        if (input != NULL)
                fclose(input);
-
+out_init:
        return yaml;
 }
index 3a47aa0..ceec0a3 100644 (file)
@@ -1857,7 +1857,16 @@ int lcfg_apply_param_yaml(char *func, char *filename)
 
        convert = !strncmp(func, "set_param", 9);
        file = fopen(filename, "rb");
-       yaml_parser_initialize(&parser);
+       if (!file) {
+               rc1 = -errno;
+               goto out_open;
+       }
+
+       rc = yaml_parser_initialize(&parser);
+       if (rc == 0) {
+               rc1 = -EOPNOTSUPP;
+               goto out_init;
+       }
        yaml_parser_set_input_file(&parser, file);
 
        /*
@@ -1974,8 +1983,9 @@ int lcfg_apply_param_yaml(char *func, char *filename)
        }
 
        yaml_parser_delete(&parser);
+out_init:
        fclose(file);
-
+out_open:
        return rc1;
 }