aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2005-11-08 04:25:24 +0000
committerhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2005-11-08 04:25:24 +0000
commit59a6c6c9d64ec3b0c17b05cf2c71f37c5e63508d (patch)
tree41775caf530c807a0b2c6e80fa68d3192d1f88dd /src
parentcc106602861def0fbd4f50154cb36e34921c2367 (diff)
src/ldif.c: ldif_get_line(): fixed buffer overflow.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@720 ee746299-78ed-0310-b773-934348b2243d
Diffstat (limited to 'src')
-rw-r--r--src/ldif.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/src/ldif.c b/src/ldif.c
index eccb306a..91daf0d7 100644
--- a/src/ldif.c
+++ b/src/ldif.c
@@ -229,26 +229,29 @@ static void ldif_close_file( LdifFile *ldifFile ) {
static gchar *ldif_get_line( LdifFile *ldifFile ) {
gchar buf[ LDIFBUFSIZE ];
gint ch;
- gchar *ptr;
+ gint i = 0;
- if( feof( ldifFile->file ) ) return NULL;
+ if( feof( ldifFile->file ) )
+ return NULL;
- ptr = buf;
- while( TRUE ) {
- *ptr = '\0';
+ while( i < LDIFBUFSIZE - 1 ) {
ch = fgetc( ldifFile->file );
if( ch == '\0' || ch == EOF ) {
- if( *buf == '\0' ) return NULL;
+ if( i == 0 )
+ return NULL;
break;
}
#if HAVE_DOSISH_SYSTEM
#else
- if( ch == '\r' ) continue;
+ if( ch == '\r' )
+ continue;
#endif
- if( ch == '\n' ) break;
- *ptr = ch;
- ptr++;
+ if( ch == '\n' )
+ break;
+ buf[i] = ch;
+ i++;
}
+ buf[i] = '\0';
/* Return a copy of buffer */
return g_strdup( buf );