[MPlayer-cvslog] r32898 - in trunk/gui/skin: cut.c cut.h

ib subversion at mplayerhq.hu
Sun Feb 13 18:58:02 CET 2011


Author: ib
Date: Sun Feb 13 18:58:02 2011
New Revision: 32898

Log:
Prevent out buffer overflow.

Modified:
   trunk/gui/skin/cut.c
   trunk/gui/skin/cut.h

Modified: trunk/gui/skin/cut.c
==============================================================================
--- trunk/gui/skin/cut.c	Sun Feb 13 00:58:50 2011	(r32897)
+++ trunk/gui/skin/cut.c	Sun Feb 13 18:58:02 2011	(r32898)
@@ -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 )

Modified: trunk/gui/skin/cut.h
==============================================================================
--- trunk/gui/skin/cut.h	Sun Feb 13 00:58:50 2011	(r32897)
+++ trunk/gui/skin/cut.h	Sun Feb 13 18:58:02 2011	(r32898)
@@ -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 );


More information about the MPlayer-cvslog mailing list