Commit 710cc84c authored by rswindell's avatar rswindell
Browse files

Alway truncate vsnprintf-formatted strings at maximum length regardless of

return value (some implementations do not return negative on overflow).
parent 79ad24f2
......@@ -127,8 +127,8 @@ int sbbs_t::bprintf(char *fmt, ...)
if(!strchr(fmt,'%'))
return(bputs(fmt));
va_start(argptr,fmt);
if(vsnprintf(sbuf,sizeof(sbuf),fmt,argptr)<0)
sbuf[sizeof(sbuf)-1]=0; /* force termination */
vsnprintf(sbuf,sizeof(sbuf),fmt,argptr);
sbuf[sizeof(sbuf)-1]=0; /* force termination */
va_end(argptr);
return(bputs(sbuf));
}
......@@ -142,8 +142,8 @@ int sbbs_t::rprintf(char *fmt, ...)
char sbuf[4096];
va_start(argptr,fmt);
if(vsnprintf(sbuf,sizeof(sbuf),fmt,argptr)<0)
sbuf[sizeof(sbuf)-1]=0; /* force termination */
vsnprintf(sbuf,sizeof(sbuf),fmt,argptr);
sbuf[sizeof(sbuf)-1]=0; /* force termination */
va_end(argptr);
return(rputs(sbuf));
}
......
......@@ -80,8 +80,8 @@ int sbbs_t::exec_misc(csi_t* csi, char *path)
else
arglist[i]=*(char **)vp;
csi->ip+=4; }
if(vsnprintf(tmp,sizeof(tmp),str,(char*)arglist)<0)
tmp[sizeof(tmp)-1]=0;
vsnprintf(tmp,sizeof(tmp),str,(char*)arglist);
tmp[sizeof(tmp)-1]=0;
if(op==VAR_PRINTF)
putmsg(cmdstr(tmp,path,csi->str,buf),P_SAVEATR|P_NOABORT);
else {
......@@ -504,8 +504,8 @@ int sbbs_t::exec_misc(csi_t* csi, char *path)
else
arglist[i]=*(char **)vp;
csi->ip+=4; }
if(vsnprintf(tmp,sizeof(tmp),str,(char *)arglist)<0)
tmp[sizeof(tmp)-1]=0;
vsnprintf(tmp,sizeof(tmp),str,(char *)arglist);
tmp[sizeof(tmp)-1]=0;
cmdstr(tmp,path,csi->str,str);
if(pp)
*pp=copystrvar(csi,*pp,str);
......@@ -1314,8 +1314,8 @@ int sbbs_t::exec_misc(csi_t* csi, char *path)
arglist[i]=*(char **)vp;
csi->ip+=4;
}
if(vsnprintf(tmp,sizeof(tmp),str,(char *)arglist)<0)
tmp[sizeof(tmp)-1]=0;
vsnprintf(tmp,sizeof(tmp),str,(char *)arglist);
tmp[sizeof(tmp)-1]=0;
if(lp1 && *lp1) {
cmdstr(tmp,path,csi->str,str);
fwrite(str,1,strlen(str),(FILE *)*lp1);
......
......@@ -155,8 +155,8 @@ static int lprintf(char *fmt, ...)
#endif
va_start(argptr,fmt);
if(vsnprintf(sbuf,sizeof(sbuf),fmt,argptr)<0)
sbuf[sizeof(sbuf)-1]=0;
vsnprintf(sbuf,sizeof(sbuf),fmt,argptr);
sbuf[sizeof(sbuf)-1]=0;
va_end(argptr);
result=startup->lputs(sbuf);
......@@ -304,8 +304,7 @@ static int sockprintf(SOCKET sock, char *fmt, ...)
va_start(argptr,fmt);
len=vsnprintf(sbuf,sizeof(sbuf),fmt,argptr);
if(len<0)
sbuf[sizeof(sbuf)-1]=0;
sbuf[sizeof(sbuf)-1]=0;
if(startup!=NULL && startup->options&FTP_OPT_DEBUG_TX)
lprintf("%04d TX: %s", sock, sbuf);
strcat(sbuf,"\r\n");
......
......@@ -60,8 +60,8 @@ static void dbprintf(BOOL error, private_t* p, char* fmt, ...)
return;
va_start(argptr,fmt);
if(vsnprintf(sbuf,sizeof(sbuf),fmt,argptr)<0)
sbuf[sizeof(sbuf)-1]=0;
vsnprintf(sbuf,sizeof(sbuf),fmt,argptr);
sbuf[sizeof(sbuf)-1]=0;
va_end(argptr);
lprintf("%04u File %s%s",p->fp ? fileno(p->fp) : 0,error ? "ERROR: ":"",sbuf);
......
......@@ -60,8 +60,8 @@ static void dbprintf(BOOL error, private_t* p, char* fmt, ...)
return;
va_start(argptr,fmt);
if(vsnprintf(sbuf,sizeof(sbuf),fmt,argptr)<0)
sbuf[sizeof(sbuf)-1]=0;
vsnprintf(sbuf,sizeof(sbuf),fmt,argptr);
sbuf[sizeof(sbuf)-1]=0;
va_end(argptr);
lprintf("%04d Socket %s%s",p->sock,error ? "ERROR: ":"",sbuf);
......
......@@ -115,8 +115,8 @@ static int lprintf(char *fmt, ...)
#endif
va_start(argptr,fmt);
if(vsnprintf(sbuf,sizeof(sbuf),fmt,argptr)<0)
sbuf[sizeof(sbuf)-1]=0;
vsnprintf(sbuf,sizeof(sbuf),fmt,argptr);
sbuf[sizeof(sbuf)-1]=0;
va_end(argptr);
return(startup->lputs(sbuf));
}
......@@ -275,8 +275,7 @@ int sockprintf(SOCKET sock, char *fmt, ...)
va_start(argptr,fmt);
len=vsnprintf(sbuf,sizeof(sbuf),fmt,argptr);
if(len<0)
sbuf[sizeof(sbuf)-1]=0;
sbuf[sizeof(sbuf)-1]=0;
if(startup->options&MAIL_OPT_DEBUG_TX)
lprintf("%04d TX: %s", sock, sbuf);
strcat(sbuf,"\r\n");
......
......@@ -152,8 +152,8 @@ int lprintf(char *fmt, ...)
return(0);
va_start(argptr,fmt);
if(vsnprintf(sbuf,sizeof(sbuf),fmt,argptr)<0)
sbuf[sizeof(sbuf)-1]=0;
vsnprintf(sbuf,sizeof(sbuf),fmt,argptr);
sbuf[sizeof(sbuf)-1]=0;
va_end(argptr);
return(startup->lputs(sbuf));
}
......@@ -167,8 +167,8 @@ int eprintf(char *fmt, ...)
return(0);
va_start(argptr,fmt);
if(vsnprintf(sbuf,sizeof(sbuf),fmt,argptr)<0)
sbuf[sizeof(sbuf)-1]=0;
vsnprintf(sbuf,sizeof(sbuf),fmt,argptr);
sbuf[sizeof(sbuf)-1]=0;
va_end(argptr);
return(startup->event_log(sbuf));
}
......
......@@ -227,8 +227,7 @@ int lprintf(char *fmat, ...)
va_start(argptr,fmat);
chcount=vsnprintf(sbuf,sizeof(sbuf),fmat,argptr);
if(chcount<0)
sbuf[sizeof(sbuf)-1]=0;
sbuf[sizeof(sbuf)-1]=0;
va_end(argptr);
lputs(sbuf);
return(chcount);
......
......@@ -137,8 +137,7 @@ int lprintf(char *fmat, ...)
va_start(argptr,fmat);
chcount=vsnprintf(sbuf,sizeof(sbuf),fmat,argptr);
if(chcount<0)
sbuf[sizeof(sbuf)-1]=0;
sbuf[sizeof(sbuf)-1]=0;
va_end(argptr);
lputs(sbuf);
return(chcount);
......@@ -238,18 +237,19 @@ void logprintf(char *str, ...)
time_t now;
struct tm *gm;
if(!(misc&LOGFILE) || fidologfile==NULL)
return;
va_start(argptr,str);
vsprintf(buf,str,argptr);
va_end(argptr);
now=time(NULL);
gm=localtime(&now);
fseek(fidologfile,0L,SEEK_END);
fprintf(fidologfile,"%02u/%02u/%02u %02u:%02u:%02u %s\r\n"
,gm->tm_mon+1,gm->tm_mday,TM_YEAR(gm->tm_year),gm->tm_hour,gm->tm_min,gm->tm_sec
,buf);
fflush(fidologfile);
if(!(misc&LOGFILE) || fidologfile==NULL)
return;
va_start(argptr,str);
vsnprintf(buf,sizeof(buf),str,argptr);
buf[sizeof(buf)-1]=0;
va_end(argptr);
now=time(NULL);
gm=localtime(&now);
fseek(fidologfile,0L,SEEK_END);
fprintf(fidologfile,"%02u/%02u/%02u %02u:%02u:%02u %s\r\n"
,gm->tm_mon+1,gm->tm_mday,TM_YEAR(gm->tm_year),gm->tm_hour,gm->tm_min,gm->tm_sec
,buf);
fflush(fidologfile);
}
/*****************************************************************************/
......
......@@ -120,8 +120,8 @@ static int lprintf(char *fmt, ...)
#endif
va_start(argptr,fmt);
if(vsnprintf(sbuf,sizeof(sbuf),fmt,argptr)<0)
sbuf[sizeof(sbuf)-1]=0;
vsnprintf(sbuf,sizeof(sbuf),fmt,argptr);
sbuf[sizeof(sbuf)-1]=0;
va_end(argptr);
return(startup->lputs(sbuf));
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment