2020
2121/* size of buffer used to share the inital config params to dsp */
2222#define PROC_SHAREDBUF_SIZE (4*1024)
23- #define ENV_PATH_LEN 256
2423#define WORD_SIZE 4
2524
2625extern struct handle_list * hlist ;
@@ -69,13 +68,16 @@ int proc_sharedbuf_init(int dev, int domain) {
6968
7069static int get_non_preload_lib_names (char * * lib_names , size_t * buffer_size , int domain )
7170{
72- int nErr = AEE_SUCCESS , env_list_len = 0 ;
71+ int nErr = AEE_SUCCESS , env_list_len = 0 , concat_len = 0 , new_len = 0 ;
7372 char * data_paths = NULL ;
7473 char * saveptr = NULL ;
75- VERIFYC (NULL != (data_paths = calloc (1 , sizeof (char ) * ENV_PATH_LEN )), AEE_ENOMEMORY );
76- VERIFY (AEE_SUCCESS == (nErr = apps_std_getenv (DSP_LIBRARY_PATH , data_paths , ENV_PATH_LEN , & env_list_len )));
74+ size_t dsp_search_path_len = std_strlen (DSP_LIBRARY_PATH ) + 1 ;
7775
78- char * path = strtok_r (data_paths , ":" , & saveptr );
76+ VERIFYC (* lib_names != NULL , AEE_ENOMEMORY );
77+ VERIFYC (NULL != (data_paths = calloc (1 , sizeof (char ) * dsp_search_path_len )), AEE_ENOMEMORY );
78+ VERIFYC (AEE_SUCCESS == apps_std_getenv (DSP_LIBRARY_PATH , data_paths , dsp_search_path_len , & env_list_len ), AEE_EGETENV );
79+
80+ char * path = strtok_r (data_paths , ";" , & saveptr );
7981 while (path != NULL )
8082 {
8183 struct dirent * entry ;
@@ -85,23 +87,31 @@ static int get_non_preload_lib_names (char** lib_names, size_t* buffer_size, int
8587 while ((entry = readdir (dir )) != NULL ) {
8688 if ( entry -> d_type == DT_REG ) {
8789 char * file = entry -> d_name ;
88- if ( strstr (file , ".so" ) != NULL ) {
89- size_t new_len = * buffer_size + std_strlen (file ) + 1 ;
90- VERIFYC (NULL != (* lib_names = realloc (* lib_names , new_len )), AEE_ENOMEMORY );
91- std_strlcat (* lib_names , file , new_len );
92- std_strlcat (* lib_names , ";" , new_len );
93- * buffer_size = new_len ;
90+ if (std_strstr (file , FILE_EXT ) != NULL ) {
91+ if (concat_len + std_strlen (file ) > MAX_NON_PRELOAD_LIBS_LEN ) {
92+ FARF (ALWAYS ,"ERROR: Failed to pack library names in custom DSP_LIBRARY_PATH as required buffer size exceeds Max limit (%d)." , MAX_NON_PRELOAD_LIBS_LEN );
93+ nErr = AEE_EBUFFERTOOSMALL ;
94+ closedir (dir );
95+ goto bail ;
96+ }
97+ std_strlcat (* lib_names , file , MAX_NON_PRELOAD_LIBS_LEN );
98+ concat_len = std_strlcat (* lib_names , ";" , MAX_NON_PRELOAD_LIBS_LEN );
9499 }
95100 }
96101 }
97- closedir (dir );
98- path = strtok_r (NULL ,":" , & saveptr );
102+ if (dir != NULL ) {
103+ closedir (dir );
104+ }
105+ path = strtok_r (NULL ,";" , & saveptr );
99106 }
100- (* lib_names )[* buffer_size - 1 ] = '\0' ;
101107 * buffer_size = std_strlen (* lib_names ) + 1 ;
102108
103109bail :
104- if (nErr ) {
110+ if (data_paths ) {
111+ free (data_paths );
112+ data_paths = NULL ;
113+ }
114+ if (nErr && (nErr != AEE_EGETENV )) {
105115 FARF (ERROR , "Error 0x%x: %s Failed for domain %d (%s)\n" ,
106116 nErr , __func__ , domain , strerror (errno ));
107117 }
@@ -238,14 +248,15 @@ void fastrpc_process_pack_params(int dev, int domain) {
238248 FARF (ERROR , "Error 0x%x: %s: Failed to pack effective domain id %d in shared buffer" ,
239249 nErr , __func__ , domain );
240250 }
241- if (AEE_SUCCESS != get_non_preload_lib_names (& lib_names , & buffer_size , domain )){
242- return ;
243- }
244- nErr = pack_proc_shared_buf_params (domain , CUSTOM_DSP_SEARCH_PATH_LIBS_ID ,
245- lib_names , buffer_size );
246- if (nErr ) {
247- FARF (ERROR , "Error 0x%x: %s: Failed to pack the directory list in shared buffer" ,
248- nErr , __func__ );
251+ lib_names = (char * )malloc (sizeof (char ) * MAX_NON_PRELOAD_LIBS_LEN );
252+ if (lib_names ) {
253+ if (AEE_SUCCESS == get_non_preload_lib_names (& lib_names , & buffer_size , domain )) {
254+ nErr = pack_proc_shared_buf_params (domain , CUSTOM_DSP_SEARCH_PATH_LIBS_ID , lib_names , buffer_size );
255+ if (nErr ) {
256+ FARF (ERROR , "Error 0x%x: %s: Failed to pack the directory list in shared buffer" ,
257+ nErr , __func__ );
258+ }
259+ }
249260 }
250261 nErr = pack_proc_shared_buf_params (domain , HLOS_PROC_SESS_ID ,
251262 & sess_id , sizeof (sess_id ));
0 commit comments