From edccd46eba01748a5f57b32f5917f730985585b2 Mon Sep 17 00:00:00 2001 From: Arshad Hussain Date: Tue, 5 Dec 2023 14:24:42 +0530 Subject: [PATCH] LU-17000 utils: Check return value of yaml_parser_initialize 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 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/53331 Tested-by: jenkins Tested-by: Maloo Reviewed-by: James Simmons Reviewed-by: Andreas Dilger Reviewed-by: Chris Horn Reviewed-by: Oleg Drokin --- lnet/utils/lnetconfig/cyaml.c | 7 ++++--- lustre/utils/lustre_cfg.c | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lnet/utils/lnetconfig/cyaml.c b/lnet/utils/lnetconfig/cyaml.c index 5d153c5..6600337 100644 --- a/lnet/utils/lnetconfig/cyaml.c +++ b/lnet/utils/lnetconfig/cyaml.c @@ -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; } diff --git a/lustre/utils/lustre_cfg.c b/lustre/utils/lustre_cfg.c index 3a47aa0..ceec0a3 100644 --- a/lustre/utils/lustre_cfg.c +++ b/lustre/utils/lustre_cfg.c @@ -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; } -- 1.8.3.1