From: Shangbin Liu liushangbin@hisilicon.com
Solving the problem of traversing the entire library directory to load alg drv lib may result in unexpected results by specifying the loading directory 'uadk'.
Signed-off-by: Shangbin Liu liushangbin@hisilicon.com --- Makefile.am | 7 +++++-- wd_util.c | 26 +++++++++++++------------- 2 files changed, 18 insertions(+), 15 deletions(-)
diff --git a/Makefile.am b/Makefile.am index f04164f..11aa2a0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -38,8 +38,11 @@ pkginclude_HEADERS = include/wd.h include/wd_cipher.h include/wd_aead.h \ nobase_pkginclude_HEADERS = v1/wd.h v1/wd_cipher.h v1/wd_aead.h v1/uacce.h v1/wd_dh.h \ v1/wd_digest.h v1/wd_rsa.h v1/wd_bmm.h
-lib_LTLIBRARIES=libwd.la libwd_comp.la libwd_crypto.la libhisi_zip.la \ - libhisi_hpre.la libhisi_sec.la +lib_LTLIBRARIES=libwd.la libwd_comp.la libwd_crypto.la + +uadk_driversdir=$(libdir)/uadk +uadk_drivers_LTLIBRARIES=libhisi_sec.la libhisi_hpre.la libhisi_zip.la +
libwd_la_SOURCES=wd.c wd_mempool.c wd.h wd_alg.c wd_alg.h \ v1/wd.c v1/wd.h v1/wd_adapter.c v1/wd_adapter.h \ diff --git a/wd_util.c b/wd_util.c index cb89709..2f6fcf7 100644 --- a/wd_util.c +++ b/wd_util.c @@ -28,7 +28,7 @@ #define US2S(us) ((us) >> 20) #define WD_INIT_RETRY_TIMEOUT 3
-#define DEF_DRV_LIB_FILE "libwd.so" +#define WD_DRV_LIB_DIR "uadk"
struct msg_pool { /* message array allocated dynamically */ @@ -2151,7 +2151,7 @@ static void dladdr_empty(void) int wd_get_lib_file_path(char *lib_file, char *lib_path, bool is_dir) { char file_path[PATH_MAX] = {0}; - char path[PATH_MAX]; + char path[PATH_MAX] = {0}; Dl_info file_info; int len, rc, i;
@@ -2173,16 +2173,17 @@ int wd_get_lib_file_path(char *lib_file, char *lib_path, bool is_dir) }
if (is_dir) { - (void)snprintf(lib_path, PATH_MAX, "%s", file_path); - return 0; + len = snprintf(lib_path, PATH_MAX, "%s/%s", file_path, WD_DRV_LIB_DIR); + if (len < 0) + return -WD_EINVAL; + } else { + len = snprintf(lib_path, PATH_MAX, "%s/%s/%s", file_path, WD_DRV_LIB_DIR, lib_file); + if (len < 0) + return -WD_EINVAL; }
- len = snprintf(lib_path, PATH_MAX, "%s/%s", file_path, lib_file); - if (len < 0) - return -WD_EINVAL; - if (realpath(lib_path, path) == NULL) { - WD_ERR("%s: no such file or directory!\n", path); + WD_ERR("invalid: %s: no such file or directory!\n", path); return -WD_EINVAL; }
@@ -2205,11 +2206,10 @@ void *wd_dlopen_drv(const char *cust_lib_dir) if (ret) return NULL; } else { - (void)snprintf(lib_path, PATH_MAX, "%s/%s", cust_lib_dir, DEF_DRV_LIB_FILE); - ret = access(lib_path, F_OK); - if (ret) + if (realpath(cust_lib_dir, lib_path) == NULL) { + WD_ERR("invalid: %s: no such file or directory!\n", lib_path); return NULL; - + } strncpy(lib_dir_path, cust_lib_dir, PATH_MAX - 1); }