Secured sprintf with snprintf

This commit is contained in:
Michiel Broek 2005-08-28 13:45:26 +00:00
parent e04af3ed02
commit 581cdc9c7f
19 changed files with 56 additions and 56 deletions

View File

@ -486,7 +486,7 @@ SM_STATE(WaitAddr)
history.aka.net = remote->addr->net;
history.aka.node = remote->addr->node;
history.aka.point = remote->addr->point;
snprintf(history.aka.domain, 12, "%s", printable(remote->addr->domain, 0));
snprintf(history.aka.domain, 13, "%s", printable(remote->addr->domain, 0));
SM_PROCEED(SendPasswd)
} else if (bp.rxbuf[0] == MM_BSY) {
@ -787,7 +787,7 @@ SM_STATE(WaitAddr)
history.aka.net = remote->addr->net;
history.aka.node = remote->addr->node;
history.aka.point = remote->addr->point;
snprintf(history.aka.domain, 12, "%s", printable(remote->addr->domain, 0));
snprintf(history.aka.domain, 13, "%s", printable(remote->addr->domain, 0));
SM_PROCEED(IsPasswd)
@ -1113,11 +1113,11 @@ TrType binkp_receiver(void)
bp.rmode = CompNone;
if (strlen(bp.rxbuf) < 512) {
snprintf(bp.rname, 511, "%s", strtok(bp.rxbuf+1, " \n\r"));
snprintf(bp.rname, 512, "%s", strtok(bp.rxbuf+1, " \n\r"));
bp.rsize = atoi(strtok(NULL, " \n\r"));
bp.rtime = atoi(strtok(NULL, " \n\r"));
bp.roffs = atoi(strtok(NULL, " \n\r"));
snprintf(bp.ropts, 511, "%s", printable(strtok(NULL, " \n\r\0"), 0));
snprintf(bp.ropts, 512, "%s", printable(strtok(NULL, " \n\r\0"), 0));
if (strcmp((char *)"GZ", bp.ropts) == 0)
bp.rmode = CompGZ;
else if (strcmp((char *)"BZ2", bp.ropts) == 0)
@ -1871,7 +1871,7 @@ int binkp_send_command(int id, ...)
fmt = va_arg(args, char*);
if (fmt) {
vsnprintf(buf, 1023, fmt, args);
vsnprintf(buf, 1024, fmt, args);
sz = (strlen(buf) & 0x7fff);
} else {
buf[0]='\0';
@ -2272,11 +2272,11 @@ int binkp_process_messages(void)
Syslog('+', "Binkp: %s \"%s\"", bstate[tmpq->cmd], printable(tmpq->data, 0));
if (tmpq->cmd == MM_GET) {
rmode = CompNone;
snprintf(lname, 511, "%s", strtok(tmpq->data, " \n\r"));
snprintf(lname, 512, "%s", strtok(tmpq->data, " \n\r"));
lsize = atoi(strtok(NULL, " \n\r"));
ltime = atoi(strtok(NULL, " \n\r"));
loffs = atoi(strtok(NULL, " \n\r"));
snprintf(ropts, 511, "%s", strtok(NULL, " \n\r"));
snprintf(ropts, 512, "%s", strtok(NULL, " \n\r"));
Syslog('b', "Binkp: m_file options \"%s\"", ropts);
if (strcmp((char *)"GZ", ropts) == 0)
rmode = CompGZ;
@ -2371,7 +2371,7 @@ int binkp_process_messages(void)
}
}
} else if (tmpq->cmd == MM_GOT) {
snprintf(lname, 511, "%s", strtok(tmpq->data, " \n\r"));
snprintf(lname, 512, "%s", strtok(tmpq->data, " \n\r"));
lsize = atoi(strtok(NULL, " \n\r"));
ltime = atoi(strtok(NULL, " \n\r"));
Found = FALSE;
@ -2404,7 +2404,7 @@ int binkp_process_messages(void)
Syslog('+', "Binkp: unexpected M_GOT \"%s\"", tmpq->data); /* Ignore frame */
}
} else if (tmpq->cmd == MM_SKIP) {
snprintf(lname, 511, "%s", strtok(tmpq->data, " \n\r"));
snprintf(lname, 512, "%s", strtok(tmpq->data, " \n\r"));
lsize = atoi(strtok(NULL, " \n\r"));
ltime = atoi(strtok(NULL, " \n\r"));
Found = FALSE;

View File

@ -147,7 +147,7 @@ int call(faddr *addr)
history.aka.node = addr->node;
history.aka.point = addr->point;
if (addr->domain && strlen(addr->domain))
snprintf(history.aka.domain, 12, "%s", printable(addr->domain, 0));
snprintf(history.aka.domain, 13, "%s", printable(addr->domain, 0));
/*
* Extract the protocol from the URL.

View File

@ -102,12 +102,12 @@ int send_str(char *str, char *Phone)
case 'p': msleep(250); *q++ = '\\'; *q++ = 'p'; break;
case 'D': if (Phone) {
PUTSTR(Phone);
snprintf(q, 20, "%s", Phone);
snprintf(q, 21, "%s", Phone);
}
break;
case 'T': if (Phone) {
PUTSTR(tranphone(Phone));
snprintf(q, 20, "%s", tranphone(Phone));
snprintf(q, 21, "%s", tranphone(Phone));
}
break;
default: PUTCHAR(*p); *q++ = *p; break;

View File

@ -523,7 +523,7 @@ SM_STATE(senddata)
PUTCHAR('*');
PUTCHAR('*');
PUTSTR(p);
snprintf(trailer, 7, "%04X\r\021", crc16xmodem(p, strlen(p)));
snprintf(trailer, 8, "%04X\r\021", crc16xmodem(p, strlen(p)));
PUTSTR(trailer);
Syslog('i', "TXEMSI: send **%s%04X", p, crc16xmodem(p, strlen(p)));
free(p);

View File

@ -204,7 +204,7 @@ char *mkemsidat(int caller)
else
p=xstrcat(p,(char *)"}");
snprintf(cbuf,15,"{%X}",PRODCODE);
snprintf(cbuf,16,"{%X}",PRODCODE);
p=xstrcat(p,cbuf);
p=xstrcat(p,(char *)"{mbcico}{");
p=xstrcat(p,(char *)VERSION);
@ -220,7 +220,7 @@ char *mkemsidat(int caller)
p=xstrcat(p,phone?emsiencode(phone):(char *)"-Unpublished-");
p=xstrcat(p,(char *)"][");
if ((CFG.IP_Speed) && (emsi_local_protos & PROT_TCP))
snprintf(cbuf,15,"%ld",CFG.IP_Speed);
snprintf(cbuf,16,"%ld",CFG.IP_Speed);
else
strcpy(cbuf,"9600");
p=xstrcat(p,cbuf);
@ -228,13 +228,13 @@ char *mkemsidat(int caller)
p=xstrcat(p,flags?emsiencode(flags):(char *)"");
p=xstrcat(p,(char *)"]}{TRX#}{[");
tt = time(NULL);
snprintf(cbuf,15,"%08lX", (unsigned long)mtime2sl(tt));
snprintf(cbuf,16,"%08lX", (unsigned long)mtime2sl(tt));
p=xstrcat(p,cbuf);
p=xstrcat(p,(char *)"]}{TZUTC}{[");
p=xstrcat(p,gmtoffset(tt));
p=xstrcat(p,(char *)"]}");
snprintf(cbuf,15,"%04X",(unsigned int)strlen(p+12));
snprintf(cbuf,16,"%04X",(unsigned int)strlen(p+12));
memcpy(p+8,cbuf,4);
emsiencode(NULL); /* Free memory */
return p;
@ -396,7 +396,7 @@ int scanemsidat(char *buf)
history.aka.net = remote->addr->net;
history.aka.node = remote->addr->node;
history.aka.point = remote->addr->point;
snprintf(history.aka.domain, 12, "%s", printable(remote->addr->domain, 0));
snprintf(history.aka.domain, 13, "%s", printable(remote->addr->domain, 0));
}
if (emsi_remote_password)

