[Ocfs2-tools-devel] [PATCH 6/6] o2info: Check the validity of variables before use
piaojun
piaojun at huawei.com
Thu Mar 26 00:00:02 PDT 2015
1. In main(), we need check if device_or_file is null before use.
2. In o2info_print_line(), we need check if tmp is null before use.
3. In fs_features_run(), we need check if features is null before use.
4. In volinfo_run(), we need check if features is null before use.
5. In o2info_gen_mkfs_string(), we need check if features is null before
use.
Signed-off-by: Jun Piao <piaojun at huawei.com>
Reviewed-by: Alex Chen <alex.chen at huawei.com>
---
o2info/o2info.c | 3 ++-
o2info/operations.c | 17 ++++++++++++++---
2 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/o2info/o2info.c b/o2info/o2info.c
index e64564a..cb68154 100644
--- a/o2info/o2info.c
+++ b/o2info/o2info.c
@@ -582,7 +582,8 @@ int main(int argc, char *argv[])
o2info_init(argv[0]);
parse_options(argc, argv, &device_or_file);
-
+ if (!device_or_file)
+ return -EINVAL;
rc = o2info_method(device_or_file);
if (rc < 0)
goto out;
diff --git a/o2info/operations.c b/o2info/operations.c
index 5c393b4..b416d62 100644
--- a/o2info/operations.c
+++ b/o2info/operations.c
@@ -165,6 +165,8 @@ static void o2info_print_line(char const *qualifier, char *content,
uint32_t max_len = 80, len = 0;
tmp = malloc(max_len);
+ if (!tmp)
+ return;
ptr = content;
snprintf(tmp, max_len, "%s", qualifier);
@@ -240,7 +242,10 @@ static int fs_features_run(struct o2info_operation *op,
features = malloc(strlen(compat) + strlen(incompat) +
strlen(rocompat) + 3);
-
+ if (!features) {
+ rc = -ENOMEM;
+ goto out;
+ }
sprintf(features, "%s %s %s", compat, incompat, rocompat);
o2info_print_line("", features, ' ');
@@ -372,7 +377,10 @@ static int volinfo_run(struct o2info_operation *op,
features = malloc(strlen(compat) + strlen(incompat) +
strlen(rocompat) + 3);
-
+ if (!features) {
+ rc = -ENOMEM;
+ goto out;
+ }
sprintf(features, "%s %s %s", compat, incompat, rocompat);
fprintf(stdout, VOLINFO, vf.label, vf.uuid_str, vf.blocksize,
@@ -472,7 +480,10 @@ static int o2info_gen_mkfs_string(struct o2info_mkfs oms, char **mkfs)
features = malloc(strlen(compat) + strlen(incompat) +
strlen(rocompat) + 3);
-
+ if (!features) {
+ rc = -ENOMEM;
+ goto out;
+ }
sprintf(features, "%s %s %s", compat, incompat, rocompat);
ptr = features;
-- 1.8.4.3
More information about the Ocfs2-tools-devel
mailing list