1616
1717static bool is_path_allowed (char const * home , char const * newpath )
1818{
19- char const * real_newpath = realpath ( newpath , NULL ) ;
19+ char real_newpath [ PATH_MAX ] ;
2020
21- if (real_newpath == NULL )
21+ if (realpath ( newpath , real_newpath ) == NULL )
2222 return false;
2323 return strncmp (home , real_newpath , strlen (home )) == 0 ;
2424}
2525
2626void cmd_pwd_handler (client_t * client , __attribute__((unused )) const char * _ )
2727{
28- write_msg (client , "257" , "%s" , realpath (client -> currPath , NULL ));
28+ char path_buff [PATH_MAX ];
29+
30+ realpath (client -> currPath , path_buff );
31+ write_msg (client , "257" , "%s" , path_buff );
2932}
3033
3134void cmd_cdup_handler (client_t * client , __attribute__((unused )) const char * _ )
@@ -48,19 +51,18 @@ static int check_for_path_errors(const char *args, const char *realpath_buff,
4851void cmd_cwd_handler (client_t * client , const char * args )
4952{
5053 char new_path [PATH_MAX ] = {0 };
51- char * realpath_buff ;
54+ char realpath_buff [ PATH_MAX ] = { 0 } ;
5255
5356 if (args [0 ] == '/' ) {
54- realpath_buff = realpath (args , NULL );
57+ realpath (args , realpath_buff );
5558 } else {
5659 strcpy (new_path , client -> currPath );
5760 strcat (new_path , "/" );
5861 strcat (new_path , args );
59- realpath_buff = realpath (new_path , NULL );
62+ realpath (new_path , realpath_buff );
6063 if (check_for_path_errors (args , realpath_buff , client ) == -1 )
6164 return ;
6265 }
6366 strcpy (client -> currPath , realpath_buff );
64- free (realpath_buff );
6567 write_msg (client , "250" , "Requested file action okay, completed." );
6668}
0 commit comments