xcatf.txt
snippets · 2.5 KB · 2010-03-30
xcatf system by Dazzle (Darien): uses xprintf technology to stop strcat overflows.
Download « Back to the snippets list
/*xcatf system by (Dazzle)Darien
*This uses my xprintf technology to stop
*strcat overflows... enjoy
*/
in merc.h
#define MAS 262144
/* xcatf memory overflow detection system, Replacement for strcat */
void safe_strcatf (const char *file, const char *function, int line,int size, char *prev, char *next, ... );
# define xcatf(var, args...) safe_strcatf(__FILE__,__FUNCTION__,__LINE__,sizeof(var), (var),##args )
# define xcatf_2(var, args...) safe_strcatf(__FILE__,__FUNCTION__,__LINE__,MAS, (var),##args )
in handler.c
/* xcatf a formated string */
void safe_strcatf (const char *file, const char *function, int line,int size, char *prev, char *next, ... )
{
char buf [MAS];
va_list args;
va_start ( args, next );
vsnprintf ( buf, MAS, next, args );
va_end ( args );
/*Max Alloc Size is allot!*/
if(size > MAS)
{
char egbug[MSL];
log_string(LOG_BUG, "xcatf size greater then MAS!!!!\n\r");
log_string(LOG_BUG, "ERROR: System Memory Corrupted by Overflow, through xcatf.\n\r");
log_string(LOG_BUG, "Memcheck: xcatf:File %s, Function %s, Line %d.\n\r",file,function,line);
xprintf(egbug, "Memcheck: System memory corrupted by overflow through xcatf: File: %s Function: %s Line: %d",file, function,line);
wiznet(egbug,NULL,NULL,WIZ_MEMCHECK,0,0);
return;
}
if ((unsigned)size < strlen(buf)+1)
{
char egbug[MSL];
log_string(LOG_BUG, "XCATF error: fmt %s.\n\r",next);
log_string(LOG_BUG, "ERROR: System Memory Corrupted by Overflow, through xcatf.\n\r");
log_string(LOG_BUG, "Memcheck: xcatf: File %s, Function %s, Line %d.\n\r",file,function,line);
/*Yes, this is a potential loop bug if infact the xcatf does collapse in on itself..*/
xprintf(egbug, "Memcheck: System memory corrupted by overflow through xcatf: File: %s Function: %s Line: %d",file,function,line);
wiznet(egbug,NULL,NULL,WIZ_MEMCHECK,0,0);
return;
}
strcat ( prev, buf );
/*Just double checking.*/
if( strlen( prev ) > (unsigned)size - 1 )
{
char egbug[MSL];
log_string(LOG_BUG, "XCATF error: fmt %s.\n\r",next);
log_string(LOG_BUG, "ERROR: System Memory Corrupted by Overflow, through xcatf.\n\r");
log_string(LOG_BUG, "Memcheck: Xcatf: File %s, Function %s, Line %d.\n\r",file, function,line);
/*Yes, this is a potential loop bug if infact the xcatf does collapse in on itself..*/
xprintf(egbug, "Memcheck: System memory corrupted by overflow through xcatf: File: %s Function: %s Line: %d",file, function,line);
wiznet(egbug,NULL,NULL,WIZ_MEMCHECK,0,0);
}
}