Commit eb9e07a9 authored by Jean-Paul Saman's avatar Jean-Paul Saman

Fix crash when osdmenu failed loading.

parent d4915c18
/***************************************************************************** /*****************************************************************************
* parser.c : OSD import module * parser.c : OSD import module
***************************************************************************** *****************************************************************************
* Copyright (C) 2007 M2X * Copyright (C) 2007-2008 M2X
* $Id$ * $Id$
* *
* Authors: Jean-Paul Saman * Authors: Jean-Paul Saman
...@@ -120,6 +120,8 @@ void osd_ButtonFree( osd_menu_t *p_menu, osd_button_t *p_button ) ...@@ -120,6 +120,8 @@ void osd_ButtonFree( osd_menu_t *p_menu, osd_button_t *p_button )
osd_button_t *p_next = NULL; osd_button_t *p_next = NULL;
osd_button_t *p_prev = NULL; osd_button_t *p_prev = NULL;
if( !p_current ) return;
/* First walk to the end. */ /* First walk to the end. */
while( p_current->p_next ) while( p_current->p_next )
{ {
...@@ -218,9 +220,11 @@ osd_state_t *osd_StateNew( osd_menu_t *p_menu, const char *psz_file, ...@@ -218,9 +220,11 @@ osd_state_t *osd_StateNew( osd_menu_t *p_menu, const char *psz_file,
{ {
p_state->p_pic = image_ReadUrl( p_menu->p_image, psz_file, p_state->p_pic = image_ReadUrl( p_menu->p_image, psz_file,
&fmt_in, &fmt_out ); &fmt_in, &fmt_out );
if( p_state->p_pic )
p_state->i_width = p_state->p_pic->p[Y_PLANE].i_visible_pitch; {
p_state->i_height = p_state->p_pic->p[Y_PLANE].i_visible_lines; p_state->i_width = p_state->p_pic->p[Y_PLANE].i_visible_pitch;
p_state->i_height = p_state->p_pic->p[Y_PLANE].i_visible_lines;
}
} }
if( psz_state ) if( psz_state )
...@@ -248,6 +252,8 @@ void osd_StatesFree( osd_menu_t *p_menu, osd_state_t *p_states ) ...@@ -248,6 +252,8 @@ void osd_StatesFree( osd_menu_t *p_menu, osd_state_t *p_states )
osd_state_t *p_next = NULL; osd_state_t *p_next = NULL;
osd_state_t *p_prev = NULL; osd_state_t *p_prev = NULL;
if( !p_state ) return;
while( p_state->p_next ) while( p_state->p_next )
{ {
p_next = p_state->p_next; p_next = p_state->p_next;
......
/***************************************************************************** /*****************************************************************************
* simple.c - The OSD Menu simple parser code. * simple.c - The OSD Menu simple parser code.
***************************************************************************** *****************************************************************************
* Copyright (C) 2005-2007 M2X * Copyright (C) 2005-2008 M2X
* $Id$ * $Id$
* *
* Authors: Jean-Paul Saman * Authors: Jean-Paul Saman
...@@ -51,7 +51,6 @@ int osd_parser_simpleOpen( vlc_object_t *p_this ) ...@@ -51,7 +51,6 @@ int osd_parser_simpleOpen( vlc_object_t *p_this )
osd_button_t *p_current = NULL; /* button currently processed */ osd_button_t *p_current = NULL; /* button currently processed */
osd_button_t *p_prev = NULL; /* previous processed button */ osd_button_t *p_prev = NULL; /* previous processed button */
#define MAX_FILE_PATH 256
FILE *fd = NULL; FILE *fd = NULL;
int result = 0; int result = 0;
...@@ -71,7 +70,7 @@ int osd_parser_simpleOpen( vlc_object_t *p_this ) ...@@ -71,7 +70,7 @@ int osd_parser_simpleOpen( vlc_object_t *p_this )
{ {
char action[25] = ""; char action[25] = "";
char cmd[25] = ""; char cmd[25] = "";
char path[MAX_FILE_PATH] = ""; char path[PATH_MAX] = "";
char *psz_path = NULL; char *psz_path = NULL;
size_t i_len = 0; size_t i_len = 0;
long pos = 0; long pos = 0;
...@@ -85,14 +84,14 @@ int osd_parser_simpleOpen( vlc_object_t *p_this ) ...@@ -85,14 +84,14 @@ int osd_parser_simpleOpen( vlc_object_t *p_this )
/* psz_path is not null and therefor &path[0] cannot be NULL /* psz_path is not null and therefor &path[0] cannot be NULL
* it might be null terminated. * it might be null terminated.
*/ */
strncpy( &path[0], psz_path, MAX_FILE_PATH ); strncpy( &path[0], psz_path, PATH_MAX );
free( psz_path ); free( psz_path );
psz_path = NULL; psz_path = NULL;
} }
/* NULL terminate before asking the length of path[] */ /* NULL terminate before asking the length of path[] */
path[MAX_FILE_PATH-1] = '\0'; path[PATH_MAX-1] = '\0';
i_len = strlen(&path[0]); i_len = strlen(&path[0]);
if( i_len == MAX_FILE_PATH ) if( i_len == PATH_MAX )
i_len--; /* truncate to prevent buffer overflow */ i_len--; /* truncate to prevent buffer overflow */
#if defined(WIN32) || defined(UNDER_CE) #if defined(WIN32) || defined(UNDER_CE)
if( (i_len > 0) && path[i_len] != '\\' ) if( (i_len > 0) && path[i_len] != '\\' )
...@@ -153,7 +152,7 @@ int osd_parser_simpleOpen( vlc_object_t *p_this ) ...@@ -153,7 +152,7 @@ int osd_parser_simpleOpen( vlc_object_t *p_this )
char action[25] = ""; char action[25] = "";
char state[25] = ""; char state[25] = "";
char file[256] = ""; char file[256] = "";
char path[512] = ""; char path[PATH_MAX] = "";
int i_x = 0; int i_x = 0;
int i_y = 0; int i_y = 0;
...@@ -261,8 +260,13 @@ int osd_parser_simpleOpen( vlc_object_t *p_this ) ...@@ -261,8 +260,13 @@ int osd_parser_simpleOpen( vlc_object_t *p_this )
size_t i_path_size = strlen( p_menu->psz_path ); size_t i_path_size = strlen( p_menu->psz_path );
size_t i_file_size = strlen( &file[0] ); size_t i_file_size = strlen( &file[0] );
if( (i_path_size + i_file_size >= PATH_MAX) ||
(i_path_size >= PATH_MAX) )
goto error;
strncpy( &path[0], p_menu->psz_path, i_path_size ); strncpy( &path[0], p_menu->psz_path, i_path_size );
strncpy( &path[i_path_size], &file[0], 512 - (i_path_size + i_file_size) ); strncpy( &path[i_path_size], &file[0],
PATH_MAX - (i_path_size + i_file_size) );
path[ i_path_size + i_file_size ] = '\0'; path[ i_path_size + i_file_size ] = '\0';
p_range_current = osd_StateNew( p_menu, &path[0], "pressed" ); p_range_current = osd_StateNew( p_menu, &path[0], "pressed" );
...@@ -366,8 +370,13 @@ int osd_parser_simpleOpen( vlc_object_t *p_this ) ...@@ -366,8 +370,13 @@ int osd_parser_simpleOpen( vlc_object_t *p_this )
size_t i_path_size = strlen( p_menu->psz_path ); size_t i_path_size = strlen( p_menu->psz_path );
size_t i_file_size = strlen( &file[0] ); size_t i_file_size = strlen( &file[0] );
if( (i_path_size + i_file_size >= PATH_MAX) ||
(i_path_size >= PATH_MAX) )
goto error;
strncpy( &path[0], p_menu->psz_path, i_path_size ); strncpy( &path[0], p_menu->psz_path, i_path_size );
strncpy( &path[i_path_size], &file[0], 512 - (i_path_size + i_file_size) ); strncpy( &path[i_path_size], &file[0],
PATH_MAX - (i_path_size + i_file_size) );
path[ i_path_size + i_file_size ] = '\0'; path[ i_path_size + i_file_size ] = '\0';
p_range_current = osd_StateNew( p_menu, &path[0], "pressed" ); p_range_current = osd_StateNew( p_menu, &path[0], "pressed" );
...@@ -442,8 +451,13 @@ int osd_parser_simpleOpen( vlc_object_t *p_this ) ...@@ -442,8 +451,13 @@ int osd_parser_simpleOpen( vlc_object_t *p_this )
size_t i_path_size = strlen( p_menu->psz_path ); size_t i_path_size = strlen( p_menu->psz_path );
size_t i_file_size = strlen( &file[0] ); size_t i_file_size = strlen( &file[0] );
if( (i_path_size + i_file_size >= PATH_MAX) ||
(i_path_size >= PATH_MAX) )
goto error;
strncpy( &path[0], p_menu->psz_path, i_path_size ); strncpy( &path[0], p_menu->psz_path, i_path_size );
strncpy( &path[i_path_size], &file[0], 512 - (i_path_size + i_file_size) ); strncpy( &path[i_path_size], &file[0],
PATH_MAX - (i_path_size + i_file_size) );
path[ i_path_size + i_file_size ] = '\0'; path[ i_path_size + i_file_size ] = '\0';
p_state_current = osd_StateNew( p_menu, &path[0], &state[0] ); p_state_current = osd_StateNew( p_menu, &path[0], &state[0] );
...@@ -489,7 +503,6 @@ int osd_parser_simpleOpen( vlc_object_t *p_this ) ...@@ -489,7 +503,6 @@ int osd_parser_simpleOpen( vlc_object_t *p_this )
fclose( fd ); fclose( fd );
return VLC_SUCCESS; return VLC_SUCCESS;
#undef MAX_FILE_PATH
error: error:
msg_Err( p_menu, "parsing file failed (returned %d)", result ); msg_Err( p_menu, "parsing file failed (returned %d)", result );
osd_MenuFree( p_menu ); osd_MenuFree( p_menu );
......
/***************************************************************************** /*****************************************************************************
* osd.c - The OSD Menu core code. * osd.c - The OSD Menu core code.
***************************************************************************** *****************************************************************************
* Copyright (C) 2005-2007 M2X * Copyright (C) 2005-2008 M2X
* $Id$ * $Id$
* *
* Authors: Jean-Paul Saman <jpsaman #_at_# m2x dot nl> * Authors: Jean-Paul Saman <jpsaman #_at_# m2x dot nl>
...@@ -38,10 +38,6 @@ ...@@ -38,10 +38,6 @@
#undef OSD_MENU_DEBUG #undef OSD_MENU_DEBUG
#if 0
static const char *ppsz_button_states[] = { "unselect", "select", "pressed" };
#endif
/***************************************************************************** /*****************************************************************************
* Local prototypes * Local prototypes
*****************************************************************************/ *****************************************************************************/
...@@ -74,6 +70,7 @@ static osd_menu_t *osd_ParserLoad( vlc_object_t *p_this, const char *psz_file ) ...@@ -74,6 +70,7 @@ static osd_menu_t *osd_ParserLoad( vlc_object_t *p_this, const char *psz_file )
if( !p_menu ) if( !p_menu )
return NULL; return NULL;
p_menu->p_parser = NULL;
vlc_object_attach( p_menu, p_this->p_libvlc ); vlc_object_attach( p_menu, p_this->p_libvlc );
/* Stuff needed for Parser */ /* Stuff needed for Parser */
...@@ -110,12 +107,12 @@ static void osd_ParserUnload( osd_menu_t *p_menu ) ...@@ -110,12 +107,12 @@ static void osd_ParserUnload( osd_menu_t *p_menu )
{ {
if( p_menu->p_image ) if( p_menu->p_image )
image_HandlerDelete( p_menu->p_image ); image_HandlerDelete( p_menu->p_image );
if( p_menu->psz_file )
free( p_menu->psz_file );
if( p_menu->p_parser ) if( p_menu->p_parser )
module_Unneed( p_menu, p_menu->p_parser ); module_Unneed( p_menu, p_menu->p_parser );
free( p_menu->psz_file );
vlc_object_detach( p_menu ); vlc_object_detach( p_menu );
vlc_object_release( p_menu ); vlc_object_release( p_menu );
} }
...@@ -123,7 +120,7 @@ static void osd_ParserUnload( osd_menu_t *p_menu ) ...@@ -123,7 +120,7 @@ static void osd_ParserUnload( osd_menu_t *p_menu )
/** /**
* Change state on an osd_button_t. * Change state on an osd_button_t.
* *
* This function selects the specified state and returns a pointer to it. The * This function selects the specified state and returns a pointer vlc_custom_createto it. The
* following states are currently supported: * following states are currently supported:
* \see OSD_BUTTON_UNSELECT * \see OSD_BUTTON_UNSELECT
* \see OSD_BUTTON_SELECT * \see OSD_BUTTON_SELECT
...@@ -173,7 +170,7 @@ osd_menu_t *__osd_MenuCreate( vlc_object_t *p_this, const char *psz_file ) ...@@ -173,7 +170,7 @@ osd_menu_t *__osd_MenuCreate( vlc_object_t *p_this, const char *psz_file )
/* Parse configuration file */ /* Parse configuration file */
p_osd = osd_ParserLoad( p_this, psz_file ); p_osd = osd_ParserLoad( p_this, psz_file );
if( !p_osd ) if( !p_osd || !p_osd->p_state )
goto error; goto error;
/* Setup default button (first button) */ /* Setup default button (first button) */
...@@ -207,16 +204,7 @@ osd_menu_t *__osd_MenuCreate( vlc_object_t *p_this, const char *psz_file ) ...@@ -207,16 +204,7 @@ osd_menu_t *__osd_MenuCreate( vlc_object_t *p_this, const char *psz_file )
return p_osd; return p_osd;
error: error:
msg_Err( p_this, "creating OSD menu object failed" ); __osd_MenuDelete( p_this, p_osd );
if( p_osd->p_image )
image_HandlerDelete( p_osd->p_image );
if( p_osd->psz_file )
free( p_osd->psz_file );
vlc_object_detach( p_osd );
vlc_object_release( p_osd );
vlc_mutex_unlock( lockval.p_address );
return NULL; return NULL;
} }
......
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