@@ -242,7 +242,7 @@ static byte* getBufferFromFile(const char* fileName, word32* bufSz, void* heap)
242242{
243243 FILE * file ;
244244 byte * buf = NULL ;
245- word32 fileSz ;
245+ long fileSz ;
246246 word32 readSz ;
247247
248248 WOLFSSH_UNUSED (heap );
@@ -252,13 +252,17 @@ static byte* getBufferFromFile(const char* fileName, word32* bufSz, void* heap)
252252 if (WFOPEN (NULL , & file , fileName , "rb" ) != 0 )
253253 return NULL ;
254254 WFSEEK (NULL , file , 0 , WSEEK_END );
255- fileSz = (word32 )WFTELL (NULL , file );
255+ fileSz = WFTELL (NULL , file );
256+ if (fileSz < 0 ) {
257+ WFCLOSE (NULL , file );
258+ return NULL ;
259+ }
256260 WREWIND (NULL , file );
257261
258262 buf = (byte * )WMALLOC (fileSz + 1 , heap , DYNTYPE_SSHD );
259263 if (buf != NULL ) {
260264 readSz = (word32 )WFREAD (NULL , buf , 1 , fileSz , file );
261- if (readSz < fileSz ) {
265+ if (readSz < ( size_t ) fileSz ) {
262266 WFCLOSE (NULL , file );
263267 WFREE (buf , heap , DYNTYPE_SSHD );
264268 return NULL ;
@@ -1347,20 +1351,19 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
13471351 setenv ("LOGNAME" , pPasswd -> pw_name , 1 );
13481352 setenv ("SHELL" , pPasswd -> pw_shell , 1 );
13491353
1350- if (pPasswd -> pw_shell ) {
1351- if (WSTRLEN (pPasswd -> pw_shell ) < sizeof (shell )) {
1352- char * cursor ;
1353- char * start ;
1354+ if (WSTRLEN (pPasswd -> pw_shell ) < sizeof (shell )) {
1355+ char * cursor ;
1356+ char * start ;
13541357
1355- WSTRNCPY (shell , pPasswd -> pw_shell , sizeof (shell ));
1356- cursor = shell ;
1357- do {
1358- start = cursor ;
1359- * cursor = '-' ;
1360- cursor = WSTRCHR ( start , '/' ) ;
1361- } while ( cursor && * cursor != '\0 ' );
1362- args [ 0 ] = start ;
1363- }
1358+ WSTRNCPY (shell , pPasswd -> pw_shell , sizeof (shell )- 1 );
1359+ shell [ sizeof ( shell ) - 1 ] = 0 ;
1360+ cursor = shell ;
1361+ do {
1362+ start = cursor ;
1363+ * cursor = '-' ;
1364+ cursor = WSTRCHR ( start , '/ ' );
1365+ } while ( cursor && * cursor != '\0' ) ;
1366+ args [ 0 ] = start ;
13641367 }
13651368
13661369 rc = chdir (pPasswd -> pw_dir );
0 commit comments