vlc | branch: master | Rémi Denis-Courmont <[email protected]> | Mon Aug 31 19:50:12 2015 +0300| [d3b3ce68d25db6b6c4df7d3745b159b66387c1af] | committer: Rémi Denis-Courmont
vlm: simplify and fix abnormal cases Correctly reject non-regular files: previously, the code would get stuck on FIFOs, and ignore other types silently. Check that reading the file actually succeeds. > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=d3b3ce68d25db6b6c4df7d3745b159b66387c1af --- src/input/vlmshell.c | 41 +++++++++++++++-------------------------- 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/src/input/vlmshell.c b/src/input/vlmshell.c index a6a75e5..d698639 100644 --- a/src/input/vlmshell.c +++ b/src/input/vlmshell.c @@ -41,6 +41,9 @@ #ifdef ENABLE_VLM #include <time.h> /* ctime() */ +#include <limits.h> +#include <fcntl.h> +#include <sys/stat.h> #include <vlc_input.h> #include "input_internal.h" @@ -49,7 +52,6 @@ #include <vlc_charset.h> #include <vlc_fs.h> #include <vlc_sout.h> -#include <vlc_url.h> #include "../stream_output/stream_output.h" #include "../libvlc.h" @@ -525,44 +527,31 @@ error: static int ExecuteLoad( vlm_t *p_vlm, const char *psz_path, vlm_message_t **pp_status ) { - char *psz_url = vlc_path2uri( psz_path, NULL ); - stream_t *p_stream = stream_UrlNew( p_vlm, psz_url ); - free( psz_url ); - uint64_t i_size; - char *psz_buffer; - - if( !p_stream ) + int fd = vlc_open( psz_path, O_RDONLY|O_NONBLOCK ); + if( fd == -1 ) { *pp_status = vlm_MessageNew( "load", "Unable to load from file" ); return VLC_EGENERIC; } - /* FIXME needed ? */ - if( stream_Seek( p_stream, 0 ) != 0 ) - { - stream_Delete( p_stream ); - - *pp_status = vlm_MessageNew( "load", "Read file error" ); - return VLC_EGENERIC; - } - - i_size = stream_Size( p_stream ); - if( i_size > SIZE_MAX - 1 ) - i_size = SIZE_MAX - 1; + struct stat st; + char *psz_buffer = NULL; - psz_buffer = malloc( i_size + 1 ); - if( !psz_buffer ) + if( fstat( fd, &st ) || !S_ISREG( st.st_mode ) + || st.st_size >= SSIZE_MAX + || ((psz_buffer = malloc( st.st_size + 1 )) == NULL) + || read( fd, psz_buffer, st.st_size ) < (ssize_t)st.st_size ) { - stream_Delete( p_stream ); + free( psz_buffer ); + close( fd ); *pp_status = vlm_MessageNew( "load", "Read file error" ); return VLC_EGENERIC; } - stream_Read( p_stream, psz_buffer, i_size ); - psz_buffer[i_size] = '\0'; + close( fd ); - stream_Delete( p_stream ); + psz_buffer[st.st_size] = '\0'; if( Load( p_vlm, psz_buffer ) ) { _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
