X-Git-Url: http://git.videolan.org/gitweb.cgi/vlc.git/?p=vlc.git;p=vlc.git;a=blobdiff_plain;f=modules%2Fmisc%2Fosd%2Fsimple.c;h=d618da1d5c572b8431180032b93ee9c1f5ca6c9e;hp=b48ca3f7dc05d441c0b7e4704de9064ae1e53d92;hb=a5ad91e7fc1d2050ba0ced5283af9ebb80155e81;hpb=eb9e07a916b33ec6a0a91013b124fbd67473b405;ds=sidebyside diff --git a/modules/misc/osd/simple.c b/modules/misc/osd/simple.c index b48ca3f7dc..d618da1d5c 100644 --- a/modules/misc/osd/simple.c +++ b/modules/misc/osd/simple.c @@ -38,6 +38,8 @@ #include #include +#include + #include "osd_menu.h" int osd_parser_simpleOpen( vlc_object_t *p_this ); @@ -91,8 +93,11 @@ int osd_parser_simpleOpen( vlc_object_t *p_this ) /* NULL terminate before asking the length of path[] */ path[PATH_MAX-1] = '\0'; i_len = strlen(&path[0]); - if( i_len == PATH_MAX ) - i_len--; /* truncate to prevent buffer overflow */ + /* Protect against buffer overflow: + * max index is PATH_MAX-1 and we increment by 1 after + * so PATH_MAX-2 is the bigest we can have */ + if( i_len > PATH_MAX - 2 ) + i_len = PATH_MAX - 2; #if defined(WIN32) || defined(UNDER_CE) if( (i_len > 0) && path[i_len] != '\\' ) path[i_len] = '\\'; @@ -113,7 +118,7 @@ int osd_parser_simpleOpen( vlc_object_t *p_this ) /* Peek for 'style' argument */ pos = ftell( fd ); if( pos < 0 ) - goto error; + goto error; result = fscanf(fd, "%24s %24s", &cmd[0], &action[0] ); if( result == 0 || result == EOF ) @@ -505,7 +510,8 @@ int osd_parser_simpleOpen( vlc_object_t *p_this ) error: msg_Err( p_menu, "parsing file failed (returned %d)", result ); - osd_MenuFree( p_menu ); + if( p_menu ) + osd_MenuFree( p_menu ); fclose( fd ); return VLC_EGENERIC; }