-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Partial audit for string handling. From: Andrew Dalgleish <[email protected]>
- Loading branch information
Christian Weisgerber
committed
Jun 20, 2004
1 parent
2824d05
commit 1419106
Showing
31 changed files
with
1,676 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
MD5 (bitlbee-0.83-1-darwin.patch) = 2750a59c02fe963187c479e039edde29 | ||
MD5 (bitlbee-0.83.tar.gz) = d379bb7e6b9e89d8af50d6e1114ee22e | ||
RMD160 (bitlbee-0.83-1-darwin.patch) = 348c511c31dea2d36bba5b5d3f43bfb0fbb993a5 | ||
RMD160 (bitlbee-0.83.tar.gz) = 4e5ea7714be3fbfc6823614b46d245bd9f934eec | ||
SHA1 (bitlbee-0.83-1-darwin.patch) = 01f4bbaf7c5f4748828ebcc12e1d4b8ebf32afb6 | ||
SHA1 (bitlbee-0.83.tar.gz) = f553b7b2f5dcc9d453602b99015a1573b3c63bad | ||
MD5 (bitlbee-0.90.tar.gz) = b6a7093651141e95b6ac78bf3eec95f3 | ||
RMD160 (bitlbee-0.90.tar.gz) = 0c9925704935f5a63c26bc0b4eb393c45fc8b051 | ||
SHA1 (bitlbee-0.90.tar.gz) = 18e4daf9f3efe0d3514635398e015612cb6eb924 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
$OpenBSD: patch-bitlbee_c,v 1.1 2004/06/20 16:27:49 naddy Exp $ | ||
--- bitlbee.c.orig 2004-05-28 08:31:48.000000000 +1000 | ||
+++ bitlbee.c 2004-06-09 22:14:42.000000000 +1000 | ||
@@ -314,12 +314,13 @@ int bitlbee_load( irc_t *irc, char* pass | ||
if( irc->status == USTATUS_IDENTIFIED ) | ||
return( 1 ); | ||
|
||
- g_snprintf( s, 511, "%s%s", irc->nick, ".accounts" ); | ||
+ g_snprintf( s, sizeof(s), "%s%s", irc->nick, ".accounts" ); | ||
path = g_build_path( G_DIR_SEPARATOR_S, global.conf->configdir, s, NULL ); | ||
fp = fopen( path, "r" ); | ||
g_free( path ); | ||
if( !fp ) return( 0 ); | ||
|
||
+ COMPILE_TIME_ASSERT(32 < sizeof(s)); | ||
fscanf( fp, "%32[^\n]s", s ); | ||
if( setpass( irc, password, s ) < 0 ) | ||
return( -1 ); | ||
@@ -328,6 +329,7 @@ int bitlbee_load( irc_t *irc, char* pass | ||
account command will not work otherwise. */ | ||
irc->status = USTATUS_IDENTIFIED; | ||
|
||
+ COMPILE_TIME_ASSERT(511 < sizeof(s)); | ||
while( fscanf( fp, "%511[^\n]s", s ) > 0 ) | ||
{ | ||
fgetc( fp ); | ||
@@ -337,12 +339,14 @@ int bitlbee_load( irc_t *irc, char* pass | ||
} | ||
fclose( fp ); | ||
|
||
- g_snprintf( s, 511, "%s%s", irc->nick, ".nicks" ); | ||
+ g_snprintf( s, sizeof(s), "%s%s", irc->nick, ".nicks" ); | ||
path = g_build_path( G_DIR_SEPARATOR_S, global.conf->configdir, s, NULL ); | ||
fp = fopen( path, "r" ); | ||
g_free( path ); | ||
if( !fp ) return( 0 ); | ||
- while( fscanf( fp, "%s %d %s", s, &proto, nick ) > 0 ) | ||
+ COMPILE_TIME_ASSERT(511 < sizeof(s)); | ||
+ COMPILE_TIME_ASSERT(24 < sizeof(nick)); | ||
+ while( fscanf( fp, "%511s %d %24s", s, &proto, nick ) > 0 ) | ||
{ | ||
http_decode( s ); | ||
nick_set( irc, s, proto, nick ); | ||
@@ -351,7 +355,7 @@ int bitlbee_load( irc_t *irc, char* pass | ||
|
||
if( set_getint( IRC, "auto_connect" ) ) | ||
{ | ||
- strcpy( s, "account on" ); /* Can't do this directly because r_c_s alters the string */ | ||
+ strlcpy( s, "account on", sizeof(s) ); /* Can't do this directly because r_c_s alters the string */ | ||
root_command_string( irc, ru, s ); | ||
} | ||
|
||
@@ -391,16 +395,16 @@ int bitlbee_save( irc_t *irc ) | ||
return( 0 ); | ||
} | ||
|
||
- g_snprintf( s, 511, "%s%s", irc->nick, ".nicks~" ); | ||
+ g_snprintf( s, sizeof(s), "%s%s", irc->nick, ".nicks~" ); | ||
path = g_build_path(G_DIR_SEPARATOR_S, global.conf->configdir, s, NULL); | ||
fp = fopen( path, "w" ); | ||
if( !fp ) return( 0 ); | ||
while( n ) | ||
{ | ||
- strcpy( s, n->handle ); | ||
- s[169] = 0; /* Prevent any overflow (169 ~ 512 / 3) */ | ||
- http_encode( s ); | ||
- g_snprintf( s + strlen( s ), 510 - strlen( s ), " %d %s", n->proto, n->nick ); | ||
+ strlcpy( s, n->handle, sizeof(s) ); | ||
+ s[sizeof(s)/3] = 0; /* Prevent any overflow when expanding to %02X */ | ||
+ http_encode( s, sizeof(s) ); | ||
+ g_snprintf( s + strlen( s ), sizeof(s)-strlen( s ), " %d %s", n->proto, n->nick ); | ||
if( fprintf( fp, "%s\n", s ) != strlen( s ) + 1 ) | ||
{ | ||
irc_usermsg( irc, "fprintf() wrote too little. Disk full?" ); | ||
@@ -412,7 +416,7 @@ int bitlbee_save( irc_t *irc ) | ||
} | ||
fclose( fp ); | ||
|
||
- g_snprintf( s, 512, "%s%s", irc->nick, ".nicks" ); | ||
+ g_snprintf( s, sizeof(s), "%s%s", irc->nick, ".nicks" ); | ||
old_path = g_build_path(G_DIR_SEPARATOR_S, global.conf->configdir, s, NULL); | ||
if( unlink( old_path ) != 0 ) | ||
{ | ||
@@ -435,7 +439,7 @@ int bitlbee_save( irc_t *irc ) | ||
g_free( old_path ); | ||
|
||
|
||
- g_snprintf( s, 511, "%s%s", irc->nick, ".accounts~" ); | ||
+ g_snprintf( s, sizeof(s), "%s%s", irc->nick, ".accounts~" ); | ||
path = g_build_path(G_DIR_SEPARATOR_S, global.conf->configdir, s, NULL); | ||
fp = fopen( path, "w" ); | ||
if( !fp ) return( 0 ); | ||
@@ -509,7 +513,7 @@ int bitlbee_save( irc_t *irc ) | ||
} | ||
fclose( fp ); | ||
|
||
- g_snprintf( s, 512, "%s%s", irc->nick, ".accounts" ); | ||
+ g_snprintf( s, sizeof(s), "%s%s", irc->nick, ".accounts" ); | ||
old_path = g_build_path(G_DIR_SEPARATOR_S, global.conf->configdir, s, NULL); | ||
if( unlink( old_path ) != 0 ) | ||
{ | ||
@@ -600,8 +604,9 @@ void http_decode( char *s ) | ||
{ | ||
char *t; | ||
int i, j, k; | ||
+ size_t s_len = strlen(s) + 1; | ||
|
||
- t = bitlbee_alloc( strlen( s ) + 1 ); | ||
+ t = bitlbee_alloc(s_len); | ||
|
||
for( i = j = 0; s[i]; i ++, j ++ ) | ||
{ | ||
@@ -625,24 +630,24 @@ void http_decode( char *s ) | ||
} | ||
t[j] = 0; | ||
|
||
- strcpy( s, t ); | ||
+ strlcpy( s, t, s_len ); | ||
g_free( t ); | ||
} | ||
|
||
/* Warning: This one explodes the string. Worst-cases can make the string 3x its original size! */ | ||
/* This fuction is safe, but make sure you call it safely as well! */ | ||
-void http_encode( char *s ) | ||
+void http_encode( char *s, size_t s_len ) | ||
{ | ||
char *t; | ||
int i, j; | ||
|
||
t = g_strdup( s ); | ||
|
||
- for( i = j = 0; t[i]; i ++, j ++ ) | ||
+ for( i = j = 0; t[i] && j < s_len -1; i ++, j ++ ) | ||
{ | ||
if( t[i] <= ' ' || ((unsigned char *)t)[i] >= 128 || t[i] == '%' ) | ||
{ | ||
- sprintf( s + j, "%%%02X", t[i] ); | ||
+ g_snprintf( s + j, s_len - j, "%%%02X", t[i] ); | ||
j += 2; | ||
} | ||
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
$OpenBSD: patch-commands_c,v 1.1 2004/06/20 16:27:49 naddy Exp $ | ||
--- commands.c.orig 2004-05-12 21:36:25.000000000 +1000 | ||
+++ commands.c 2004-06-08 19:59:37.000000000 +1000 | ||
@@ -63,8 +63,8 @@ int cmd_help( irc_t *irc, char **cmd ) | ||
memset( param, 0, sizeof(param) ); | ||
for ( i = 1; (cmd[i] != NULL && ( strlen(param) < (sizeof(param)-1) ) ); i++ ) { | ||
if ( i != 1 ) // prepend space except for the first parameter | ||
- strcat(param, " "); | ||
- strncat( param, cmd[i], sizeof(param) - strlen(param) - 1 ); | ||
+ strlcat(param, " ", sizeof(param)); | ||
+ strlcat( param, cmd[i], sizeof(param)); | ||
} | ||
|
||
s = help_get( &(global.help), param ); | ||
@@ -111,6 +111,7 @@ int cmd_register( irc_t *irc, char **cmd | ||
{ | ||
int checkie; | ||
char *path, *file; | ||
+ size_t file_len; | ||
|
||
if( global.conf->authmode == AUTHMODE_REGISTERED ) | ||
{ | ||
@@ -118,17 +119,18 @@ int cmd_register( irc_t *irc, char **cmd | ||
return( 0 ); | ||
} | ||
|
||
- file = (char *) bitlbee_alloc( strlen( irc->nick ) + strlen( ".accounts" ) + 1 ); | ||
+ file_len = strlen( irc->nick ) + strlen( ".accounts" ) + 1; | ||
+ file = (char *) bitlbee_alloc( file_len ); | ||
|
||
- strcpy( file, irc->nick ); | ||
- strcat( file, ".accounts" ); | ||
+ strlcpy( file, irc->nick, file_len ); | ||
+ strlcat( file, ".accounts", file_len ); | ||
path = g_build_path( G_DIR_SEPARATOR_S, global.conf->configdir, file, NULL ); | ||
|
||
checkie = g_file_test( path, G_FILE_TEST_EXISTS ) ? 0 : -1 ; | ||
g_free( path ); | ||
|
||
- strcpy( file, irc->nick ); | ||
- strcat( file, ".nicks" ); | ||
+ strlcpy( file, irc->nick, file_len ); | ||
+ strlcat( file, ".nicks", file_len ); | ||
path = g_build_path( G_DIR_SEPARATOR_S, global.conf->configdir, file, NULL ); | ||
|
||
checkie += g_file_test( path, G_FILE_TEST_EXISTS ) ? 0 : -1; | ||
@@ -154,11 +156,13 @@ int cmd_drop( irc_t *irc, char **cmd ) | ||
{ | ||
char *path, *file, s[512]; | ||
FILE *fp; | ||
+ size_t file_len; | ||
|
||
- file = (char *) bitlbee_alloc( strlen( irc->nick ) + strlen( ".accounts" ) + 1 ); | ||
+ file_len = strlen( irc->nick ) + strlen( ".accounts" ) + 1; | ||
+ file = (char *) bitlbee_alloc( file_len ); | ||
|
||
- strcpy( file, irc->nick ); | ||
- strcat( file, ".accounts" ); | ||
+ strlcpy( file, irc->nick, file_len ); | ||
+ strlcat( file, ".accounts", file_len ); | ||
path = g_build_path( G_DIR_SEPARATOR_S, global.conf->configdir, file, NULL ); | ||
|
||
fp = fopen( path, "r" ); | ||
@@ -170,6 +174,7 @@ int cmd_drop( irc_t *irc, char **cmd ) | ||
return( 0 ); | ||
} | ||
|
||
+ COMPILE_TIME_ASSERT(32 < sizeof(s)); | ||
fscanf( fp, "%32[^\n]s", s ); | ||
fclose( fp ); | ||
if( setpass( irc, cmd[1], s ) < 0 ) | ||
@@ -183,8 +188,8 @@ int cmd_drop( irc_t *irc, char **cmd ) | ||
unlink( path ); | ||
g_free( path ); | ||
|
||
- strcpy( file, irc->nick ); | ||
- strcat( file, ".nicks" ); | ||
+ strlcpy( file, irc->nick, file_len ); | ||
+ strlcat( file, ".nicks", file_len ); | ||
path = g_build_path( G_DIR_SEPARATOR_S, global.conf->configdir, file, NULL ); | ||
|
||
unlink( path ); | ||
@@ -676,21 +681,21 @@ int cmd_blist( irc_t *irc, char **cmd ) | ||
|
||
if( online == 1 ) for( u = irc->users; u; u = u->next ) if( u->gc && u->online && !u->away ) | ||
{ | ||
- g_snprintf( s, 63, "%s@%s (%s)", u->user, u->host, proto_name[u->gc->user->protocol] ); | ||
+ g_snprintf( s, sizeof(s), "%s@%s (%s)", u->user, u->host, proto_name[u->gc->user->protocol] ); | ||
irc_usermsg( irc, "%-16.16s %-40.40s %s", u->nick, s, "Online" ); | ||
n_online ++; | ||
} | ||
|
||
if( away == 1 ) for( u = irc->users; u; u = u->next ) if( u->gc && u->online && u->away ) | ||
{ | ||
- g_snprintf( s, 63, "%s@%s (%s)", u->user, u->host, proto_name[u->gc->user->protocol] ); | ||
+ g_snprintf( s, sizeof(s), "%s@%s (%s)", u->user, u->host, proto_name[u->gc->user->protocol] ); | ||
irc_usermsg( irc, "%-16.16s %-40.40s %s", u->nick, s, u->away ); | ||
n_away ++; | ||
} | ||
|
||
if( offline == 1 ) for( u = irc->users; u; u = u->next ) if( u->gc && !u->online ) | ||
{ | ||
- g_snprintf( s, 63, "%s@%s (%s)", u->user, u->host, proto_name[u->gc->user->protocol] ); | ||
+ g_snprintf( s, sizeof(s), "%s@%s (%s)", u->user, u->host, proto_name[u->gc->user->protocol] ); | ||
irc_usermsg( irc, "%-16.16s %-40.40s %s", u->nick, s, "Offline" ); | ||
n_offline ++; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
$OpenBSD: patch-conf_c,v 1.1 2004/06/20 16:27:49 naddy Exp $ | ||
--- conf.c.orig 2004-04-05 06:50:52.000000000 +1000 | ||
+++ conf.c 2004-06-09 21:17:00.000000000 +1000 | ||
@@ -131,9 +131,10 @@ conf_t *conf_load( int argc, char *argv[ | ||
|
||
if( conf->configdir[strlen(conf->configdir)-1] != '/' ) | ||
{ | ||
- char *s = bitlbee_alloc( strlen( conf->configdir ) + 2 ); | ||
+ size_t s_len = strlen( conf->configdir ) + 2 ; | ||
+ char *s = bitlbee_alloc( s_len ); | ||
|
||
- sprintf( s, "%s/", conf->configdir ); | ||
+ g_snprintf( s, s_len, "%s/", conf->configdir ); | ||
g_free( conf->configdir ); | ||
conf->configdir = s; | ||
} |
Oops, something went wrong.