From 34acf235688cfc7de559db2e6da860177b087c67 Mon Sep 17 00:00:00 2001 From: Henning Brauer Date: Thu, 17 Apr 2003 17:17:28 +0000 Subject: nuke strcpy + -Wall parts from and ok mickey@ --- usr.bin/tftp/tftp.c | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'usr.bin/tftp/tftp.c') diff --git a/usr.bin/tftp/tftp.c b/usr.bin/tftp/tftp.c index 8809155d4cd..19b4842c873 100644 --- a/usr.bin/tftp/tftp.c +++ b/usr.bin/tftp/tftp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tftp.c,v 1.10 2002/02/16 21:27:55 millert Exp $ */ +/* $OpenBSD: tftp.c,v 1.11 2003/04/17 17:17:27 henning Exp $ */ /* $NetBSD: tftp.c,v 1.5 1995/04/29 05:55:25 cgd Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)tftp.c 8.1 (Berkeley) 6/6/93"; #endif -static char rcsid[] = "$OpenBSD: tftp.c,v 1.10 2002/02/16 21:27:55 millert Exp $"; +static const char rcsid[] = "$OpenBSD: tftp.c,v 1.11 2003/04/17 17:17:27 henning Exp $"; #endif /* not lint */ /* Many bug fixes are from Jim Guyton */ @@ -58,6 +58,7 @@ static char rcsid[] = "$OpenBSD: tftp.c,v 1.10 2002/02/16 21:27:55 millert Exp $ #include #include #include +#include #include #include #include @@ -96,13 +97,11 @@ sendfile(fd, name, mode) char *name; char *mode; { - struct tftphdr *ap; /* data and ack packets */ - struct tftphdr *r_init(), *dp; - int n; + struct tftphdr *dp, *ap; /* data and ack packets */ volatile int block, size, convert; volatile unsigned long amount; struct sockaddr_in from; - int fromlen; + int n, fromlen; FILE *file; startclock(); /* start stat's clock */ @@ -201,13 +200,11 @@ recvfile(fd, name, mode) char *name; char *mode; { - struct tftphdr *ap; - struct tftphdr *dp, *w_init(); - int n; + struct tftphdr *dp, *ap; volatile int block, size, firsttrip; volatile unsigned long amount; struct sockaddr_in from; - int fromlen; + int n, fromlen; FILE *file; volatile int convert; /* true if converting crlf -> lf */ @@ -312,16 +309,16 @@ makerequest(request, name, tp, mode) const char *mode; { char *cp; + int len, pktlen; tp->th_opcode = htons((u_short)request); cp = tp->th_stuff; - strcpy(cp, name); - cp += strlen(name); - *cp++ = '\0'; - strcpy(cp, mode); - cp += strlen(mode); - *cp++ = '\0'; - return (cp - (char *)tp); + pktlen = PKTSIZE - offsetof(struct tftphdr, th_stuff); + len = strlen(name) + 1; + strlcpy(cp, name, pktlen); + strlcpy(cp + len, mode, pktlen - len); + len += strlen(mode) + 1; + return (cp + len - (char *)tp); } struct errmsg { -- cgit v1.2.3