diff --git a/src/DMRaid.cc b/src/DMRaid.cc index 077831f8..a439826d 100644 --- a/src/DMRaid.cc +++ b/src/DMRaid.cc @@ -17,6 +17,7 @@ #include "../include/DMRaid.h" #include "../include/Partition.h" +#include #include //atoi function namespace GParted @@ -126,11 +127,11 @@ bool DMRaid::is_dmraid_device( const Glib::ustring & dev_path ) if ( ! device_found && file_test( dev_path, Glib::FILE_TEST_IS_SYMLINK ) ) { //Path is a symbolic link so find real path - char c_str[4096+1] ; - //FIXME: it seems realpath is very unsafe to use (manpage)... - if ( realpath( dev_path .c_str(), c_str ) != NULL ) + char * rpath = realpath( dev_path.c_str(), NULL ); + if ( rpath != NULL ) { - Glib::ustring tmp_path = c_str ; + Glib::ustring tmp_path = rpath; + free( rpath ); if ( tmp_path .length() > 0 ) for ( unsigned int k=0; k < dmraid_devices .size(); k++ ) if ( tmp_path .find( dmraid_devices[k] ) != Glib::ustring::npos ) @@ -196,11 +197,11 @@ Glib::ustring DMRaid::get_dmraid_name( const Glib::ustring & dev_path ) if ( dmraid_name .empty() && file_test( dev_path, Glib::FILE_TEST_IS_SYMLINK ) ) { //Path is a symbolic link so find real path - char c_str[4096+1] ; - //FIXME: it seems realpath is very unsafe to use (manpage)... - if( realpath( dev_path .c_str(), c_str ) != NULL ) + char * rpath = realpath( dev_path.c_str(), NULL ); + if ( rpath != NULL ) { - Glib::ustring tmp_path = c_str ; + Glib::ustring tmp_path = rpath; + free( rpath ); if ( tmp_path .length() > 0 ) for ( unsigned int k=0; k < dmraid_devices .size(); k++ ) if ( tmp_path .find( dmraid_devices[k] ) != Glib::ustring::npos ) diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc index fb786efb..be6665cd 100644 --- a/src/GParted_Core.cc +++ b/src/GParted_Core.cc @@ -47,11 +47,14 @@ #include "../include/reiser4.h" #include "../include/ufs.h" #include "../include/Copy_Blocks.h" + #include #include #include #include #include +#include +#include #include #include #include @@ -1091,10 +1094,12 @@ void GParted_Core::add_node_and_mountpoint( // then find real path and add entry too if ( file_test( node, Glib::FILE_TEST_IS_SYMLINK ) ) { - char c_str[4096+1] ; - //FIXME: it seems realpath is very unsafe to use (manpage)... - if ( realpath( node .c_str(), c_str ) != NULL ) - map[ c_str ] .push_back( mountpoint ) ; + char * rpath = realpath( node.c_str(), NULL ); + if ( rpath != NULL ) + { + map[rpath].push_back( mountpoint ); + free( rpath ); + } } } } diff --git a/src/Proc_Partitions_Info.cc b/src/Proc_Partitions_Info.cc index f17f689f..08d2e922 100644 --- a/src/Proc_Partitions_Info.cc +++ b/src/Proc_Partitions_Info.cc @@ -17,6 +17,8 @@ #include "../include/Proc_Partitions_Info.h" #include +#include +#include namespace GParted { @@ -131,16 +133,17 @@ void Proc_Partitions_Info::load_proc_partitions_info_cache() line = "/dev/" ; line += c_str ; - //FIXME: it seems realpath is very unsafe to use (manpage)... - if ( file_test( line, Glib::FILE_TEST_EXISTS ) - && realpath( line .c_str(), c_str ) + char * rpath = NULL; + if ( file_test( line, Glib::FILE_TEST_EXISTS ) + && ( ( rpath = realpath( line.c_str(), NULL ) ) != NULL ) //&& line != c_str ) { //Because we can make no assumption about which path libparted will //detect, we add all combinations. - alternate_paths_cache[ c_str ] = line ; - alternate_paths_cache[ line ] = c_str ; + alternate_paths_cache[rpath] = line; + alternate_paths_cache[line] = rpath; + free( rpath ); } }