diff options
author | Michael Shalayeff <mickey@cvs.openbsd.org> | 2001-05-05 05:10:06 +0000 |
---|---|---|
committer | Michael Shalayeff <mickey@cvs.openbsd.org> | 2001-05-05 05:10:06 +0000 |
commit | e4af968b707ae073d6f7cf0bff61722959187823 (patch) | |
tree | 998c09a5a83e2dcf1ab96ac2669cebc597d02755 /usr.sbin | |
parent | ae94b2190e36ae46e23c787341cf331830b9839e (diff) |
use strlcpy vs strncpy+a[len-1]='\0', some trailing spaces; millert@ ok
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/timed/timed/acksend.c | 7 | ||||
-rw-r--r-- | usr.sbin/timed/timed/byteorder.c | 8 | ||||
-rw-r--r-- | usr.sbin/timed/timed/candidate.c | 13 | ||||
-rw-r--r-- | usr.sbin/timed/timed/correct.c | 8 | ||||
-rw-r--r-- | usr.sbin/timed/timed/globals.h | 8 | ||||
-rw-r--r-- | usr.sbin/timed/timed/master.c | 47 | ||||
-rw-r--r-- | usr.sbin/timed/timed/measure.c | 10 | ||||
-rw-r--r-- | usr.sbin/timed/timed/networkdelta.c | 6 | ||||
-rw-r--r-- | usr.sbin/timed/timed/readmsg.c | 14 | ||||
-rw-r--r-- | usr.sbin/timed/timed/slave.c | 69 | ||||
-rw-r--r-- | usr.sbin/timed/timed/timed.c | 22 |
11 files changed, 81 insertions, 131 deletions
diff --git a/usr.sbin/timed/timed/acksend.c b/usr.sbin/timed/timed/acksend.c index 88092321767..ea139893b69 100644 --- a/usr.sbin/timed/timed/acksend.c +++ b/usr.sbin/timed/timed/acksend.c @@ -1,4 +1,4 @@ -/* $OpenBSD: acksend.c,v 1.3 2001/04/07 20:00:15 ho Exp $ */ +/* $OpenBSD: acksend.c,v 1.4 2001/05/05 05:10:04 mickey Exp $ */ /*- * Copyright (c) 1985, 1993 The Regents of the University of California. @@ -38,7 +38,7 @@ static char sccsid[] = "@(#)acksend.c 5.1 (Berkeley) 5/11/93"; #endif /* not lint */ #ifdef sgi -#ident "$Revision: 1.3 $" +#ident "$Revision: 1.4 $" #endif #include "globals.h" @@ -58,8 +58,7 @@ xmit(int type, msg.tsp_type = type; msg.tsp_seq = seq; msg.tsp_vers = TSPVERSION; - (void)strncpy(msg.tsp_name, hostname, sizeof msg.tsp_name-1); - msg.tsp_name[sizeof msg.tsp_name-1] = '\0'; + 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) { diff --git a/usr.sbin/timed/timed/byteorder.c b/usr.sbin/timed/timed/byteorder.c index 5dc91f232d5..2d6692c1b8b 100644 --- a/usr.sbin/timed/timed/byteorder.c +++ b/usr.sbin/timed/timed/byteorder.c @@ -1,4 +1,4 @@ -/* $OpenBSD: byteorder.c,v 1.2 2001/04/07 20:00:15 ho Exp $ */ +/* $OpenBSD: byteorder.c,v 1.3 2001/05/05 05:10:04 mickey Exp $ */ /*- * Copyright (c) 1985, 1993 The Regents of the University of California. @@ -38,7 +38,7 @@ static char sccsid[] = "@(#)byteorder.c 5.1 (Berkeley) 5/11/93"; #endif /* not lint */ #ifdef sgi -#ident "$Revision: 1.2 $" +#ident "$Revision: 1.3 $" #endif #include "globals.h" @@ -60,7 +60,7 @@ bytenetorder(struct tsp *ptr) ptr->tsp_time.tv_sec = htonl((u_long)ptr->tsp_time.tv_sec); ptr->tsp_time.tv_usec = htonl((u_long)ptr->tsp_time.tv_usec); break; - + default: break; /* nothing more needed */ } @@ -79,7 +79,7 @@ bytehostorder(struct tsp *ptr) ptr->tsp_time.tv_sec = ntohl((u_long)ptr->tsp_time.tv_sec); ptr->tsp_time.tv_usec = ntohl((u_long)ptr->tsp_time.tv_usec); break; - + default: break; /* nothing more needed */ } diff --git a/usr.sbin/timed/timed/candidate.c b/usr.sbin/timed/timed/candidate.c index b5d2374837b..cfa09ad13dc 100644 --- a/usr.sbin/timed/timed/candidate.c +++ b/usr.sbin/timed/timed/candidate.c @@ -1,4 +1,4 @@ -/* $OpenBSD: candidate.c,v 1.3 2001/04/07 20:00:15 ho Exp $ */ +/* $OpenBSD: candidate.c,v 1.4 2001/05/05 05:10:04 mickey Exp $ */ /*- * Copyright (c) 1985, 1993 The Regents of the University of California. @@ -38,7 +38,7 @@ static char sccsid[] = "@(#)candidate.c 5.1 (Berkeley) 5/11/93"; #endif /* not lint */ #ifdef sgi -#ident "$Revision: 1.3 $" +#ident "$Revision: 1.4 $" #endif #include "globals.h" @@ -82,8 +82,7 @@ again: fprintf(fd, "This machine is a candidate time master\n"); msg.tsp_type = TSP_ELECTION; msg.tsp_vers = TSPVERSION; - (void)strncpy(msg.tsp_name, hostname, sizeof msg.tsp_name-1); - msg.tsp_name[sizeof msg.tsp_name-1] = '\0'; + 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, @@ -126,7 +125,7 @@ again: case TSP_REFUSE: /* * Collision: change value of election timer - * using exponential backoff. + * using exponential backoff. * * Fooey. * An exponential backoff on a delay starting at @@ -142,9 +141,7 @@ again: /* no master for another round */ htp = addmach(resp->tsp_name,&from,fromnet); msg.tsp_type = TSP_REFUSE; - (void)strncpy(msg.tsp_name, hostname, - sizeof msg.tsp_name-1); - msg.tsp_name[sizeof msg.tsp_name-1] = '\0'; + strlcpy(msg.tsp_name, hostname, sizeof msg.tsp_name); answer = acksend(&msg, &htp->addr, htp->name, TSP_ACK, 0, htp->noanswer); if (!answer) { diff --git a/usr.sbin/timed/timed/correct.c b/usr.sbin/timed/timed/correct.c index d8d70ade26c..cf8c66ef3c1 100644 --- a/usr.sbin/timed/timed/correct.c +++ b/usr.sbin/timed/timed/correct.c @@ -1,4 +1,4 @@ -/* $OpenBSD: correct.c,v 1.5 2001/04/07 20:00:15 ho Exp $ */ +/* $OpenBSD: correct.c,v 1.6 2001/05/05 05:10:04 mickey Exp $ */ /*- * Copyright (c) 1985, 1993 The Regents of the University of California. @@ -38,7 +38,7 @@ static char sccsid[] = "@(#)correct.c 5.1 (Berkeley) 5/11/93"; #endif /* not lint */ #ifdef sgi -#ident "$Revision: 1.5 $" +#ident "$Revision: 1.6 $" #endif #include "globals.h" @@ -91,9 +91,7 @@ correct(long avdelta) to.tsp_time.tv_usec = tmptv.tv_usec; to.tsp_type = TSP_ADJTIME; } - (void)strncpy(to.tsp_name, hostname, - sizeof to.tsp_name-1); - to.tsp_name[sizeof to.tsp_name-1] = '\0'; + strlcpy(to.tsp_name, hostname, sizeof to.tsp_name); answer = acksend(&to, &htp->addr, htp->name, TSP_ACK, 0, 0); if (!answer) { diff --git a/usr.sbin/timed/timed/globals.h b/usr.sbin/timed/timed/globals.h index 9a99cc9603f..9ee802d0324 100644 --- a/usr.sbin/timed/timed/globals.h +++ b/usr.sbin/timed/timed/globals.h @@ -1,4 +1,4 @@ -/* $OpenBSD: globals.h,v 1.2 2001/04/07 20:00:16 ho Exp $ */ +/* $OpenBSD: globals.h,v 1.3 2001/05/05 05:10:04 mickey Exp $ */ /*- * Copyright (c) 1985 The Regents of the University of California. @@ -36,7 +36,7 @@ */ #ifdef sgi -#ident "$Revision: 1.2 $" +#ident "$Revision: 1.3 $" #endif #include <sys/param.h> @@ -183,6 +183,6 @@ extern int nnets; /* nets I am connected to */ } -# define max(a,b) (a<b ? b : a) -# define min(a,b) (a>b ? b : a) +# define max(a,b) (a<b ? b : a) +# define min(a,b) (a>b ? b : a) # define abs(x) (x>=0 ? x : -(x)) diff --git a/usr.sbin/timed/timed/master.c b/usr.sbin/timed/timed/master.c index c2e364f307a..83320db1813 100644 --- a/usr.sbin/timed/timed/master.c +++ b/usr.sbin/timed/timed/master.c @@ -1,4 +1,4 @@ -/* $OpenBSD: master.c,v 1.5 2001/03/31 19:40:58 fgsch Exp $ */ +/* $OpenBSD: master.c,v 1.6 2001/05/05 05:10:04 mickey Exp $ */ /*- * Copyright (c) 1985, 1993 The Regents of the University of California. @@ -38,7 +38,7 @@ static char sccsid[] = "@(#)master.c 5.1 (Berkeley) 5/11/93"; #endif /* not lint */ #ifdef sgi -#ident "$Revision: 1.5 $" +#ident "$Revision: 1.6 $" #endif #include "globals.h" @@ -157,9 +157,8 @@ loop: to.tsp_vers = TSPVERSION; to.tsp_seq = sequence++; to.tsp_hopcnt = MAX_HOPCNT; - (void)strncpy(to.tsp_name, hostname, - sizeof to.tsp_name-1); - to.tsp_name[sizeof to.tsp_name-1] = '\0'; + strlcpy(to.tsp_name, hostname, + sizeof to.tsp_name); bytenetorder(&to); if (sendto(sock, (char *)&to, sizeof(struct tsp), 0, @@ -189,8 +188,7 @@ loop: (void)cftime(newdate, "%D %T", &msg->tsp_time.tv_sec); #else tmpt = msg->tsp_time.tv_sec; - (void)strncpy(newdate, ctime(&tmpt), sizeof newdate-1); - newdate[sizeof newdate-1] = '\0'; + strlcpy(newdate, ctime(&tmpt), sizeof newdate); #endif /* sgi */ if (!good_host_name(msg->tsp_name)) { syslog(LOG_NOTICE, @@ -212,8 +210,7 @@ loop: (void)cftime(newdate, "%D %T", &msg->tsp_time.tv_sec); #else tmpt = msg->tsp_time.tv_sec; - (void)strncpy(newdate, ctime(&tmpt), sizeof newdate-1); - newdate[sizeof newdate-1] = '\0'; + strlcpy(newdate, ctime(&tmpt), sizeof newdate); #endif /* sgi */ htp = findhost(msg->tsp_name); if (htp == 0) { @@ -261,12 +258,9 @@ loop: (void)addmach(msg->tsp_name, &from,fromnet); } taddr = from; - (void)strncpy(tname, msg->tsp_name, sizeof tname-1); - tname[sizeof tname-1] = '\0'; + strlcpy(tname, msg->tsp_name, sizeof tname); to.tsp_type = TSP_QUIT; - (void)strncpy(to.tsp_name, hostname, - sizeof to.tsp_name-1); - to.tsp_name[sizeof to.tsp_name-1] = '\0'; + strlcpy(to.tsp_name, hostname, sizeof to.tsp_name); answer = acksend(&to, &taddr, tname, TSP_ACK, 0, 1); if (answer == NULL) { @@ -283,9 +277,7 @@ loop: */ if (!fromnet || fromnet->status != MASTER) break; - (void)strncpy(to.tsp_name, hostname, - sizeof to.tsp_name-1); - to.tsp_name[sizeof to.tsp_name-1] = '\0'; + 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. @@ -293,9 +285,8 @@ loop: ntp = fromnet; /* (acksend() can leave fromnet=0 */ for (i = 0; i < 3; i++) { to.tsp_type = TSP_RESOLVE; - (void)strncpy(to.tsp_name, hostname, - sizeof to.tsp_name-1); - to.tsp_name[sizeof to.tsp_name-1] = '\0'; + strlcpy(to.tsp_name, hostname, + sizeof to.tsp_name); answer = acksend(&to, &ntp->dest_addr, ANYADDR, TSP_MASTERACK, ntp, 0); @@ -340,9 +331,7 @@ loop: */ htp = addmach(msg->tsp_name, &from,fromnet); to.tsp_type = TSP_QUIT; - (void)strncpy(to.tsp_name, hostname, - sizeof to.tsp_name-1); - to.tsp_name[sizeof to.tsp_name-1] = '\0'; + strlcpy(to.tsp_name, hostname, sizeof to.tsp_name); answer = acksend(&to, &htp->addr, htp->name, TSP_ACK, 0, 1); if (!answer) { @@ -385,13 +374,11 @@ mchgdate(struct tsp *msg) char olddate[32]; struct timeval otime, ntime, tmptv; - (void)strncpy(tname, msg->tsp_name, sizeof tname-1); - tname[sizeof tname-1] = '\0'; + strlcpy(tname, msg->tsp_name, sizeof tname); xmit(TSP_DATEACK, msg->tsp_seq, &from); - (void)strncpy(olddate, date(), sizeof olddate-1); - olddate[sizeof olddate-1] = '\0'; + strlcpy(olddate, date(), sizeof olddate); /* adjust time for residence on the queue */ (void)gettimeofday(&otime, 0); @@ -528,8 +515,7 @@ spreadtime() dictate = 2; for (htp = self.l_fwd; htp != &self; htp = htp->l_fwd) { to.tsp_type = TSP_SETTIME; - (void)strncpy(to.tsp_name, hostname, sizeof to.tsp_name-1); - to.tsp_name[sizeof to.tsp_name-1] = '\0'; + 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; @@ -808,8 +794,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)strncpy(to.tsp_name, hostname, sizeof to.tsp_name-1); - to.tsp_name[sizeof to.tsp_name-1] = '\0'; + 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; diff --git a/usr.sbin/timed/timed/measure.c b/usr.sbin/timed/timed/measure.c index 94800456ff3..fd35b5fcd33 100644 --- a/usr.sbin/timed/timed/measure.c +++ b/usr.sbin/timed/timed/measure.c @@ -1,4 +1,4 @@ -/* $OpenBSD: measure.c,v 1.3 2001/04/07 20:00:16 ho Exp $ */ +/* $OpenBSD: measure.c,v 1.4 2001/05/05 05:10:04 mickey Exp $ */ /*- * Copyright (c) 1985, 1993 The Regents of the University of California. @@ -38,7 +38,7 @@ static char sccsid[] = "@(#)measure.c 5.1 (Berkeley) 5/11/93"; #endif /* not lint */ #ifdef sgi -#ident "$Revision: 1.3 $" +#ident "$Revision: 1.4 $" #endif #include "globals.h" @@ -100,7 +100,7 @@ measure(u_long maxmsec, /* wait this many msec at most */ goto quit; } } - + /* * empty the icmp input queue @@ -194,7 +194,7 @@ measure(u_long maxmsec, /* wait this many msec at most */ if (cc < 0) goto quit; - /* + /* * got something. See if it is ours */ icp = (struct icmp *)(packet + (ip->ip_hl << 2)); @@ -272,7 +272,7 @@ quit: if (trace) { fprintf(fd, "measured delta %4d, %d trials to %-15s %s\n", - measure_delta, trials, + measure_delta, trials, inet_ntoa(addr->sin_addr), hname); } } else if (print) { diff --git a/usr.sbin/timed/timed/networkdelta.c b/usr.sbin/timed/timed/networkdelta.c index b0cdd4d9e88..18ea81f7500 100644 --- a/usr.sbin/timed/timed/networkdelta.c +++ b/usr.sbin/timed/timed/networkdelta.c @@ -1,4 +1,4 @@ -/* $OpenBSD: networkdelta.c,v 1.3 2001/04/07 20:00:16 ho Exp $ */ +/* $OpenBSD: networkdelta.c,v 1.4 2001/05/05 05:10:04 mickey Exp $ */ /*- * Copyright (c) 1985, 1993 The Regents of the University of California. @@ -38,7 +38,7 @@ static char sccsid[] = "@(#)networkdelta.c 5.1 (Berkeley) 5/11/93"; #endif /* not lint */ #ifdef sgi -#ident "$Revision: 1.3 $" +#ident "$Revision: 1.4 $" #endif #include "globals.h" @@ -252,7 +252,7 @@ median(float a, /* initial guess for the median */ else a = (xm+a)/2; - } else if (npts != 0) { /* odd number of points */ + } else if (npts != 0) { /* odd number of points */ if (npts > 0) a = xp; else diff --git a/usr.sbin/timed/timed/readmsg.c b/usr.sbin/timed/timed/readmsg.c index 55634a0c9c7..7dfee3216a5 100644 --- a/usr.sbin/timed/timed/readmsg.c +++ b/usr.sbin/timed/timed/readmsg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: readmsg.c,v 1.7 2001/04/07 20:00:16 ho Exp $ */ +/* $OpenBSD: readmsg.c,v 1.8 2001/05/05 05:10:04 mickey Exp $ */ /*- * Copyright (c) 1985, 1993 The Regents of the University of California. @@ -38,7 +38,7 @@ static char sccsid[] = "@(#)readmsg.c 5.1 (Berkeley) 5/11/93"; #endif /* not lint */ #ifdef sgi -#ident "$Revision: 1.7 $" +#ident "$Revision: 1.8 $" #endif #include "globals.h" @@ -52,7 +52,7 @@ extern char *tsptype[]; #define LOOKAT(msg, mtype, mfrom, netp, froms) \ (((mtype) == TSP_ANY || (mtype) == (msg).tsp_type) && \ ((mfrom) == 0 || !strcmp((mfrom), (msg).tsp_name)) && \ - ((netp) == 0 || \ + ((netp) == 0 || \ ((netp)->mask & (froms).sin_addr.s_addr) == (netp)->net.s_addr)) struct timeval rtime, rwait, rtout; @@ -406,8 +406,7 @@ masterack() resp = msgin; resp.tsp_vers = TSPVERSION; - (void)strncpy(resp.tsp_name, hostname, sizeof resp.tsp_name-1); - resp.tsp_name[sizeof resp.tsp_name-1] = '\0'; + strlcpy(resp.tsp_name, hostname, sizeof resp.tsp_name); switch(msgin.tsp_type) { @@ -450,7 +449,7 @@ struct sockaddr_in *addr; { char tm[26]; time_t msgtime; - + if (msg->tsp_type >= TSPTYPENUMBER) { fprintf(fd, "bad type (%u) on packet from %s\n", msg->tsp_type, inet_ntoa(addr->sin_addr)); @@ -476,8 +475,7 @@ struct sockaddr_in *addr; (void)cftime(tm, "%D %T", &msg->tsp_time.tv_sec); #else msgtime = msg->tsp_time.tv_sec; - strncpy(tm, ctime(&msgtime)+3+1, sizeof(tm)); - tm[15] = '\0'; /* ugh */ + strftime(tm, sizeof(tm), "%D %T", localtime(&msgtime)); #endif /* sgi */ fprintf(fd, "%s %d %-6u %s %-15s %s\n", tsptype[msg->tsp_type], diff --git a/usr.sbin/timed/timed/slave.c b/usr.sbin/timed/timed/slave.c index 545f797f783..b28db24eb45 100644 --- a/usr.sbin/timed/timed/slave.c +++ b/usr.sbin/timed/timed/slave.c @@ -1,4 +1,4 @@ -/* $OpenBSD: slave.c,v 1.4 1996/11/01 06:10:42 deraadt Exp $ */ +/* $OpenBSD: slave.c,v 1.5 2001/05/05 05:10:05 mickey Exp $ */ /*- * Copyright (c) 1985, 1993 The Regents of the University of California. @@ -38,7 +38,7 @@ static char sccsid[] = "@(#)slave.c 5.1 (Berkeley) 5/11/93"; #endif /* not lint */ #ifdef sgi -#ident "$Revision: 1.4 $" +#ident "$Revision: 1.5 $" #endif #include "globals.h" @@ -154,9 +154,7 @@ loop: to.tsp_vers = TSPVERSION; to.tsp_seq = sequence++; to.tsp_hopcnt = MAX_HOPCNT; - (void)strncpy(to.tsp_name, hostname, - sizeof to.tsp_name-1); - to.tsp_name[sizeof to.tsp_name-1] = '\0'; + 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, @@ -270,11 +268,9 @@ loop: * the following line is necessary due to syslog * calling ctime() which clobbers the static buffer */ - (void)strncpy(olddate, date(), sizeof olddate-1); - olddate[sizeof olddate-1] = '\0'; + strlcpy(olddate, date(), sizeof olddate); tmpt = msg->tsp_time.tv_sec; - (void)strncpy(newdate, ctime(&tmpt), sizeof newdate-1); - newdate[sizeof newdate-1] = '\0'; + strlcpy(newdate, ctime(&tmpt), sizeof newdate); #endif /* sgi */ if (!good_host_name(msg->tsp_name)) { @@ -368,8 +364,7 @@ loop: (void)cftime(newdate, "%D %T", &msg->tsp_time.tv_sec); #else tmpt = msg->tsp_time.tv_sec; - (void)strncpy(newdate, ctime(&tmpt), sizeof newdate-1); - newdate[sizeof newdate-1] = '\0'; + strlcpy(newdate, ctime(&tmpt), sizeof newdate); #endif /* sgi */ schgdate(msg, newdate); break; @@ -381,8 +376,7 @@ loop: (void)cftime(newdate, "%D %T", &msg->tsp_time.tv_sec); #else tmpt = msg->tsp_time.tv_sec; - (void)strncpy(newdate, ctime(&tmpt), sizeof newdate-1); - newdate[sizeof newdate-1] = '\0'; + strlcpy(newdate, ctime(&tmpt), sizeof newdate); #endif /* sgi */ htp = findhost(msg->tsp_name); if (0 == htp) { @@ -436,12 +430,9 @@ loop: refusetime = ntime.tv_sec + 30; } taddr = from; - (void)strncpy(tname, msg->tsp_name, - sizeof tname-1); - tname[sizeof tname-1] = '\0'; - (void)strncpy(to.tsp_name, hostname, - sizeof to.tsp_name-1); - to.tsp_name[sizeof to.tsp_name-1] = '\0'; + strlcpy(tname, msg->tsp_name, sizeof tname); + strlcpy(to.tsp_name, hostname, + sizeof to.tsp_name); answerdelay(); if (!acksend(&to, &taddr, tname, TSP_ACK, 0, 0)) @@ -452,9 +443,8 @@ loop: } else { /* fromnet->status == MASTER */ htp = addmach(msg->tsp_name, &from,fromnet); to.tsp_type = TSP_QUIT; - (void)strncpy(to.tsp_name, hostname, - sizeof to.tsp_name-1); - to.tsp_name[sizeof to.tsp_name-1] = '\0'; + strlcpy(to.tsp_name, hostname, + sizeof to.tsp_name); if (!acksend(&to, &htp->addr, htp->name, TSP_ACK, 0, htp->noanswer)) { syslog(LOG_ERR, @@ -473,9 +463,7 @@ loop: * more than one master: the first slave to * come up will notify here the situation. */ - (void)strncpy(to.tsp_name, hostname, - sizeof to.tsp_name-1); - to.tsp_name[sizeof to.tsp_name-1] = '\0'; + strlcpy(to.tsp_name, hostname, sizeof to.tsp_name); /* The other master often gets into the same state, * with boring results. @@ -509,9 +497,7 @@ loop: to.tsp_type = TSP_MSITEREQ; to.tsp_vers = TSPVERSION; to.tsp_seq = 0; - (void)strncpy(to.tsp_name, hostname, - sizeof to.tsp_name-1); - to.tsp_name[sizeof to.tsp_name-1] = '\0'; + strlcpy(to.tsp_name, hostname, sizeof to.tsp_name); answer = acksend(&to, &slavenet->dest_addr, ANYADDR, TSP_ACK, slavenet, 0); @@ -519,9 +505,8 @@ loop: && good_host_name(answer->tsp_name)) { setmaster(answer); to.tsp_type = TSP_ACK; - (void)strncpy(to.tsp_name, answer->tsp_name, - sizeof to.tsp_name-1); - to.tsp_name[sizeof to.tsp_name-1] = '\0'; + strlcpy(to.tsp_name, answer->tsp_name, + sizeof to.tsp_name); bytenetorder(&to); if (sendto(sock, (char *)&to, sizeof(struct tsp), 0, @@ -570,13 +555,11 @@ loop: if (answer == NULL) break; taddr = from; - (void)strncpy(tname, answer->tsp_name, - sizeof tname-1); - tname[sizeof tname-1] = '\0'; + strlcpy(tname, answer->tsp_name, + sizeof tname); to.tsp_type = TSP_QUIT; - (void)strncpy(to.tsp_name, hostname, - sizeof to.tsp_name-1); - to.tsp_name[sizeof to.tsp_name-1] = '\0'; + strlcpy(to.tsp_name, hostname, + sizeof to.tsp_name); if (!acksend(&to, &taddr, tname, TSP_ACK, 0, 1)) { syslog(LOG_ERR, @@ -629,9 +612,8 @@ loop: htp = addmach(answer->tsp_name, &from,ntp); to.tsp_type = TSP_QUIT; - (void)strncpy(to.tsp_name, hostname, - sizeof to.tsp_name-1); - to.tsp_name[sizeof to.tsp_name-1] = '\0'; + strlcpy(to.tsp_name, hostname, + sizeof to.tsp_name); if (!acksend(&to,&htp->addr,htp->name, TSP_ACK, 0, htp->noanswer)) { syslog(LOG_ERR, @@ -666,9 +648,7 @@ setmaster(struct tsp *msg) && (slavenet != old_slavenet || strcmp(msg->tsp_name, master_name) || old_status != status)) { - (void)strncpy(master_name, msg->tsp_name, - sizeof master_name-1); - master_name[sizeof master_name-1] = '\0'; + strlcpy(master_name, msg->tsp_name, sizeof master_name); old_slavenet = slavenet; old_status = status; @@ -714,8 +694,7 @@ schgdate(struct tsp *msg, char *newdate) to.tsp_type = TSP_SETDATEREQ; to.tsp_time = msg->tsp_time; - (void)strncpy(to.tsp_name, hostname, sizeof to.tsp_name-1); - to.tsp_name[sizeof to.tsp_name-1] = '\0'; + strlcpy(to.tsp_name, hostname, sizeof to.tsp_name); if (!acksend(&to, &slavenet->dest_addr, ANYADDR, TSP_DATEACK, slavenet, 0)) diff --git a/usr.sbin/timed/timed/timed.c b/usr.sbin/timed/timed/timed.c index dec831964f0..d7cbaf29d4c 100644 --- a/usr.sbin/timed/timed/timed.c +++ b/usr.sbin/timed/timed/timed.c @@ -1,4 +1,4 @@ -/* $OpenBSD: timed.c,v 1.9 2001/04/07 19:58:07 ho Exp $ */ +/* $OpenBSD: timed.c,v 1.10 2001/05/05 05:10:05 mickey Exp $ */ /*- * Copyright (c) 1985, 1993 The Regents of the University of California. @@ -44,7 +44,7 @@ static char sccsid[] = "@(#)timed.c 5.1 (Berkeley) 5/11/93"; #endif /* not lint */ #ifdef sgi -#ident "$Revision: 1.9 $" +#ident "$Revision: 1.10 $" #endif /* sgi */ #define TSPTYPES @@ -462,7 +462,7 @@ main(int argc, char **argv) * So we cannot just mask ntp->dest_addr. */ ntp->net = ntp->my_addr; ntp->net.s_addr &= ntp->mask; - } else { + } else { ((struct sockaddr_in *)&ifr->ifr_addr)->sin_addr = ntp->my_addr; if (ioctl(sock, SIOCGIFDSTADDR, @@ -613,8 +613,7 @@ suppress(struct sockaddr_in *addr, if (trace) fprintf(fd, "suppress: %s\n", name); tgt = *addr; - (void)strncpy(tname, name, sizeof tname-1); - tname[sizeof tname-1] = '\0'; + strlcpy(tname, name, sizeof tname); while (0 != readmsg(TSP_ANY, ANYADDR, &wait, net)) { if (trace) @@ -624,8 +623,7 @@ suppress(struct sockaddr_in *addr, syslog(LOG_NOTICE, "suppressing false master %s", tname); msg.tsp_type = TSP_QUIT; - (void)strncpy(msg.tsp_name, hostname, sizeof msg.tsp_name-1); - msg.tsp_name[sizeof msg.tsp_name-1] = '\0'; + strlcpy(msg.tsp_name, hostname, sizeof msg.tsp_name); (void)acksend(&msg, &tgt, tname, TSP_ACK, 0, 1); } @@ -642,8 +640,7 @@ lookformaster(struct netinfo *ntp) /* look for master */ resp.tsp_type = TSP_MASTERREQ; - (void)strncpy(resp.tsp_name, hostname, sizeof resp.tsp_name-1); - resp.tsp_name[sizeof resp.tsp_name-1] = '\0'; + 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)) { @@ -698,8 +695,7 @@ lookformaster(struct netinfo *ntp) } ntp->status = SLAVE; - (void)strncpy(mastername, answer->tsp_name, sizeof mastername-1); - mastername[sizeof mastername-1] = '\0'; + strlcpy(mastername, answer->tsp_name, sizeof mastername); masteraddr = from; /* @@ -717,9 +713,7 @@ lookformaster(struct netinfo *ntp) if (answer != NULL && strcmp(answer->tsp_name, mastername) != 0) { conflict.tsp_type = TSP_CONFLICT; - (void)strncpy(conflict.tsp_name, hostname, - sizeof conflict.tsp_name-1); - conflict.tsp_name[sizeof conflict.tsp_name-1] = '\0'; + strlcpy(conflict.tsp_name, hostname, sizeof conflict.tsp_name); if (!acksend(&conflict, &masteraddr, mastername, TSP_ACK, 0, 0)) { syslog(LOG_ERR, |