50 lines
1.5 KiB
Plaintext
50 lines
1.5 KiB
Plaintext
$OpenBSD: patch-ini_c,v 1.2 2006/04/11 15:11:33 naddy Exp $
|
|
--- ini.c.orig Thu Feb 24 02:47:58 2005
|
|
+++ ini.c Wed Nov 2 11:51:26 2005
|
|
@@ -46,28 +46,31 @@ int ini_read( ini_t *file )
|
|
while( !feof( file->fp ) )
|
|
{
|
|
*s = 0;
|
|
+ COMPILE_TIME_ASSERT(127 < sizeof(s));
|
|
fscanf( file->fp, "%127[^\n#]s", s );
|
|
fscanf( file->fp, "%*[^\n]s" );
|
|
fgetc( file->fp ); /* Skip newline */
|
|
file->line ++;
|
|
if( strchr( s, '=' ) )
|
|
{
|
|
- sscanf( s, "%[^ =]s", key );
|
|
+ COMPILE_TIME_ASSERT(127 < sizeof(key));
|
|
+ sscanf( s, "%127[^ =]s", key );
|
|
if( ( t = strchr( key, '.' ) ) )
|
|
{
|
|
*t = 0;
|
|
- strcpy( file->section, key );
|
|
+ strlcpy( file->section, key, sizeof(file->section) );
|
|
t ++;
|
|
}
|
|
else
|
|
{
|
|
- strcpy( file->section, file->c_section );
|
|
+ strlcpy( file->section, file->c_section, sizeof(file->section) );
|
|
t = key;
|
|
}
|
|
- sscanf( t, "%s", file->key );
|
|
+ COMPILE_TIME_ASSERT(127 < sizeof(file->key));
|
|
+ sscanf( t, "%127s", file->key );
|
|
t = strchr( s, '=' ) + 1;
|
|
for( i = 0; t[i] == ' '; i ++ );
|
|
- strcpy( file->value, &t[i] );
|
|
+ strlcpy( file->value, &t[i], sizeof(file->value) );
|
|
for( i = strlen( file->value ) - 1; file->value[i] == 32; i -- )
|
|
file->value[i] = 0;
|
|
|
|
@@ -75,7 +78,7 @@ int ini_read( ini_t *file )
|
|
}
|
|
else if( ( t = strchr( s, '[' ) ) )
|
|
{
|
|
- strcpy( file->c_section, t + 1 );
|
|
+ strlcpy( file->c_section, t + 1, sizeof(file->c_section) );
|
|
t = strchr( file->c_section, ']' );
|
|
*t = 0;
|
|
}
|