#include <vlc_osd.h>
#include <vlc_charset.h>
+#include <limits.h>
+
#include "osd_menu.h"
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] = '\\';
/* 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 )
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;
}