The max length of the file path defined by user should be PATH_MAX.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- wd_aead.c | 3 ++- wd_cipher.c | 3 ++- wd_comp.c | 2 +- wd_dh.c | 2 +- wd_digest.c | 3 ++- wd_ecc.c | 2 +- wd_rsa.c | 2 +- wd_util.c | 20 ++++++++++---------- 8 files changed, 20 insertions(+), 17 deletions(-)
diff --git a/wd_aead.c b/wd_aead.c index 0967dda..85acf5d 100644 --- a/wd_aead.c +++ b/wd_aead.c @@ -6,6 +6,7 @@
#include <stdlib.h> #include <pthread.h> +#include <limits.h> #include "include/drv/wd_aead_drv.h" #include "wd_aead.h"
@@ -85,7 +86,7 @@ static int wd_aead_open_driver(void) { struct wd_alg_driver *driver = NULL; const char *alg_name = "gcm(aes)"; - char lib_path[PATH_STR_SIZE]; + char lib_path[PATH_MAX]; int ret;
/* diff --git a/wd_cipher.c b/wd_cipher.c index 1344119..a8fbecb 100644 --- a/wd_cipher.c +++ b/wd_cipher.c @@ -7,6 +7,7 @@ #include <stdlib.h> #include <pthread.h> #include <sched.h> +#include <limits.h> #include "include/drv/wd_cipher_drv.h" #include "wd_cipher.h"
@@ -91,7 +92,7 @@ static int wd_cipher_open_driver(void) { struct wd_alg_driver *driver = NULL; const char *alg_name = "cbc(aes)"; - char lib_path[PATH_STR_SIZE]; + char lib_path[PATH_MAX]; int ret;
/* diff --git a/wd_comp.c b/wd_comp.c index f48938a..6be6b72 100644 --- a/wd_comp.c +++ b/wd_comp.c @@ -64,7 +64,7 @@ static void wd_comp_close_driver(void) static int wd_comp_open_driver(void) { struct wd_alg_driver *driver = NULL; - char lib_path[PATH_STR_SIZE]; + char lib_path[PATH_MAX]; const char *alg_name = "zlib"; int ret;
diff --git a/wd_dh.c b/wd_dh.c index 6aebb8c..203d3e0 100644 --- a/wd_dh.c +++ b/wd_dh.c @@ -56,7 +56,7 @@ static void wd_dh_close_driver(void) static int wd_dh_open_driver(void) { struct wd_alg_driver *driver = NULL; - char lib_path[PATH_STR_SIZE]; + char lib_path[PATH_MAX]; const char *alg_name = "dh"; int ret;
diff --git a/wd_digest.c b/wd_digest.c index 11cdc9b..73f44e5 100644 --- a/wd_digest.c +++ b/wd_digest.c @@ -6,6 +6,7 @@
#include <stdlib.h> #include <pthread.h> +#include <limits.h> #include "include/drv/wd_digest_drv.h" #include "wd_digest.h"
@@ -88,7 +89,7 @@ static int wd_digest_open_driver(void) { struct wd_alg_driver *driver = NULL; const char *alg_name = "sm3"; - char lib_path[PATH_STR_SIZE]; + char lib_path[PATH_MAX]; int ret;
/* diff --git a/wd_ecc.c b/wd_ecc.c index ea54a8f..695c61d 100644 --- a/wd_ecc.c +++ b/wd_ecc.c @@ -112,7 +112,7 @@ static void wd_ecc_close_driver(void) static int wd_ecc_open_driver(void) { struct wd_alg_driver *driver = NULL; - char lib_path[PATH_STR_SIZE]; + char lib_path[PATH_MAX]; const char *alg_name = "sm2"; int ret;
diff --git a/wd_rsa.c b/wd_rsa.c index fff6067..58b1229 100644 --- a/wd_rsa.c +++ b/wd_rsa.c @@ -97,7 +97,7 @@ static void wd_rsa_close_driver(void) static int wd_rsa_open_driver(void) { struct wd_alg_driver *driver = NULL; - char lib_path[PATH_STR_SIZE]; + char lib_path[PATH_MAX]; const char *alg_name = "rsa"; int ret;
diff --git a/wd_util.c b/wd_util.c index 9a591d5..053a654 100644 --- a/wd_util.c +++ b/wd_util.c @@ -2156,7 +2156,7 @@ int wd_ctx_param_init(struct wd_ctx_params *ctx_params, static void dladdr_empty(void) {} int wd_get_lib_file_path(char *lib_file, char *lib_path, bool is_dir) { - char file_path[PATH_STR_SIZE] = {0}; + char file_path[PATH_MAX] = {0}; char path[PATH_MAX]; Dl_info file_info; int len, rc, i; @@ -2167,23 +2167,23 @@ int wd_get_lib_file_path(char *lib_file, char *lib_path, bool is_dir) WD_ERR("fail to get lib file path.\n"); return -WD_EINVAL; } - strncpy(file_path, file_info.dli_fname, PATH_STR_SIZE - 1); + strncpy(file_path, file_info.dli_fname, PATH_MAX - 1);
/* Clear the file path's tail file name */ len = strlen(file_path) - 1; for (i = len; i >= 0; i--) { if (file_path[i] == '/') { - memset(&file_path[i], 0, PATH_STR_SIZE - i + 1); + memset(&file_path[i], 0, PATH_MAX - i + 1); break; } }
if (is_dir) { - (void)snprintf(lib_path, PATH_STR_SIZE, "%s", file_path); + (void)snprintf(lib_path, PATH_MAX, "%s", file_path); return 0; }
- len = snprintf(lib_path, PATH_STR_SIZE, "%s/%s", file_path, lib_file); + len = snprintf(lib_path, PATH_MAX, "%s/%s", file_path, lib_file); if (len < 0) return -WD_EINVAL;
@@ -2199,8 +2199,8 @@ void *wd_dlopen_drv(const char *cust_lib_dir) { typedef int (*alg_ops)(struct wd_alg_driver *drv); struct drv_lib_list *node, *head = NULL; - char lib_dir_path[PATH_STR_SIZE] = {0}; - char lib_path[PATH_STR_SIZE] = {0}; + char lib_dir_path[PATH_MAX] = {0}; + char lib_path[PATH_MAX] = {0}; struct dirent *lib_dir; alg_ops dl_func = NULL; DIR *wd_dir; @@ -2211,12 +2211,12 @@ void *wd_dlopen_drv(const char *cust_lib_dir) if (ret) return NULL; } else { - (void)snprintf(lib_path, PATH_STR_SIZE, "%s/%s", cust_lib_dir, DEF_DRV_LIB_FILE); + (void)snprintf(lib_path, PATH_MAX, "%s/%s", cust_lib_dir, DEF_DRV_LIB_FILE); ret = access(lib_path, F_OK); if (ret) return NULL;
- strncpy(lib_dir_path, cust_lib_dir, PATH_STR_SIZE - 1); + strncpy(lib_dir_path, cust_lib_dir, PATH_MAX - 1); }
wd_dir = opendir(lib_dir_path); @@ -2238,7 +2238,7 @@ void *wd_dlopen_drv(const char *cust_lib_dir) if (!node) goto free_list;
- ret = snprintf(lib_path, PATH_STR_SIZE, "%s/%s", lib_dir_path, lib_dir->d_name); + ret = snprintf(lib_path, PATH_MAX, "%s/%s", lib_dir_path, lib_dir->d_name); if (ret < 0) goto free_node;