secGear/0044-fix-pointer-without-init-or-check-NULL.patch
2022-04-29 14:20:55 +08:00

98 lines
4.7 KiB
Diff

From d550148b0c79e1d544d7edd0eef52750d6422e40 Mon Sep 17 00:00:00 2001
From: houmingyong<houmingyong@huawei.com>
Date: Sat, 8 Jan 2022 17:01:27 +0800
Subject: [PATCH] modify codex
Conflict:NA
Reference:https://gitee.com/openeuler/secGear/pulls/77
---
src/enclave_src/gp/itrustee/error_conversion.c | 14 +++++++-------
src/host_src/gp/gp_enclave.c | 2 +-
tools/codegener/Gentrust.ml | 14 ++++++++------
3 files changed, 16 insertions(+), 14 deletions(-)
diff --git a/src/enclave_src/gp/itrustee/error_conversion.c b/src/enclave_src/gp/itrustee/error_conversion.c
index 5177322..f30bc81 100644
--- a/src/enclave_src/gp/itrustee/error_conversion.c
+++ b/src/enclave_src/gp/itrustee/error_conversion.c
@@ -28,13 +28,13 @@ cc_enclave_result_t conversion_res_status(uint32_t enclave_res)
CC_ERROR_READ_DATA, CC_ERROR_WRITE_DATA, CC_ERROR_TRUNCATE_OBJECT, CC_ERROR_SEEK_DATA, CC_ERROR_SYNC_DATA,
CC_ERROR_RENAME_OBJECT, CC_ERROR_INVALID_ENCLAVE,
};
- const int res_table2_begin = 0x80000100U;
- const int res_table3_begin = 0x80001001U;
- const int res_table4_begin = 0xFFFF7000U;
- const int res_table5_begin = 0xFFFF7110U;
- const int res_table6_begin = 0xFFFF7118U;
- const int res_table7_begin = 0xFFFF9110U;
- const int shift = 7;
+ const uint32_t res_table2_begin = 0x80000100U;
+ const uint32_t res_table3_begin = 0x80001001U;
+ const uint32_t res_table4_begin = 0xFFFF7000U;
+ const uint32_t res_table5_begin = 0xFFFF7110U;
+ const uint32_t res_table6_begin = 0xFFFF7118U;
+ const uint32_t res_table7_begin = 0xFFFF9110U;
+ const uint32_t shift = 7;
if (enclave_res < res_table2_begin) {
if (enclave_res < sizeof(result_table1) / sizeof(cc_enclave_result_t)) {
diff --git a/src/host_src/gp/gp_enclave.c b/src/host_src/gp/gp_enclave.c
index c7554de..0bedb71 100644
--- a/src/host_src/gp/gp_enclave.c
+++ b/src/host_src/gp/gp_enclave.c
@@ -79,7 +79,7 @@ static cc_enclave_result_t ta_path_to_uuid(const char *path, TEEC_UUID *uuid)
const int clock_end = 7;
const int unit = 8;
const int uuid_base = 16;
- char uuid_str[UUID_LEN];
+ char uuid_str[UUID_LEN + 1] = {0};
uint64_t uuid_split[gp_token_nums];
const char *uuid_pos = NULL;
diff --git a/tools/codegener/Gentrust.ml b/tools/codegener/Gentrust.ml
index 18af7f2..b62624e 100644
--- a/tools/codegener/Gentrust.ml
+++ b/tools/codegener/Gentrust.ml
@@ -27,23 +27,23 @@ let set_parameters_point (fd : func_decl) =
let pre (_: parameter_type) = "" in
let post = "" in
let generator_in (_ : parameter_type) (_ : parameter_type) (decl : declarator) (mem_decl : declarator) =
- sprintf "uint8_t *%s_%s_p;\n " decl.identifier mem_decl.identifier in
+ sprintf "uint8_t *%s_%s_p = NULL;\n " decl.identifier mem_decl.identifier in
let generator_inout (_ : parameter_type) (_ : parameter_type) (decl : declarator) (mem_decl : declarator) =
- (sprintf "uint8_t *%s_%s_in_p;\n " decl.identifier mem_decl.identifier) ^ (sprintf "uint8_t *%s_%s_out_p;\n " decl.identifier mem_decl.identifier) in
+ (sprintf "uint8_t *%s_%s_in_p = NULL;\n " decl.identifier mem_decl.identifier) ^ (sprintf "uint8_t *%s_%s_out_p = NULL;\n " decl.identifier mem_decl.identifier) in
[
- (match fd.rtype with Void -> "" | _ -> "uint8_t *retval_p;");
+ (match fd.rtype with Void -> "" | _ -> "uint8_t *retval_p = NULL;");
concat "\n "
(List.map
(fun (_, decl) ->
- sprintf "uint8_t *%s_p;" decl.identifier)
+ sprintf "uint8_t *%s_p = NULL;" decl.identifier)
params);
concat "\n "
(List.map (deep_copy_func pre generator_in post) deep_copy_in);
concat "\n "
(List.map
(fun (_, decl) ->
- sprintf "uint8_t *%s_out_p;\n " decl.identifier ^
- sprintf "uint8_t *%s_in_p;" decl.identifier)
+ sprintf "uint8_t *%s_out_p = NULL;\n " decl.identifier ^
+ sprintf "uint8_t *%s_in_p = NULL;" decl.identifier)
params_inout);
concat "\n "
(List.map (deep_copy_func pre generator_inout post) deep_copy_inout);
@@ -156,6 +156,8 @@ let set_ecall_func (tf : trusted_func) =
else
" /* There is no parameters point */";
"";
+ " if (in_buf == NULL || out_buf == NULL)";
+ " goto done;";
sprintf " %s_size_t *args_size = (%s_size_t *)in_buf;" tfd.fname tfd.fname;
" in_buf_offset += size_to_aligned_size(sizeof(*args_size));";
"";
--
2.27.0