[vlc-commits] medialibrary: Fix TOCTOU when accesing mrls
Hugo Beauzée-Luyssen
git at videolan.org
Wed Jan 23 11:05:59 CET 2019
vlc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Mon Dec 3 10:14:10 2018 +0100| [244c1c2229a5bb96d90dec230f08409cc50c93a1] | committer: Hugo Beauzée-Luyssen
medialibrary: Fix TOCTOU when accesing mrls
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=244c1c2229a5bb96d90dec230f08409cc50c93a1
---
include/vlc_media_library.h | 2 ++
modules/misc/medialibrary/entities.cpp | 30 +++++++++++++++++++++++++-----
2 files changed, 27 insertions(+), 5 deletions(-)
diff --git a/include/vlc_media_library.h b/include/vlc_media_library.h
index 6e51b502fa..27a4324465 100644
--- a/include/vlc_media_library.h
+++ b/include/vlc_media_library.h
@@ -121,6 +121,8 @@ typedef struct vlc_ml_file_t
char* psz_mrl;
vlc_ml_file_type_t i_type;
bool b_external;
+ bool b_removable;
+ bool b_present;
} vlc_ml_file_t;
typedef struct vlc_ml_file_list_t
diff --git a/modules/misc/medialibrary/entities.cpp b/modules/misc/medialibrary/entities.cpp
index ef78221780..c9c411639f 100644
--- a/modules/misc/medialibrary/entities.cpp
+++ b/modules/misc/medialibrary/entities.cpp
@@ -38,6 +38,7 @@
#include <medialibrary/IAudioTrack.h>
#include <medialibrary/IVideoTrack.h>
#include <medialibrary/IFolder.h>
+#include <medialibrary/filesystem/IDevice.h>
#include <algorithm>
@@ -260,8 +261,18 @@ bool Convert( const medialibrary::IFile* input, vlc_ml_file_t& output )
vlc_assert_unreachable();
}
- if( !strdup_helper( input->mrl(), output.psz_mrl ) )
- return false;
+ output.b_removable = input->isRemovable();
+ output.b_present = true;
+ try
+ {
+ if( !strdup_helper( input->mrl(), output.psz_mrl ) )
+ return false;
+ }
+ catch ( const medialibrary::fs::DeviceRemovedException& )
+ {
+ output.psz_mrl = nullptr;
+ output.b_present = false;
+ }
output.b_external = input->isExternal();
return true;
@@ -371,13 +382,13 @@ bool Convert( const medialibrary::IPlaylist* input, vlc_ml_playlist_t& output )
bool Convert( const medialibrary::IFolder* input, vlc_ml_entry_point_t& output )
{
- if ( input->isPresent() == true )
+ try
{
if ( strdup_helper( input->mrl(), output.psz_mrl ) == false )
return false;
output.b_present = true;
}
- else
+ catch ( const medialibrary::fs::DeviceRemovedException& )
{
output.psz_mrl = nullptr;
output.b_present = false;
@@ -394,8 +405,17 @@ input_item_t* MediaToInputItem( const medialibrary::IMedia* media )
return f->type() == medialibrary::IFile::Type::Main;
});
assert( it != cend( files ) );
+ std::string mrl;
+ try
+ {
+ mrl = (*it)->mrl();
+ }
+ catch ( const medialibrary::fs::DeviceRemovedException& ex )
+ {
+ return nullptr;
+ }
auto inputItem = vlc::wrap_cptr<input_item_t>(
- input_item_NewExt( (*it)->mrl().c_str(), media->fileName().c_str(),
+ input_item_NewExt( mrl.c_str(), media->fileName().c_str(),
VLC_TICK_FROM_MS( media->duration() ),
ITEM_TYPE_FILE, ITEM_NET_UNKNOWN ),
&input_item_Release );
More information about the vlc-commits
mailing list