Commit d3b3ce68 authored by Rémi Denis-Courmont's avatar 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.
parent 5dc2d7fc
......@@ -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 ) )
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment