From 71a185179bf65193b23862e7686b023cd9ad9dce Mon Sep 17 00:00:00 2001 From: gaohuatao Date: Thu, 19 Mar 2020 07:54:06 -0400 Subject: [PATCH] fix shim static check Signed-off-by: gaohuatao (cherry picked from commit 546e9b771d35168d0255f8781dc08aa678fa2c1c) Signed-off-by: gaohuatao --- src/cmd/isulad-shim/terminal.c | 7 ++++++- src/cmd/isulad-shim/terminal.h | 4 ---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/cmd/isulad-shim/terminal.c b/src/cmd/isulad-shim/terminal.c index 5b094e3..5850e66 100644 --- a/src/cmd/isulad-shim/terminal.c +++ b/src/cmd/isulad-shim/terminal.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include "terminal.h" #include "common.h" @@ -69,9 +70,13 @@ static int shim_rename_old_log_file(log_terminal *terminal) static int shim_dump_log_file(log_terminal *terminal) { int ret; - char *file_newname; + char *file_newname = NULL; size_t len_path = strlen(terminal->log_path) + sizeof(".1"); + if (len_path > PATH_MAX) { + return SHIM_ERR; + } + /* isulad: rotate old log file first */ ret = shim_rename_old_log_file(terminal); if (ret != 0) { diff --git a/src/cmd/isulad-shim/terminal.h b/src/cmd/isulad-shim/terminal.h index c66992a..2f2ed4e 100644 --- a/src/cmd/isulad-shim/terminal.h +++ b/src/cmd/isulad-shim/terminal.h @@ -24,10 +24,6 @@ extern "C" { #endif -#ifndef PATH_MAX -#define PATH_MAX 4096 -#endif - typedef struct { uint64_t log_maxsize; char *log_path;