Mercurial > mplayer.hg
changeset 32811:b34b8e47a844
Prevent out buffer overflow.
author | ib |
---|---|
date | Sun, 13 Feb 2011 17:58:02 +0000 |
parents | 9d5519459be8 |
children | b72f64598fe6 |
files | gui/skin/cut.c gui/skin/cut.h |
diffstat | 2 files changed, 12 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/gui/skin/cut.c Sat Feb 12 23:58:50 2011 +0000 +++ b/gui/skin/cut.c Sun Feb 13 17:58:02 2011 +0000 @@ -21,16 +21,19 @@ #include "cut.h" -void cutItem( char * in,char * out,char sep,int num ) +void cutItemString( char * in,char * out,char sep,int num,size_t maxout ) { int i,n,c; for ( c=0,n=0,i=0;i<strlen( in );i++ ) { if ( in[i] == sep ) n++; - if ( n >= num && in[i] != sep ) out[c++]=in[i]; - if ( n >= num && in[i+1] == sep ) { out[c]=0; return; } + if ( n >= num && in[i] != sep ) + { + if ( c + 1 < maxout ) out[c++] = in[i]; + } + if ( n >= num && in[i+1] == sep ) break; } - out[c]=0; + if ( c < maxout ) out[c] = '\0'; } int cutItemToInt( char * in,char sep,int num )
--- a/gui/skin/cut.h Sat Feb 12 23:58:50 2011 +0000 +++ b/gui/skin/cut.h Sun Feb 13 17:58:02 2011 +0000 @@ -19,7 +19,11 @@ #ifndef MPLAYER_GUI_CUT_H #define MPLAYER_GUI_CUT_H -void cutItem( char * in, char * out, char sep, int num ); +#include <stddef.h> + +#define cutItem(in, out, sep, num) cutItemString(in, out, sep, num, sizeof(out)) + +void cutItemString( char * in, char * out, char sep, int num, size_t maxout ); int cutItemToInt( char * in, char sep, int num ); float cutItemToFloat( char * in, char sep, int num ); void cutChunk( char * in, char * s1 );