comparison gui/mplayer/gui_common.c @ 32709:f1b29f413940

Correct translation of filenames and prevent out-of-bounds array access
author ib
date Tue, 18 Jan 2011 11:39:49 +0000
parents fbe5c829c69b
children f49e1b37281a
comparison
equal deleted inserted replaced
32708:29b63f338a9b 32709:f1b29f413940
52 52
53 static inline void TranslateFilename( int c,char * tmp,size_t tmplen ) 53 static inline void TranslateFilename( int c,char * tmp,size_t tmplen )
54 { 54 {
55 int i; 55 int i;
56 char * p; 56 char * p;
57 size_t len;
57 58
58 switch ( guiIntfStruct.StreamType ) 59 switch ( guiIntfStruct.StreamType )
59 { 60 {
60 case STREAMTYPE_STREAM: 61 case STREAMTYPE_STREAM:
61 av_strlcpy(tmp, guiIntfStruct.Filename, tmplen); 62 av_strlcpy(tmp, guiIntfStruct.Filename, tmplen);
65 { 66 {
66 if ( (p = strrchr(guiIntfStruct.Filename, '/')) ) 67 if ( (p = strrchr(guiIntfStruct.Filename, '/')) )
67 av_strlcpy(tmp, p + 1, tmplen); 68 av_strlcpy(tmp, p + 1, tmplen);
68 else 69 else
69 av_strlcpy(tmp, guiIntfStruct.Filename, tmplen); 70 av_strlcpy(tmp, guiIntfStruct.Filename, tmplen);
70 if ( tmp[strlen( tmp ) - 4] == '.' ) tmp[strlen( tmp ) - 4]=0; 71 len=strlen( tmp );
71 if ( tmp[strlen( tmp ) - 5] == '.' ) tmp[strlen( tmp ) - 5]=0; 72 if ( ( len > 3 )&&( tmp[len - 3] == '.' ) ) tmp[len - 3]=0;
73 else if ( ( len > 4 )&&( tmp[len - 4] == '.' ) ) tmp[len - 4]=0;
74 else if ( ( len > 5 )&&( tmp[len - 5] == '.' ) ) tmp[len - 5]=0;
72 } else av_strlcpy( tmp,MSGTR_NoFileLoaded,tmplen ); 75 } else av_strlcpy( tmp,MSGTR_NoFileLoaded,tmplen );
73 break; 76 break;
74 #ifdef CONFIG_DVDREAD 77 #ifdef CONFIG_DVDREAD
75 case STREAMTYPE_DVD: 78 case STREAMTYPE_DVD:
76 if ( guiIntfStruct.DVD.current_chapter ) snprintf(tmp,tmplen,MSGTR_Chapter,guiIntfStruct.DVD.current_chapter ); 79 if ( guiIntfStruct.DVD.current_chapter ) snprintf(tmp,tmplen,MSGTR_Chapter,guiIntfStruct.DVD.current_chapter );