avoid possible buffer overrun
This commit is contained in:
parent
272c80e349
commit
bd26fba38c
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: acksend.c,v 1.7 2002/07/06 22:08:30 wiz Exp $ */
|
||||
/* $NetBSD: acksend.c,v 1.8 2003/05/16 18:28:18 itojun Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1985, 1993 The Regents of the University of California.
|
||||
@ -38,7 +38,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)acksend.c 8.1 (Berkeley) 6/6/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: acksend.c,v 1.7 2002/07/06 22:08:30 wiz Exp $");
|
||||
__RCSID("$NetBSD: acksend.c,v 1.8 2003/05/16 18:28:18 itojun Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -57,7 +57,7 @@ xmit(int type, u_short seq, struct sockaddr_in *addr)
|
||||
msg.tsp_type = type;
|
||||
msg.tsp_seq = seq;
|
||||
msg.tsp_vers = TSPVERSION;
|
||||
(void)strcpy(msg.tsp_name, hostname);
|
||||
(void)strlcpy(msg.tsp_name, hostname, sizeof(msg.tsp_name));
|
||||
bytenetorder(&msg);
|
||||
if (sendto(sock, (char *)&msg, sizeof(struct tsp), 0,
|
||||
(struct sockaddr*)addr, sizeof(struct sockaddr)) < 0) {
|
||||
|
@ -36,7 +36,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)candidate.c 8.1 (Berkeley) 6/6/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: candidate.c,v 1.8 2002/07/06 22:08:31 wiz Exp $");
|
||||
__RCSID("$NetBSD: candidate.c,v 1.9 2003/05/16 18:28:18 itojun Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -80,7 +80,7 @@ again:
|
||||
fprintf(fd, "This machine is a candidate time master\n");
|
||||
msg.tsp_type = TSP_ELECTION;
|
||||
msg.tsp_vers = TSPVERSION;
|
||||
(void)strcpy(msg.tsp_name, hostname);
|
||||
(void)strlcpy(msg.tsp_name, hostname, sizeof(msg.tsp_name));
|
||||
bytenetorder(&msg);
|
||||
if (sendto(sock, (char *)&msg, sizeof(struct tsp), 0,
|
||||
(struct sockaddr*)&net->dest_addr,
|
||||
@ -139,7 +139,8 @@ again:
|
||||
/* no master for another round */
|
||||
htp = addmach(resp->tsp_name,&from,fromnet);
|
||||
msg.tsp_type = TSP_REFUSE;
|
||||
(void)strcpy(msg.tsp_name, hostname);
|
||||
(void)strlcpy(msg.tsp_name, hostname,
|
||||
sizeof(msg.tsp_name));
|
||||
answer = acksend(&msg, &htp->addr, htp->name,
|
||||
TSP_ACK, 0, htp->noanswer);
|
||||
if (!answer) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: correct.c,v 1.9 2001/09/02 00:13:06 reinoud Exp $ */
|
||||
/* $NetBSD: correct.c,v 1.10 2003/05/16 18:28:18 itojun Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1985, 1993 The Regents of the University of California.
|
||||
@ -38,7 +38,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)correct.c 8.1 (Berkeley) 6/6/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: correct.c,v 1.9 2001/09/02 00:13:06 reinoud Exp $");
|
||||
__RCSID("$NetBSD: correct.c,v 1.10 2003/05/16 18:28:18 itojun Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -89,7 +89,8 @@ correct(long avdelta)
|
||||
to.tsp_time.tv_usec = tmptv.tv_usec;
|
||||
to.tsp_type = TSP_ADJTIME;
|
||||
}
|
||||
(void)strcpy(to.tsp_name, hostname);
|
||||
(void)strlcpy(to.tsp_name, hostname,
|
||||
sizeof(to.tsp_name));
|
||||
answer = acksend(&to, &htp->addr, htp->name,
|
||||
TSP_ACK, 0, 0);
|
||||
if (!answer) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: master.c,v 1.11 2002/08/02 02:13:46 christos Exp $ */
|
||||
/* $NetBSD: master.c,v 1.12 2003/05/16 18:28:18 itojun Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1985, 1993 The Regents of the University of California.
|
||||
@ -38,7 +38,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)master.c 8.1 (Berkeley) 6/6/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: master.c,v 1.11 2002/08/02 02:13:46 christos Exp $");
|
||||
__RCSID("$NetBSD: master.c,v 1.12 2003/05/16 18:28:18 itojun Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -149,7 +149,8 @@ loop:
|
||||
to.tsp_vers = TSPVERSION;
|
||||
to.tsp_seq = sequence++;
|
||||
to.tsp_hopcnt = MAX_HOPCNT;
|
||||
(void)strcpy(to.tsp_name, hostname);
|
||||
(void)strlcpy(to.tsp_name, hostname,
|
||||
sizeof(to.tsp_name));
|
||||
bytenetorder(&to);
|
||||
if (sendto(sock, (char *)&to,
|
||||
sizeof(struct tsp), 0,
|
||||
@ -176,7 +177,7 @@ loop:
|
||||
* XXX check to see it is from ourself
|
||||
*/
|
||||
tmpt = msg->tsp_time.tv_sec;
|
||||
(void)strcpy(newdate, ctime(&tmpt));
|
||||
(void)strlcpy(newdate, ctime(&tmpt), sizeof(newdate));
|
||||
if (!good_host_name(msg->tsp_name)) {
|
||||
syslog(LOG_NOTICE,
|
||||
"attempted date change by %s to %s",
|
||||
@ -194,7 +195,7 @@ loop:
|
||||
if (!fromnet || fromnet->status != MASTER)
|
||||
break;
|
||||
tmpt = msg->tsp_time.tv_sec;
|
||||
(void)strcpy(newdate, ctime(&tmpt));
|
||||
(void)strlcpy(newdate, ctime(&tmpt), sizeof(newdate));
|
||||
|
||||
htp = findhost(msg->tsp_name);
|
||||
if (htp == 0) {
|
||||
@ -242,9 +243,10 @@ loop:
|
||||
(void)addmach(msg->tsp_name, &from,fromnet);
|
||||
}
|
||||
taddr = from;
|
||||
(void)strcpy(tname, msg->tsp_name);
|
||||
(void)strlcpy(tname, msg->tsp_name, sizeof(tname));
|
||||
to.tsp_type = TSP_QUIT;
|
||||
(void)strcpy(to.tsp_name, hostname);
|
||||
(void)strlcpy(to.tsp_name, hostname,
|
||||
sizeof(to.tsp_name));
|
||||
answer = acksend(&to, &taddr, tname,
|
||||
TSP_ACK, 0, 1);
|
||||
if (answer == NULL) {
|
||||
@ -261,7 +263,8 @@ loop:
|
||||
*/
|
||||
if (!fromnet || fromnet->status != MASTER)
|
||||
break;
|
||||
(void)strcpy(to.tsp_name, hostname);
|
||||
(void)strlcpy(to.tsp_name, hostname,
|
||||
sizeof(to.tsp_name));
|
||||
|
||||
/* The other master often gets into the same state,
|
||||
* with boring results if we stay at it forever.
|
||||
@ -269,7 +272,7 @@ loop:
|
||||
ntp = fromnet; /* (acksend() can leave fromnet=0 */
|
||||
for (i = 0; i < 3; i++) {
|
||||
to.tsp_type = TSP_RESOLVE;
|
||||
(void)strcpy(to.tsp_name, hostname);
|
||||
(void)strlcpy(to.tsp_name, hostname, sizeof(to.tsp_name));
|
||||
answer = acksend(&to, &ntp->dest_addr,
|
||||
ANYADDR, TSP_MASTERACK,
|
||||
ntp, 0);
|
||||
@ -314,7 +317,8 @@ loop:
|
||||
*/
|
||||
htp = addmach(msg->tsp_name, &from,fromnet);
|
||||
to.tsp_type = TSP_QUIT;
|
||||
(void)strcpy(to.tsp_name, hostname);
|
||||
(void)strlcpy(to.tsp_name, hostname,
|
||||
sizeof(to.tsp_name));
|
||||
answer = acksend(&to, &htp->addr, htp->name,
|
||||
TSP_ACK, 0, 1);
|
||||
if (!answer) {
|
||||
@ -357,11 +361,11 @@ mchgdate(struct tsp *msg)
|
||||
char olddate[32];
|
||||
struct timeval otime, ntime, tmptv;
|
||||
|
||||
(void)strcpy(tname, msg->tsp_name);
|
||||
(void)strlcpy(tname, msg->tsp_name, sizeof(tname));
|
||||
|
||||
xmit(TSP_DATEACK, msg->tsp_seq, &from);
|
||||
|
||||
(void)strcpy(olddate, date());
|
||||
(void)strlcpy(olddate, date(), sizeof(olddate));
|
||||
|
||||
/* adjust time for residence on the queue */
|
||||
(void)gettimeofday(&otime, 0);
|
||||
@ -478,7 +482,7 @@ spreadtime(void)
|
||||
dictate = 2;
|
||||
for (htp = self.l_fwd; htp != &self; htp = htp->l_fwd) {
|
||||
to.tsp_type = TSP_SETTIME;
|
||||
(void)strcpy(to.tsp_name, hostname);
|
||||
(void)strlcpy(to.tsp_name, hostname, sizeof(to.tsp_name));
|
||||
(void)gettimeofday(&tmptv, 0);
|
||||
to.tsp_time.tv_sec = tmptv.tv_sec;
|
||||
to.tsp_time.tv_usec = tmptv.tv_usec;
|
||||
@ -757,7 +761,7 @@ newslave(struct tsp *msg)
|
||||
if (now.tv_sec >= fromnet->slvwait.tv_sec+3
|
||||
|| now.tv_sec < fromnet->slvwait.tv_sec) {
|
||||
to.tsp_type = TSP_SETTIME;
|
||||
(void)strcpy(to.tsp_name, hostname);
|
||||
(void)strlcpy(to.tsp_name, hostname, sizeof(to.tsp_name));
|
||||
(void)gettimeofday(&tmptv, 0);
|
||||
to.tsp_time.tv_sec = tmptv.tv_sec;
|
||||
to.tsp_time.tv_usec = tmptv.tv_usec;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: readmsg.c,v 1.13 2002/09/19 00:01:33 mycroft Exp $ */
|
||||
/* $NetBSD: readmsg.c,v 1.14 2003/05/16 18:28:18 itojun Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1985, 1993 The Regents of the University of California.
|
||||
@ -38,7 +38,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)readmsg.c 8.1 (Berkeley) 6/6/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: readmsg.c,v 1.13 2002/09/19 00:01:33 mycroft Exp $");
|
||||
__RCSID("$NetBSD: readmsg.c,v 1.14 2003/05/16 18:28:18 itojun Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -408,7 +408,7 @@ masterack(void)
|
||||
|
||||
resp = msgin;
|
||||
resp.tsp_vers = TSPVERSION;
|
||||
(void)strcpy(resp.tsp_name, hostname);
|
||||
(void)strlcpy(resp.tsp_name, hostname, sizeof(resp.tsp_name));
|
||||
|
||||
switch(msgin.tsp_type) {
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: slave.c,v 1.12 2002/09/19 00:01:33 mycroft Exp $ */
|
||||
/* $NetBSD: slave.c,v 1.13 2003/05/16 18:28:18 itojun Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1985, 1993 The Regents of the University of California.
|
||||
@ -38,7 +38,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)slave.c 8.1 (Berkeley) 6/6/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: slave.c,v 1.12 2002/09/19 00:01:33 mycroft Exp $");
|
||||
__RCSID("$NetBSD: slave.c,v 1.13 2003/05/16 18:28:18 itojun Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -151,7 +151,7 @@ loop:
|
||||
to.tsp_vers = TSPVERSION;
|
||||
to.tsp_seq = sequence++;
|
||||
to.tsp_hopcnt = MAX_HOPCNT;
|
||||
(void)strcpy(to.tsp_name, hostname);
|
||||
(void)strlcpy(to.tsp_name, hostname, sizeof(to.tsp_name));
|
||||
bytenetorder(&to);
|
||||
if (sendto(sock, (char *)&to, sizeof(struct tsp), 0,
|
||||
(struct sockaddr*)&ntp->dest_addr,
|
||||
@ -262,9 +262,9 @@ loop:
|
||||
* the following line is necessary due to syslog
|
||||
* calling ctime() which clobbers the static buffer
|
||||
*/
|
||||
(void)strcpy(olddate, date());
|
||||
(void)strlcpy(olddate, date(), sizeof(olddate));
|
||||
tmpt = msg->tsp_time.tv_sec;
|
||||
(void)strcpy(newdate, ctime(&tmpt));
|
||||
(void)strlcpy(newdate, ctime(&tmpt), sizeof(newdate));
|
||||
|
||||
if (!good_host_name(msg->tsp_name)) {
|
||||
syslog(LOG_NOTICE,
|
||||
@ -347,7 +347,7 @@ loop:
|
||||
|
||||
case TSP_SETDATE:
|
||||
tmpt = msg->tsp_time.tv_sec;
|
||||
(void)strcpy(newdate, ctime(&tmpt));
|
||||
(void)strlcpy(newdate, ctime(&tmpt), sizeof(newdate));
|
||||
schgdate(msg, newdate);
|
||||
break;
|
||||
|
||||
@ -355,7 +355,7 @@ loop:
|
||||
if (fromnet->status != MASTER)
|
||||
break;
|
||||
tmpt = msg->tsp_time.tv_sec;
|
||||
(void)strcpy(newdate, ctime(&tmpt));
|
||||
(void)strlcpy(newdate, ctime(&tmpt), sizeof(newdate));
|
||||
htp = findhost(msg->tsp_name);
|
||||
if (0 == htp) {
|
||||
syslog(LOG_WARNING,
|
||||
@ -408,8 +408,10 @@ loop:
|
||||
refusetime = ntime.tv_sec + 30;
|
||||
}
|
||||
taddr = from;
|
||||
(void)strcpy(tname, msg->tsp_name);
|
||||
(void)strcpy(to.tsp_name, hostname);
|
||||
(void)strlcpy(tname, msg->tsp_name,
|
||||
sizeof(tname));
|
||||
(void)strlcpy(to.tsp_name, hostname,
|
||||
sizeof(to.tsp_name));
|
||||
answerdelay();
|
||||
if (!acksend(&to, &taddr, tname,
|
||||
TSP_ACK, 0, 0))
|
||||
@ -420,7 +422,8 @@ loop:
|
||||
} else { /* fromnet->status == MASTER */
|
||||
htp = addmach(msg->tsp_name, &from,fromnet);
|
||||
to.tsp_type = TSP_QUIT;
|
||||
(void)strcpy(to.tsp_name, hostname);
|
||||
(void)strlcpy(to.tsp_name, hostname,
|
||||
sizeof(to.tsp_name));
|
||||
if (!acksend(&to, &htp->addr, htp->name,
|
||||
TSP_ACK, 0, htp->noanswer)) {
|
||||
syslog(LOG_ERR,
|
||||
@ -439,7 +442,7 @@ loop:
|
||||
* more than one master: the first slave to
|
||||
* come up will notify here the situation.
|
||||
*/
|
||||
(void)strcpy(to.tsp_name, hostname);
|
||||
(void)strlcpy(to.tsp_name, hostname, sizeof(to.tsp_name));
|
||||
|
||||
/* The other master often gets into the same state,
|
||||
* with boring results.
|
||||
@ -473,7 +476,7 @@ loop:
|
||||
to.tsp_type = TSP_MSITEREQ;
|
||||
to.tsp_vers = TSPVERSION;
|
||||
to.tsp_seq = 0;
|
||||
(void)strcpy(to.tsp_name, hostname);
|
||||
(void)strlcpy(to.tsp_name, hostname, sizeof(to.tsp_name));
|
||||
answer = acksend(&to, &slavenet->dest_addr,
|
||||
ANYADDR, TSP_ACK,
|
||||
slavenet, 0);
|
||||
@ -481,7 +484,8 @@ loop:
|
||||
&& good_host_name(answer->tsp_name)) {
|
||||
setmaster(answer);
|
||||
to.tsp_type = TSP_ACK;
|
||||
(void)strcpy(to.tsp_name, answer->tsp_name);
|
||||
(void)strlcpy(to.tsp_name, answer->tsp_name,
|
||||
sizeof(to.tsp_name));
|
||||
bytenetorder(&to);
|
||||
if (sendto(sock, (char *)&to,
|
||||
sizeof(struct tsp), 0,
|
||||
@ -530,9 +534,11 @@ loop:
|
||||
if (answer == NULL)
|
||||
break;
|
||||
taddr = from;
|
||||
(void)strcpy(tname, answer->tsp_name);
|
||||
(void)strlcpy(tname, answer->tsp_name,
|
||||
sizeof(tname));
|
||||
to.tsp_type = TSP_QUIT;
|
||||
(void)strcpy(to.tsp_name, hostname);
|
||||
(void)strlcpy(to.tsp_name, hostname,
|
||||
sizeof(to.tsp_name));
|
||||
if (!acksend(&to, &taddr, tname,
|
||||
TSP_ACK, 0, 1)) {
|
||||
syslog(LOG_ERR,
|
||||
@ -585,7 +591,8 @@ loop:
|
||||
htp = addmach(answer->tsp_name,
|
||||
&from,ntp);
|
||||
to.tsp_type = TSP_QUIT;
|
||||
(void)strcpy(to.tsp_name, hostname);
|
||||
(void)strlcpy(to.tsp_name, hostname,
|
||||
sizeof(to.tsp_name));
|
||||
if (!acksend(&to,&htp->addr,htp->name,
|
||||
TSP_ACK, 0, htp->noanswer)) {
|
||||
syslog(LOG_ERR,
|
||||
@ -620,7 +627,7 @@ setmaster(struct tsp *msg)
|
||||
&& (slavenet != old_slavenet
|
||||
|| strcmp(msg->tsp_name, master_name)
|
||||
|| old_status != status)) {
|
||||
(void)strcpy(master_name, msg->tsp_name);
|
||||
(void)strlcpy(master_name, msg->tsp_name, sizeof(master_name));
|
||||
old_slavenet = slavenet;
|
||||
old_status = status;
|
||||
|
||||
@ -666,7 +673,7 @@ schgdate(struct tsp *msg, char *newdate)
|
||||
|
||||
to.tsp_type = TSP_SETDATEREQ;
|
||||
to.tsp_time = msg->tsp_time;
|
||||
(void)strcpy(to.tsp_name, hostname);
|
||||
(void)strlcpy(to.tsp_name, hostname, sizeof(to.tsp_name));
|
||||
if (!acksend(&to, &slavenet->dest_addr,
|
||||
ANYADDR, TSP_DATEACK,
|
||||
slavenet, 0))
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: timed.c,v 1.16 2002/07/10 22:44:23 wiz Exp $ */
|
||||
/* $NetBSD: timed.c,v 1.17 2003/05/16 18:28:18 itojun Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1985, 1993 The Regents of the University of California.
|
||||
@ -44,7 +44,7 @@ __COPYRIGHT(
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)timed.c 8.2 (Berkeley) 3/26/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: timed.c,v 1.16 2002/07/10 22:44:23 wiz Exp $");
|
||||
__RCSID("$NetBSD: timed.c,v 1.17 2003/05/16 18:28:18 itojun Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -487,7 +487,7 @@ suppress(struct sockaddr_in *addr, char *name, struct netinfo *net)
|
||||
if (trace)
|
||||
fprintf(fd, "suppress: %s\n", name);
|
||||
tgt = *addr;
|
||||
(void)strcpy(tname, name);
|
||||
(void)strlcpy(tname, name, sizeof(tname));
|
||||
|
||||
while (0 != readmsg(TSP_ANY, ANYADDR, &wait, net)) {
|
||||
if (trace)
|
||||
@ -497,7 +497,7 @@ suppress(struct sockaddr_in *addr, char *name, struct netinfo *net)
|
||||
|
||||
syslog(LOG_NOTICE, "suppressing false master %s", tname);
|
||||
msg.tsp_type = TSP_QUIT;
|
||||
(void)strcpy(msg.tsp_name, hostname);
|
||||
(void)strlcpy(msg.tsp_name, hostname, sizeof(msg.tsp_name));
|
||||
(void)acksend(&msg, &tgt, tname, TSP_ACK, 0, 1);
|
||||
}
|
||||
|
||||
@ -514,7 +514,7 @@ lookformaster(struct netinfo *ntp)
|
||||
|
||||
/* look for master */
|
||||
resp.tsp_type = TSP_MASTERREQ;
|
||||
(void)strcpy(resp.tsp_name, hostname);
|
||||
(void)strlcpy(resp.tsp_name, hostname, sizeof(resp.tsp_name));
|
||||
answer = acksend(&resp, &ntp->dest_addr, ANYADDR,
|
||||
TSP_MASTERACK, ntp, 0);
|
||||
if (answer != 0 && !good_host_name(answer->tsp_name)) {
|
||||
@ -569,7 +569,7 @@ lookformaster(struct netinfo *ntp)
|
||||
}
|
||||
|
||||
ntp->status = SLAVE;
|
||||
(void)strcpy(mastername, answer->tsp_name);
|
||||
(void)strlcpy(mastername, answer->tsp_name, sizeof(mastername));
|
||||
masteraddr = from;
|
||||
|
||||
/*
|
||||
@ -587,7 +587,8 @@ lookformaster(struct netinfo *ntp)
|
||||
if (answer != NULL &&
|
||||
strcmp(answer->tsp_name, mastername) != 0) {
|
||||
conflict.tsp_type = TSP_CONFLICT;
|
||||
(void)strcpy(conflict.tsp_name, hostname);
|
||||
(void)strlcpy(conflict.tsp_name, hostname,
|
||||
sizeof(conflict.tsp_name));
|
||||
if (!acksend(&conflict, &masteraddr, mastername,
|
||||
TSP_ACK, 0, 0)) {
|
||||
syslog(LOG_ERR,
|
||||
|
Loading…
Reference in New Issue
Block a user