!34 [sync] PR-31: tpm2-tools:fix build error
From: @openeuler-sync-bot Reviewed-by: @huangzq6 Signed-off-by: @huangzq6
This commit is contained in:
commit
585a776ea7
109
backport-clarify-return-values-from-string.patch
Normal file
109
backport-clarify-return-values-from-string.patch
Normal file
@ -0,0 +1,109 @@
|
||||
From d6e7e673a6179400b66339bb5f66b0da87006fb1 Mon Sep 17 00:00:00 2001
|
||||
From: Imran Desai <imran.desai@intel.com>
|
||||
Date: Tue, 21 Dec 2021 13:53:40 -0700
|
||||
Subject: [PATCH] lib/tpm2_options.c: clarify return values from string
|
||||
comparisons
|
||||
|
||||
See #2890
|
||||
|
||||
Signed-off-by: Imran Desai <imran.desai@intel.com>
|
||||
---
|
||||
lib/tpm2_options.c | 58 +++++++++++++++++++++++++++++-----------------
|
||||
1 file changed, 37 insertions(+), 21 deletions(-)
|
||||
|
||||
diff --git a/lib/tpm2_options.c b/lib/tpm2_options.c
|
||||
index 8c8af2af7..ab6660dc5 100644
|
||||
--- a/lib/tpm2_options.c
|
||||
+++ b/lib/tpm2_options.c
|
||||
@@ -119,8 +119,6 @@ void tpm2_options_free(tpm2_options *opts) {
|
||||
static bool execute_man(char *prog_name, bool show_errors) {
|
||||
|
||||
pid_t pid;
|
||||
- int status;
|
||||
-
|
||||
if ((pid = fork()) < 0) {
|
||||
LOG_ERR("Could not fork process to execute man, error: %s",
|
||||
strerror(errno));
|
||||
@@ -129,7 +127,6 @@ static bool execute_man(char *prog_name, bool show_errors) {
|
||||
|
||||
#define MAX_TOOL_NAME_LEN 64
|
||||
if (pid == 0) {
|
||||
-
|
||||
if (!show_errors) {
|
||||
/* redirect manpager errors to stderr */
|
||||
int fd = open("/dev/null", O_WRONLY);
|
||||
@@ -141,29 +138,45 @@ static bool execute_man(char *prog_name, bool show_errors) {
|
||||
close(fd);
|
||||
}
|
||||
|
||||
+ /*
|
||||
+ * Handle the case where tpm2 is specified without tool-name or help
|
||||
+ */
|
||||
const char *manpage = basename(prog_name);
|
||||
- if (!strcmp(manpage, "tpm2")) {
|
||||
- /*
|
||||
- * Handle the case where tpm2 is specified without tool-name or help
|
||||
- */
|
||||
+ bool is_only_tpm2 = (strcmp(manpage, "tpm2") == 0);
|
||||
+ if (is_only_tpm2) {
|
||||
execlp("man", "man", "tpm2", NULL);
|
||||
- } else if (strncmp(manpage, "tpm2_", strlen("tpm2_"))) {
|
||||
- /*
|
||||
- * Handle the case where the tool is specified as tpm2< >tool-name
|
||||
- */
|
||||
- char man_tool_name[MAX_TOOL_NAME_LEN] = {'t','p','m','2','_'};
|
||||
- strncat(man_tool_name, manpage,
|
||||
+ }
|
||||
+
|
||||
+ /*
|
||||
+ * Handle the case where the tool is specified as tpm2< >tool-name
|
||||
+ */
|
||||
+ bool is_tpm2_space_toolname =
|
||||
+ (strncmp(manpage, "tpm2_", strlen("tpm2_")) != 0);
|
||||
+ if (is_tpm2_space_toolname) {
|
||||
+ uint8_t toolname_len =
|
||||
strlen(manpage) < (MAX_TOOL_NAME_LEN - strlen("tpm2_")) ?
|
||||
- strlen(manpage) : (MAX_TOOL_NAME_LEN - strlen("tpm2_")));
|
||||
+ strlen(manpage) : MAX_TOOL_NAME_LEN - strlen("tpm2_");
|
||||
+
|
||||
+ char man_tool_name[MAX_TOOL_NAME_LEN] = {'t','p','m','2','_'};
|
||||
+
|
||||
+ strncat(man_tool_name, manpage, toolname_len);
|
||||
execlp("man", "man", man_tool_name, NULL);
|
||||
- } else {
|
||||
- /*
|
||||
- * Handle the case where the tool is specified as tpm2<_>tool-name
|
||||
- */
|
||||
+ }
|
||||
+
|
||||
+ /*
|
||||
+ * Handle the case where the tool is specified as tpm2<_>tool-name
|
||||
+ */
|
||||
+ bool is_tpm2_underscore_toolname =
|
||||
+ (!is_only_tpm2 && !is_tpm2_space_toolname);
|
||||
+ if (is_tpm2_underscore_toolname) {
|
||||
execlp("man", "man", manpage, NULL);
|
||||
}
|
||||
- } else {
|
||||
- if (waitpid(pid, &status, 0) == -1) {
|
||||
+ }
|
||||
+
|
||||
+ if (pid != 0) {
|
||||
+ int status;
|
||||
+ bool is_child_process_incomplete = (waitpid(pid, &status, 0) == -1);
|
||||
+ if (is_child_process_incomplete) {
|
||||
LOG_ERR("Waiting for child process that executes man failed, error:"
|
||||
" %s", strerror(errno));
|
||||
return false;
|
||||
@@ -524,7 +537,10 @@ tpm2_option_code tpm2_handle_options(int argc, char **argv,
|
||||
if (!did_manpager) {
|
||||
tpm2_print_usage(argv[0], tool_opts);
|
||||
}
|
||||
- if (tcti_conf_option && strcmp(tcti_conf_option, "none")) {
|
||||
+
|
||||
+ bool is_tcti_not_none = tcti_conf_option ?
|
||||
+ (strcmp(tcti_conf_option, "none") != 0) : false;
|
||||
+ if (is_tcti_not_none) {
|
||||
TSS2_TCTI_INFO *info = NULL;
|
||||
rc_tcti = Tss2_TctiLdr_GetInfo(tcti_conf_option, &info);
|
||||
if (rc_tcti == TSS2_RC_SUCCESS && info) {
|
||||
@ -1,6 +1,6 @@
|
||||
Name: tpm2-tools
|
||||
Version: 5.0
|
||||
Release: 4
|
||||
Release: 5
|
||||
Summary: A TPM2.0 testing tool based on TPM2.0-TSS
|
||||
License: BSD
|
||||
URL: https://github.com/tpm2-software/tpm2-tools
|
||||
@ -8,6 +8,7 @@ Source0: https://github.com/tpm2-software/tpm2-tools/releases/download/%{v
|
||||
|
||||
Patch0: backport-Don-t-assume-end-of-argv-is-NULL.patch
|
||||
Patch1: backport-CVE-2021-3565.patch
|
||||
Patch2: backport-clarify-return-values-from-string.patch
|
||||
|
||||
BuildRequires: gcc-c++ libtool autoconf-archive pkgconfig(cmocka) pkgconfig(libcurl) pkgconfig(openssl)
|
||||
BuildRequires: pkgconfig(tss2-mu) pkgconfig(tss2-sys) pkgconfig(tss2-esys) pkgconfig(uuid) git libgcrypt
|
||||
@ -59,6 +60,9 @@ make check
|
||||
%{_mandir}/*/*
|
||||
|
||||
%changelog
|
||||
* Fri Dec 16 2022 jinlun <jinlun@huawei.com> - 5.0-5
|
||||
- fix build error
|
||||
|
||||
* Mon Sep 27 2021 fuanan <fuanan3@huawei.com> - 5.0-4
|
||||
- fix CVE-2021-3565
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user