From: Laurent Aimar Date: Mon, 13 Oct 2008 18:20:54 +0000 (+0200) Subject: Sanitize input headers (pass 4). X-Git-Tag: 1.0.0-pre1~2522 X-Git-Url: http://git.videolan.org/gitweb.cgi/vlc.git/?p=vlc.git;p=vlc.git;a=commitdiff_plain;h=ea83a25e84bca24d045c34713ce7008ea5ce4e8a;ds=sidebyside Sanitize input headers (pass 4). --- diff --git a/src/Makefile.am b/src/Makefile.am index cc7c932262..63cee7a7fe 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -311,10 +311,11 @@ SOURCES_libvlc_common = \ input/decoder.h \ input/demux.h \ input/es_out.h \ + input/stream.h \ input/input_internal.h \ input/vlm_internal.h \ input/stream.c \ - input/mem_stream.c \ + input/stream_memory.c \ input/subtitles.c \ input/var.c \ video_output/video_output.c \ diff --git a/src/input/access.c b/src/input/access.c index 6cb3552bed..b6e4201d4a 100644 --- a/src/input/access.c +++ b/src/input/access.c @@ -25,10 +25,8 @@ # include "config.h" #endif -#include -#include - #include "access.h" +#include /***************************************************************************** * access_InternalNew: diff --git a/src/input/access.h b/src/input/access.h new file mode 100644 index 0000000000..51f542914b --- /dev/null +++ b/src/input/access.h @@ -0,0 +1,43 @@ +/***************************************************************************** + * access.h: Input access functions + ***************************************************************************** + * Copyright (C) 1998-2008 the VideoLAN team + * Copyright (C) 2008 Laurent Aimar + * $Id$ + * + * Authors: Laurent Aimar + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + *****************************************************************************/ + +#if defined(__PLUGIN__) || defined(__BUILTIN__) || !defined(__LIBVLC__) +# error This header file can only be included from LibVLC. +#endif + +#ifndef _INPUT_ACCESS_H +#define _INPUT_ACCESS_H 1 + +#include +#include + +#define access_New( a, b, c, d ) __access_New(VLC_OBJECT(a), b, c, d ) +access_t * __access_New( vlc_object_t *p_obj, const char *psz_access, + const char *psz_demux, const char *psz_path ); +access_t * access_FilterNew( access_t *p_source, + const char *psz_access_filter ); +void access_Delete( access_t * ); + +#endif + diff --git a/src/input/demux.c b/src/input/demux.c index 31484f3c0f..89264a6533 100644 --- a/src/input/demux.c +++ b/src/input/demux.c @@ -25,11 +25,9 @@ # include "config.h" #endif -#include -#include - -#include "input_internal.h" #include "demux.h" +#include +#include static bool SkipID3Tag( demux_t * ); static bool SkipAPETag( demux_t *p_demux ); diff --git a/src/input/demux.h b/src/input/demux.h index c2f1bf56e1..77ea695d93 100644 --- a/src/input/demux.h +++ b/src/input/demux.h @@ -29,9 +29,11 @@ #ifndef _INPUT_DEMUX_H #define _INPUT_DEMUX_H 1 -#include +#include #include +#include "stream.h" + /* stream_t *s could be null and then it mean a access+demux in one */ #define demux_New( a, b, c, d, e, f,g ) __demux_New(VLC_OBJECT(a),b,c,d,e,f,g) demux_t *__demux_New(vlc_object_t *p_obj, const char *psz_access, const char *psz_demux, const char *psz_path, stream_t *s, es_out_t *out, bool ); diff --git a/src/input/input.c b/src/input/input.c index bf696f39ec..acae8eac67 100644 --- a/src/input/input.c +++ b/src/input/input.c @@ -39,6 +39,7 @@ #include "es_out.h" #include "access.h" #include "demux.h" +#include "stream.h" #include #include "../stream_output/stream_output.h" diff --git a/src/input/input_internal.h b/src/input/input_internal.h index 915becf248..878d8f032e 100644 --- a/src/input/input_internal.h +++ b/src/input/input_internal.h @@ -31,6 +31,7 @@ #include #include #include +#include /***************************************************************************** * Private input fields @@ -372,34 +373,4 @@ char *input_CreateFilename( vlc_object_t *p_obj, const char *psz_path, const cha #define INPUT_RECORD_PREFIX "vlc-record-%Y-%m-%d-%H:%M:%S-$ N-$ p" -/* Stream */ -/** - * stream_t definition - */ -struct stream_t -{ - VLC_COMMON_MEMBERS - - /*block_t *(*pf_block) ( stream_t *, int i_size );*/ - int (*pf_read) ( stream_t *, void *p_read, unsigned int i_read ); - int (*pf_peek) ( stream_t *, const uint8_t **pp_peek, unsigned int i_peek ); - int (*pf_control)( stream_t *, int i_query, va_list ); - void (*pf_destroy)( stream_t *); - - stream_sys_t *p_sys; - - /* UTF-16 and UTF-32 file reading */ - vlc_iconv_t conv; - int i_char_width; - bool b_little_endian; -}; - -#include - -static inline stream_t *vlc_stream_create( vlc_object_t *obj ) -{ - return (stream_t *)vlc_custom_create( obj, sizeof(stream_t), - VLC_OBJECT_GENERIC, "stream" ); -} - #endif diff --git a/src/input/mem_stream.c b/src/input/mem_stream.c deleted file mode 100644 index fd38b113d6..0000000000 --- a/src/input/mem_stream.c +++ /dev/null @@ -1,161 +0,0 @@ -/***************************************************************************** - * mem_stream.c: stream_t wrapper around memory buffer - ***************************************************************************** - * Copyright (C) 1999-2004 the VideoLAN team - * $Id$ - * - * Authors: Sigmund Augdal Helberg - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. - *****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include - -#include "input_internal.h" - -struct stream_sys_t -{ - bool i_preserve_memory; - int64_t i_pos; /* Current reading offset */ - int64_t i_size; - uint8_t *p_buffer; - -}; - -static int Read ( stream_t *, void *p_read, unsigned int i_read ); -static int Peek ( stream_t *, const uint8_t **pp_peek, unsigned int i_read ); -static int Control( stream_t *, int i_query, va_list ); -static void Delete ( stream_t * ); - -/** - * Create a stream from a memory buffer - * - * \param p_this the calling vlc_object - * \param p_buffer the memory buffer for the stream - * \param i_buffer the size of the buffer - * \param i_preserve_memory if this is set to false the memory buffer - * pointed to by p_buffer is freed on stream_Destroy - */ -stream_t *__stream_MemoryNew( vlc_object_t *p_this, uint8_t *p_buffer, - int64_t i_size, bool i_preserve_memory ) -{ - stream_t *s = vlc_stream_create( p_this ); - stream_sys_t *p_sys; - - if( !s ) return NULL; - - s->p_sys = p_sys = malloc( sizeof( stream_sys_t ) ); - p_sys->i_pos = 0; - p_sys->i_size = i_size; - p_sys->p_buffer = p_buffer; - p_sys->i_preserve_memory = i_preserve_memory; - - s->pf_read = Read; - s->pf_peek = Peek; - s->pf_control = Control; - s->pf_destroy = Delete; - - s->i_char_width = 1; - s->b_little_endian = false; - vlc_object_attach( s, p_this ); - - return s; -} - -static void Delete( stream_t *s ) -{ - if( !s->p_sys->i_preserve_memory ) free( s->p_sys->p_buffer ); - free( s->p_sys ); - vlc_object_detach( s ); - vlc_object_release( s ); -} - -/**************************************************************************** - * AStreamControl: - ****************************************************************************/ -static int Control( stream_t *s, int i_query, va_list args ) -{ - stream_sys_t *p_sys = s->p_sys; - - bool *p_bool; - int64_t *pi_64, i_64; - int i_int; - - switch( i_query ) - { - case STREAM_GET_SIZE: - pi_64 = (int64_t*)va_arg( args, int64_t * ); - *pi_64 = p_sys->i_size; - break; - - case STREAM_CAN_SEEK: - p_bool = (bool*)va_arg( args, bool * ); - *p_bool = true; - break; - - case STREAM_CAN_FASTSEEK: - p_bool = (bool*)va_arg( args, bool * ); - *p_bool = true; - break; - - case STREAM_GET_POSITION: - pi_64 = (int64_t*)va_arg( args, int64_t * ); - *pi_64 = p_sys->i_pos; - break; - - case STREAM_SET_POSITION: - i_64 = (int64_t)va_arg( args, int64_t ); - i_64 = __MAX( i_64, 0 ); - i_64 = __MIN( i_64, s->p_sys->i_size ); - p_sys->i_pos = i_64; - break; - - case STREAM_GET_MTU: - case STREAM_GET_CONTENT_TYPE: - return VLC_EGENERIC; - - case STREAM_CONTROL_ACCESS: - i_int = (int) va_arg( args, int ); - msg_Err( s, "Hey, what are you thinking ?" - "DON'T USE STREAM_CONTROL_ACCESS !!!" ); - return VLC_EGENERIC; - - default: - msg_Err( s, "invalid stream_vaControl query=0x%x", i_query ); - return VLC_EGENERIC; - } - return VLC_SUCCESS; -} - -static int Read( stream_t *s, void *p_read, unsigned int i_read ) -{ - stream_sys_t *p_sys = s->p_sys; - int i_res = __MIN( i_read, p_sys->i_size - p_sys->i_pos ); - memcpy( p_read, p_sys->p_buffer + p_sys->i_pos, i_res ); - p_sys->i_pos += i_res; - return i_res; -} - -static int Peek( stream_t *s, const uint8_t **pp_peek, unsigned int i_read ) -{ - stream_sys_t *p_sys = s->p_sys; - int i_res = __MIN( i_read, p_sys->i_size - p_sys->i_pos ); - *pp_peek = p_sys->p_buffer + p_sys->i_pos; - return i_res; -} diff --git a/src/input/stream.c b/src/input/stream.c index 489f6165b8..c6395e1942 100644 --- a/src/input/stream.c +++ b/src/input/stream.c @@ -26,16 +26,19 @@ #endif #include +#include #include #include #include #include -#include +#include -#include "input_internal.h" #include "access.h" +#include "stream.h" + +#include "input_internal.h" #undef STREAM_DEBUG diff --git a/src/input/stream.h b/src/input/stream.h new file mode 100644 index 0000000000..1b8a51076d --- /dev/null +++ b/src/input/stream.h @@ -0,0 +1,65 @@ +/***************************************************************************** + * stream.h: Input stream functions + ***************************************************************************** + * Copyright (C) 1998-2008 the VideoLAN team + * Copyright (C) 2008 Laurent Aimar + * $Id$ + * + * Authors: Laurent Aimar + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + *****************************************************************************/ + +#if defined(__PLUGIN__) || defined(__BUILTIN__) || !defined(__LIBVLC__) +# error This header file can only be included from LibVLC. +#endif + +#ifndef _INPUT_STREAM_H +#define _INPUT_STREAM_H 1 + +#include +#include + +/** + * stream_t definition + */ +struct stream_t +{ + VLC_COMMON_MEMBERS + + /*block_t *(*pf_block) ( stream_t *, int i_size );*/ + int (*pf_read) ( stream_t *, void *p_read, unsigned int i_read ); + int (*pf_peek) ( stream_t *, const uint8_t **pp_peek, unsigned int i_peek ); + int (*pf_control)( stream_t *, int i_query, va_list ); + void (*pf_destroy)( stream_t *); + + stream_sys_t *p_sys; + + /* UTF-16 and UTF-32 file reading */ + vlc_iconv_t conv; + int i_char_width; + bool b_little_endian; +}; + +#include + +static inline stream_t *vlc_stream_create( vlc_object_t *obj ) +{ + return (stream_t *)vlc_custom_create( obj, sizeof(stream_t), + VLC_OBJECT_GENERIC, "stream" ); +} + +#endif + diff --git a/src/input/stream_memory.c b/src/input/stream_memory.c new file mode 100644 index 0000000000..341f5f6083 --- /dev/null +++ b/src/input/stream_memory.c @@ -0,0 +1,159 @@ +/***************************************************************************** + * stream_memory.c: stream_t wrapper around memory buffer + ***************************************************************************** + * Copyright (C) 1999-2008 the VideoLAN team + * $Id$ + * + * Authors: Sigmund Augdal Helberg + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + *****************************************************************************/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "stream.h" + +struct stream_sys_t +{ + bool i_preserve_memory; + int64_t i_pos; /* Current reading offset */ + int64_t i_size; + uint8_t *p_buffer; + +}; + +static int Read ( stream_t *, void *p_read, unsigned int i_read ); +static int Peek ( stream_t *, const uint8_t **pp_peek, unsigned int i_read ); +static int Control( stream_t *, int i_query, va_list ); +static void Delete ( stream_t * ); + +/** + * Create a stream from a memory buffer + * + * \param p_this the calling vlc_object + * \param p_buffer the memory buffer for the stream + * \param i_buffer the size of the buffer + * \param i_preserve_memory if this is set to false the memory buffer + * pointed to by p_buffer is freed on stream_Destroy + */ +stream_t *__stream_MemoryNew( vlc_object_t *p_this, uint8_t *p_buffer, + int64_t i_size, bool i_preserve_memory ) +{ + stream_t *s = vlc_stream_create( p_this ); + stream_sys_t *p_sys; + + if( !s ) return NULL; + + s->p_sys = p_sys = malloc( sizeof( stream_sys_t ) ); + p_sys->i_pos = 0; + p_sys->i_size = i_size; + p_sys->p_buffer = p_buffer; + p_sys->i_preserve_memory = i_preserve_memory; + + s->pf_read = Read; + s->pf_peek = Peek; + s->pf_control = Control; + s->pf_destroy = Delete; + + s->i_char_width = 1; + s->b_little_endian = false; + vlc_object_attach( s, p_this ); + + return s; +} + +static void Delete( stream_t *s ) +{ + if( !s->p_sys->i_preserve_memory ) free( s->p_sys->p_buffer ); + free( s->p_sys ); + vlc_object_detach( s ); + vlc_object_release( s ); +} + +/**************************************************************************** + * AStreamControl: + ****************************************************************************/ +static int Control( stream_t *s, int i_query, va_list args ) +{ + stream_sys_t *p_sys = s->p_sys; + + bool *p_bool; + int64_t *pi_64, i_64; + int i_int; + + switch( i_query ) + { + case STREAM_GET_SIZE: + pi_64 = (int64_t*)va_arg( args, int64_t * ); + *pi_64 = p_sys->i_size; + break; + + case STREAM_CAN_SEEK: + p_bool = (bool*)va_arg( args, bool * ); + *p_bool = true; + break; + + case STREAM_CAN_FASTSEEK: + p_bool = (bool*)va_arg( args, bool * ); + *p_bool = true; + break; + + case STREAM_GET_POSITION: + pi_64 = (int64_t*)va_arg( args, int64_t * ); + *pi_64 = p_sys->i_pos; + break; + + case STREAM_SET_POSITION: + i_64 = (int64_t)va_arg( args, int64_t ); + i_64 = __MAX( i_64, 0 ); + i_64 = __MIN( i_64, s->p_sys->i_size ); + p_sys->i_pos = i_64; + break; + + case STREAM_GET_MTU: + case STREAM_GET_CONTENT_TYPE: + return VLC_EGENERIC; + + case STREAM_CONTROL_ACCESS: + i_int = (int) va_arg( args, int ); + msg_Err( s, "Hey, what are you thinking ?" + "DON'T USE STREAM_CONTROL_ACCESS !!!" ); + return VLC_EGENERIC; + + default: + msg_Err( s, "invalid stream_vaControl query=0x%x", i_query ); + return VLC_EGENERIC; + } + return VLC_SUCCESS; +} + +static int Read( stream_t *s, void *p_read, unsigned int i_read ) +{ + stream_sys_t *p_sys = s->p_sys; + int i_res = __MIN( i_read, p_sys->i_size - p_sys->i_pos ); + memcpy( p_read, p_sys->p_buffer + p_sys->i_pos, i_res ); + p_sys->i_pos += i_res; + return i_res; +} + +static int Peek( stream_t *s, const uint8_t **pp_peek, unsigned int i_read ) +{ + stream_sys_t *p_sys = s->p_sys; + int i_res = __MIN( i_read, p_sys->i_size - p_sys->i_pos ); + *pp_peek = p_sys->p_buffer + p_sys->i_pos; + return i_res; +}