Security: replace all uses of strcat and strcpy with strncat and strncpy

This commit is contained in:
rocky
2006-03-18 00:53:20 +00:00
parent 94eda2ef9d
commit 49bc5ccb3f
6 changed files with 32 additions and 56 deletions

View File

@@ -1,5 +1,5 @@
/*
$Id: utils.c,v 1.2 2005/01/14 01:36:12 rocky Exp $
$Id: utils.c,v 1.3 2006/03/18 00:53:20 rocky Exp $
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
Copyright (C) 1998 Monty xiphmont@mit.edu
@@ -112,9 +112,10 @@ idmessage(int messagedest,char **messages,const char *f,
if(!s)
buffer=(char *)f;
else{
buffer=malloc(strlen(f)+strlen(s)+10);
const unsigned int i_buffer=strlen(f)+strlen(s)+10;
buffer=malloc(i_buffer);
sprintf(buffer,f,s);
strcat(buffer,"\n");
strncat(buffer,"\n", i_buffer);
malloced=1;
}
@@ -138,13 +139,15 @@ idmessage(int messagedest,char **messages,const char *f,
}
char *
catstring(char *buff,const char *s){
if(s){
if(buff)
buff=realloc(buff,strlen(buff)+strlen(s)+9);
else
buff=calloc(strlen(s)+9,1);
strcat(buff,s);
catstring(char *buff, const char *s) {
if (s) {
const unsigned int add_len = strlen(s) + 9;
if(buff) {
buff = realloc(buff, strlen(buff) + add_len);
} else {
buff=calloc(add_len, 1);
}
strncat(buff, s, add_len);
}
return(buff);
}