alternative fix for %s issue, but saves some CPU cycles and is safe

This commit is contained in:
Fish 2007-08-01 03:17:25 +00:00
parent 669b309035
commit e5c34366ed
2 changed files with 20 additions and 3 deletions

13
seen.c
View file

@ -226,10 +226,15 @@ void destroyseenlist(void)
list_destroy_auto(seenlist);
}
#if 0
/** seen_report
*
* handles channel/user message selection
*/
/* we do this via a macro now, to avoid possible exploits,
* see seenserv.h. If the macro isn't portable, then we can use this function now
* without having the exploit present, but its spins more CPU cycles!
*/
static char seen_report_buf[BUFSIZE];
void seen_report( const CmdParams *cmdparams, const char *fmt, ... )
@ -240,18 +245,20 @@ void seen_report( const CmdParams *cmdparams, const char *fmt, ... )
ircvsnprintf( seen_report_buf, BUFSIZE, fmt, ap );
va_end( ap );
if( cmdparams->channel == NULL )
irc_prefmsg (sns_bot, cmdparams->source, seen_report_buf );
irc_prefmsg (sns_bot, cmdparams->source, "%s", seen_report_buf );
else
irc_chanprivmsg (sns_bot, cmdparams->channel->name, seen_report_buf );
irc_chanprivmsg (sns_bot, cmdparams->channel->name, "%s" seen_report_buf );
}
#endif
/*
* Check whether we can run the seen command
*/
static int SeenAvailable( const CmdParams *cmdparams )
{
#if 0
if( strstr(cmdparams->av[0], "%") != NULL )
return NS_FALSE;
#endif
if( cmdparams->source->user->ulevel < NS_ULEVEL_LOCOPER )
{
if( !SeenServ.enable && cmdparams->channel == NULL )

View file

@ -83,6 +83,14 @@ typedef struct SeenData {
int recordsaved;
} SeenData;
/* this should be portable. See http://gcc.gnu.org/onlinedocs/gcc/Variadic-Macros.html
* and http://msdn2.microsoft.com/en-us/library/ms177415(VS.80).aspx and
* http://en.wikipedia.org/wiki/Variadic_macro
*/
#define seen_report(X, Y, ...) \
if (X->channel == NULL) irc_prefmsg (sns_bot, X->source, Y, ## __VA_ARGS__); \
else irc_chanprivmsg (sns_bot, X->channel->name, Y, ## __VA_ARGS__)
typedef struct ExtraSeenChans {
char name[MAXCHANLEN];
Channel *c;
@ -140,7 +148,9 @@ void createseenlist(void);
void loadseendata(void);
int sortlistbytime(const void *key1, const void *key2);
void destroyseenlist(void);
#if 0
void seen_report( const CmdParams *cmdparams, const char *fmt, ... );
#endif
int sns_cmd_seenhost(const CmdParams *cmdparams);
int sns_cmd_seennick(const CmdParams *cmdparams);
int CheckSeenData(const CmdParams *cmdparams, SEEN_CHECK checktype);