View File

@ -53,7 +53,7 @@ static char *tmpkname(void)
{
static char buf[16];
snprintf(buf,15,"%08lx.pkt", sequencer());
snprintf(buf,16,"%08lx.pkt", sequencer());
return buf;
}
@ -360,7 +360,7 @@ file_list *create_filelist(fa_list *al, char *fl, int create)
*/
nm = reqname(tmpa->addr);
if ((nm != NULL) && (stat(nm, &stbuf) == 0)) {
snprintf(tmpreq, 12, "%04X%04X.REQ", tmpa->addr->net, tmpa->addr->node);
snprintf(tmpreq, 13, "%04X%04X.REQ", tmpa->addr->net, tmpa->addr->node);
add_list(&st, nm, tmpreq, DSF, 0L, NULL, 1);
made_request = 1;
}
@ -515,7 +515,7 @@ file_list *create_freqlist(fa_list *al)
for (tmpa = al; tmpa; tmpa = tmpa->next) {
nm = reqname(tmpa->addr);
if ((nm != NULL) && (stat(nm, &stbuf) == 0)) {
snprintf(tmpreq, 12, "%04X%04X.REQ", tmpa->addr->net, tmpa->addr->node);
snprintf(tmpreq, 13, "%04X%04X.REQ", tmpa->addr->net, tmpa->addr->node);
add_list(&st, nm, tmpreq, DSF, 0L, NULL, 1);
made_request = 1;
}
@ -668,10 +668,10 @@ char *transfertime(struct timeval start, struct timeval end, long bytes, int sen
if (!elapsed)
elapsed = 1L;
if (bytes > 1000000)
snprintf(resp, 80, "%ld bytes %s in %0.3Lf seconds (%0.3Lf Kb/s)",
snprintf(resp, 81, "%ld bytes %s in %0.3Lf seconds (%0.3Lf Kb/s)",
bytes, sent?"sent":"received", elapsed / 1000.000, ((bytes / elapsed) * 1000) / 1024);
else
snprintf(resp, 80, "%ld bytes %s in %0.3Lf seconds (%0.3Lf Kb/s)",
snprintf(resp, 81, "%ld bytes %s in %0.3Lf seconds (%0.3Lf Kb/s)",
bytes, sent?"sent":"received", elapsed / 1000.000, ((bytes * 1000) / elapsed) / 1024);
return resp;
}
@ -682,7 +682,7 @@ char *compress_stat(long original, long saved)
{
static char resp[81];
snprintf(resp, 80, "compressed %ld bytes, compression %0.1f%%", saved, ((saved * 100.0) / original));
snprintf(resp, 81, "compressed %ld bytes, compression %0.1f%%", saved, ((saved * 100.0) / original));
return resp;
}

View File

@ -368,7 +368,7 @@ SM_START(recv_packet)
SM_STATE(recv_packet)
snprintf(recvpktname,15, "%08lx.pkt",(unsigned long)sequencer());
snprintf(recvpktname,16, "%08lx.pkt",(unsigned long)sequencer());
if ((rc = xmrecv(recvpktname)) == 1) {
SM_SUCCESS;
} else if (rc == 0) {
@ -443,7 +443,7 @@ SM_STATE(scan_packet)
history.aka.node = remote->addr->node;
history.aka.point = remote->addr->point;
if (remote->addr->domain && strlen(remote->addr->domain))
snprintf(history.aka.domain, 12, "%s", printable(remote->addr->domain, 0));
snprintf(history.aka.domain, 13, "%s", printable(remote->addr->domain, 0));
if (((nlent=getnlent(remote->addr))) && (nlent->pflag != NL_DUMMY)) {
Syslog('+', "remote is a listed system");
@ -452,8 +452,8 @@ SM_STATE(scan_packet)
strncpy(history.sysop, nlent->sysop, 35);
UserCity(mypid, nlent->sysop, nlent->location);
} else {
snprintf(history.system_name, 35, "Unknown");
snprintf(history.location, 35, "Somewhere");
snprintf(history.system_name, 36, "Unknown");
snprintf(history.location, 36, "Somewhere");
}
if (nlent)

View File

@ -765,7 +765,7 @@ int hydra_batch(int role, file_list *to_send)
outbuf = txbuf;
/* Application ID string */
outbuf += snprintf(outbuf, H_ZIPBUFLEN -1, "%08lx%s,%s", H_REVSTAMP, "mbcico", VERSION) + 1;
outbuf += snprintf(outbuf, H_ZIPBUFLEN, "%08lx%s,%s", H_REVSTAMP, "mbcico", VERSION) + 1;
/* Supported options */
outbuf += put_flags(outbuf, HCAN_OPTIONS) + 1;
@ -776,7 +776,7 @@ int hydra_batch(int role, file_list *to_send)
Syslog('h', "Hydra: desired options : %08lx", HDEF_OPTIONS & HCAN_OPTIONS & ~HUNN_OPTIONS);
/* Desired transmitter and receiver window size */
outbuf += snprintf(outbuf, H_ZIPBUFLEN -1, "%08lx%08lx", H_TXWINDOW, H_RXWINDOW) + 1;
outbuf += snprintf(outbuf, H_ZIPBUFLEN, "%08lx%08lx", H_TXWINDOW, H_RXWINDOW) + 1;
/* Packet prefix string */
*outbuf++ = 0;
@ -901,7 +901,7 @@ int hydra_batch(int role, file_list *to_send)
break;
} else {
if (to_send) {
txlen = snprintf(txbuf, H_ZIPBUFLEN -1, "%08lx%08lx%08lx%08lx%08lx",
txlen = snprintf(txbuf, H_ZIPBUFLEN, "%08lx%08lx%08lx%08lx%08lx",
(long)mtime2sl(txstat.st_mtime+(txstat.st_mtime%2)),
(long)(txstat.st_size), 0UL, 0UL, 0UL);

View File

@ -66,7 +66,7 @@ char *date(time_t t)
else
now = time(NULL);
ptm=*localtime(&now);
snprintf(buf, 19, "%s %02d %02d:%02d:%02d", mon[ptm.tm_mon],ptm.tm_mday,ptm.tm_hour,ptm.tm_min,ptm.tm_sec);
snprintf(buf, 20, "%s %02d %02d:%02d:%02d", mon[ptm.tm_mon],ptm.tm_mday,ptm.tm_hour,ptm.tm_min,ptm.tm_sec);
return(buf);
}
@ -76,7 +76,7 @@ int IsZMH()
{
static char buf[81];
snprintf(buf, 80, "SBBS:0;");
snprintf(buf, 81, "SBBS:0;");
if (socket_send(buf) == 0) {
strncpy(buf, socket_receive(), 80);
if (strncmp(buf, "100:2,2", 7) == 0)

View File

@ -67,19 +67,19 @@ int nlinfo(faddr *addr)
*/
for (tmpf = &nl_online; *tmpf; tmpf = &((*tmpf)->next))
if ((nlent->oflags & (*tmpf)->value) == (*tmpf)->value)
snprintf(flagbuf + strlen(flagbuf), 255 - strlen(flagbuf), "%s,", (*tmpf)->name);
snprintf(flagbuf + strlen(flagbuf), 256 - strlen(flagbuf), "%s,", (*tmpf)->name);
for (tmpf = &nl_request; *tmpf; tmpf = &((*tmpf)->next))
if (nlent->xflags == (*tmpf)->value)
snprintf(flagbuf + strlen(flagbuf), 255 - strlen(flagbuf), "%s,", (*tmpf)->name);
snprintf(flagbuf + strlen(flagbuf), 256 - strlen(flagbuf), "%s,", (*tmpf)->name);
for (tmpm = &nl_pots; *tmpm; tmpm=&((*tmpm)->next))
if ((nlent->mflags & (*tmpm)->mask) == (*tmpm)->mask)
snprintf(flagbuf + strlen(flagbuf), 255 - strlen(flagbuf), "%s,", (*tmpm)->name);
snprintf(flagbuf + strlen(flagbuf), 256 - strlen(flagbuf), "%s,", (*tmpm)->name);
for (tmpm = &nl_isdn; *tmpm; tmpm=&((*tmpm)->next))
if ((nlent->dflags & (*tmpm)->mask) == (*tmpm)->mask)
snprintf(flagbuf + strlen(flagbuf), 255 - strlen(flagbuf), "%s,", (*tmpm)->name);
snprintf(flagbuf + strlen(flagbuf), 256 - strlen(flagbuf), "%s,", (*tmpm)->name);
for (tmpm = &nl_tcpip; *tmpm; tmpm=&((*tmpm)->next))
if ((nlent->iflags & (*tmpm)->mask) == (*tmpm)->mask)
snprintf(flagbuf + strlen(flagbuf), 255 - strlen(flagbuf), "%s,", (*tmpm)->name);
snprintf(flagbuf + strlen(flagbuf), 256 - strlen(flagbuf), "%s,", (*tmpm)->name);
flagbuf[strlen(flagbuf)-1] = '\0';
printf("Flags : %s\n", flagbuf);
@ -88,7 +88,7 @@ int nlinfo(faddr *addr)
*/
flagbuf[0] = 0;
for (i = 0; nlent->uflags[i]; i++) {
snprintf(flagbuf + strlen(flagbuf), 255 - strlen(flagbuf), "%s,", nlent->uflags[i]);
snprintf(flagbuf + strlen(flagbuf), 256 - strlen(flagbuf), "%s,", nlent->uflags[i]);
}
if (strlen(flagbuf)) {
flagbuf[strlen(flagbuf) - 1] = 0;

View File

@ -64,7 +64,7 @@ FILE *openfile(char *fname, time_t remtime, off_t remsize, off_t *resofs, int(*r
Syslog('s', "openfile(\"%s\",%s,%lu,...)", MBSE_SS(fname), MBSE_SS(ctt), (unsigned long)remsize);
if ((fname == NULL) || (fname[0] == '\0')) {
snprintf(tmpfname,15,"%08lx.pkt",(unsigned long)sequencer());
snprintf(tmpfname,16,"%08lx.pkt",(unsigned long)sequencer());
fname=tmpfname;
}
@ -141,7 +141,7 @@ FILE *openfile(char *fname, time_t remtime, off_t remsize, off_t *resofs, int(*r
rc = 1;
p = strrchr(infpath,'/');
*p = '\0';
snprintf(ctt,31,"%08lx.doe",(unsigned long)sequencer());
snprintf(ctt,32,"%08lx.doe",(unsigned long)sequencer());
free(infpath);
infpath = xstrcpy(p);
infpath = xstrcat(infpath, ctt);

View File

@ -443,7 +443,7 @@ int IsZMH()
{
static char buf[81];
snprintf(buf, 80, "SBBS:0;");
snprintf(buf, 81, "SBBS:0;");
if (socket_send(buf) == 0) {
strncpy(buf, socket_receive(), 80);
if (strncmp(buf, "100:2,2", 7) == 0)

View File

@ -523,7 +523,7 @@ file_list *respmagic(char *cmd) /* must free(cmd) before exit */
}
fwrite(&zeroes, 1, 3, fp);
fclose(fp);
snprintf(remname, 31, "%08lX.PKT", (unsigned long)sequencer());
snprintf(remname, 32, "%08lX.PKT", (unsigned long)sequencer());
add_list(&fl, tmptx, remname, KFS, 0L, NULL, 0);
fmsg.from->name = svname;
@ -622,7 +622,7 @@ static void attach_report(file_list **fl)
fwrite(report_text, 1, strlen(report_text), fp);
fwrite(&zeroes, 1, 3, fp);
fclose(fp);
snprintf(remname, 13, "%08lX.PKT", (unsigned long)sequencer());
snprintf(remname, 14, "%08lX.PKT", (unsigned long)sequencer());
add_list(fl, tmpfn, remname, KFS, 0L, NULL, 0);
fmsg.from->name = svname;
} else {
@ -643,13 +643,13 @@ static void add_report(char *format, ...)
char buf[1024];
if (report_text == NULL) {
snprintf(buf, 1023,
snprintf(buf, 1024,
" Status of file request\r\
======================\r\r\
Received By: %s\r\
",
ascfnode(bestaka_s(remote->addr),0x1f));
snprintf(buf+strlen(buf), 1023 - strlen(buf),
snprintf(buf+strlen(buf), 1024 - strlen(buf),
" From: %s\r\
On: %s\r\r\
",
@ -659,7 +659,7 @@ static void add_report(char *format, ...)
}
va_start(va_ptr, format);
vsnprintf(buf, 1023, format, va_ptr);
vsnprintf(buf, 1024, format, va_ptr);
va_end(va_ptr);
strcat(buf,"\r");
report_text = xstrcat(report_text,buf);

View File

@ -210,7 +210,7 @@ int scanout(int (*fn)(faddr *, char, int, char *))
*/
if (fidonet.zone[j]) {
if (j) {
snprintf(fext, 4, ".%03x", fidonet.zone[j]);
snprintf(fext, 5, ".%03x", fidonet.zone[j]);
p = xstrcat(p, fext);
}
Syslog('o', "Zone %d Dir %s", fidonet.zone[j], p);

View File

@ -123,7 +123,7 @@ SM_EDECL
unsigned short crc;
int c, count = 0;
snprintf(buf,255,"%s %s %s",nm,dt,pw);
snprintf(buf,256,"%s %s %s",nm,dt,pw);
crc = crc16xmodem(buf, strlen(buf));
Syslog('s', "sending bark packet \"%s\", crc = 0x%04x", buf, crc);

View File

@ -222,7 +222,7 @@ static int sendtfile(char *ln, char *rn)
return 0;
}
snprintf(txbuf,TCP_BLKSIZE -1, "S %s %lu %lu",rn,(unsigned long)st.st_size,(unsigned long)st.st_mtime+(st.st_mtime%2));
snprintf(txbuf,TCP_BLKSIZE, "S %s %lu %lu",rn,(unsigned long)st.st_size,(unsigned long)st.st_mtime+(st.st_mtime%2));
bufl = strlen(txbuf);
rc = tcp_sblk(txbuf, bufl, TCP_CMD);
rc = tcp_rblk(rxbuf, &bufl);
@ -274,7 +274,7 @@ static int sendtfile(char *ln, char *rn)
static int resync(off_t off)
{
snprintf(txbuf, TCP_BLKSIZE -1, "ROK %ld",(long)off);
snprintf(txbuf, TCP_BLKSIZE, "ROK %ld",(long)off);
return 0;
}

View File

@ -59,7 +59,7 @@ int lock(char *line)
else
p++;
mypid = getpid();
snprintf(tmpname,255,"%s%d",LCKTMP,mypid);
snprintf(tmpname,256,"%s%d",LCKTMP,mypid);
if ((f = fopen(tmpname,"w")) == NULL) {
WriteError("$ulock: can't create %s",tmpname);
return(-1);
@ -68,7 +68,7 @@ int lock(char *line)
fprintf(f,"%10d\n",mypid);
fclose(f);
chmod(tmpname,0444);
snprintf(lckname,255,"%s%s",LCKPREFIX,p);
snprintf(lckname,256,"%s%s",LCKPREFIX,p);
p=lckname+strlen(lckname)-1;
*p=tolower(*p);
@ -116,7 +116,7 @@ int ulock(char *line)
else
p++;
mypid=getpid();
snprintf(lckname,255,"%s%s",LCKPREFIX,p);
snprintf(lckname,256,"%s%s",LCKPREFIX,p);
p=lckname+strlen(lckname)-1;
*p=tolower(*p);

View File

@ -555,7 +555,7 @@ int resync(off_t resofs)
Syslog('x', "trying to resync at offset %ld",resofs);
sblk=resofs/XMBLKSIZ+1;
snprintf(resynbuf,15,"%ld",sblk);
snprintf(resynbuf,16,"%ld",sblk);
lcrc=crc16xmodem(resynbuf,strlen(resynbuf));
gotack=0;
gotnak=0;

View File

@ -213,7 +213,7 @@ static int sendzfile(char *ln, char *rn)
Syslog('+', "Zmodem: size %lu bytes, dated %s", (unsigned long)st.st_size, date(st.st_mtime));
gettimeofday(&starttime, &tz);
snprintf(txbuf,MAXBLOCK -1, "%s %lu %lo %o 0 0 0", rn,
snprintf(txbuf,MAXBLOCK, "%s %lu %lo %o 0 0 0", rn,
(unsigned long)st.st_size, (long)st.st_mtime+((long)st.st_mtime%2), st.st_mode);
bufl = strlen(txbuf);
*(strchr(txbuf,' ')) = '\0'; /*hope no blanks in filename*/