diff options
author | Henning Brauer <henning@cvs.openbsd.org> | 2003-04-17 17:17:28 +0000 |
---|---|---|
committer | Henning Brauer <henning@cvs.openbsd.org> | 2003-04-17 17:17:28 +0000 |
commit | 34acf235688cfc7de559db2e6da860177b087c67 (patch) | |
tree | 17b5af9f70c53c2b00e28292cf996201cf52408d | |
parent | 988b4ff4aaec196c993ecb5234a8350eda8ade72 (diff) |
nuke strcpy + -Wall
parts from and ok mickey@
-rw-r--r-- | usr.bin/tftp/Makefile | 3 | ||||
-rw-r--r-- | usr.bin/tftp/main.c | 16 | ||||
-rw-r--r-- | usr.bin/tftp/tftp.c | 31 | ||||
-rw-r--r-- | usr.bin/tftp/tftpsubs.c | 4 |
4 files changed, 26 insertions, 28 deletions
diff --git a/usr.bin/tftp/Makefile b/usr.bin/tftp/Makefile index 42dc100768c..7f58cb044bb 100644 --- a/usr.bin/tftp/Makefile +++ b/usr.bin/tftp/Makefile @@ -1,6 +1,7 @@ -# $OpenBSD: Makefile,v 1.3 1997/09/21 11:51:13 deraadt Exp $ +# $OpenBSD: Makefile,v 1.4 2003/04/17 17:17:27 henning Exp $ PROG= tftp +CFLAGS+=-Wall SRCS= main.c tftp.c tftpsubs.c .include <bsd.prog.mk> diff --git a/usr.bin/tftp/main.c b/usr.bin/tftp/main.c index 5f0f6756519..a808013969d 100644 --- a/usr.bin/tftp/main.c +++ b/usr.bin/tftp/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.11 2003/03/13 09:09:35 deraadt Exp $ */ +/* $OpenBSD: main.c,v 1.12 2003/04/17 17:17:27 henning Exp $ */ /* $NetBSD: main.c,v 1.6 1995/05/21 16:54:10 mycroft Exp $ */ /* @@ -35,7 +35,7 @@ */ #ifndef lint -static char copyright[] = +static const char copyright[] = "@(#) Copyright (c) 1983, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ @@ -44,7 +44,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93"; #endif -static char rcsid[] = "$OpenBSD: main.c,v 1.11 2003/03/13 09:09:35 deraadt Exp $"; +static const char rcsid[] = "$OpenBSD: main.c,v 1.12 2003/04/17 17:17:27 henning Exp $"; #endif /* not lint */ /* Many bug fixes are from Jim Guyton <guyton@rand-unix> */ @@ -379,10 +379,9 @@ put(argc, argv) } /* this assumes the target is a directory */ /* on a remote unix system. hmmmm. */ - cp = strchr(targ, '\0'); - *cp++ = '/'; for (n = 1; n < argc - 1; n++) { - strcpy(cp, tail(argv[n])); + if (asprintf(&cp, "%s/%s", targ, tail(argv[n])) == -1) + err(1, "asprintf"); fd = open(argv[n], O_RDONLY); if (fd < 0) { warn("open: %s", argv[n]); @@ -390,9 +389,10 @@ put(argc, argv) } if (verbose) printf("putting %s to %s:%s [%s]\n", - argv[n], hostname, targ, mode); + argv[n], hostname, cp, mode); peeraddr.sin_port = port; - sendfile(fd, targ, mode); + sendfile(fd, cp, mode); + free(cp); } } 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 <guyton@rand-unix> */ @@ -58,6 +58,7 @@ static char rcsid[] = "$OpenBSD: tftp.c,v 1.10 2002/02/16 21:27:55 millert Exp $ #include <setjmp.h> #include <signal.h> #include <stdio.h> +#include <stddef.h> #include <string.h> #include <unistd.h> #include <err.h> @@ -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 { diff --git a/usr.bin/tftp/tftpsubs.c b/usr.bin/tftp/tftpsubs.c index 9445cd898fc..c5761499c10 100644 --- a/usr.bin/tftp/tftpsubs.c +++ b/usr.bin/tftp/tftpsubs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tftpsubs.c,v 1.4 2002/09/06 18:55:04 deraadt Exp $ */ +/* $OpenBSD: tftpsubs.c,v 1.5 2003/04/17 17:17:27 henning Exp $ */ /* $NetBSD: tftpsubs.c,v 1.3 1994/12/08 09:51:31 jtc Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)tftpsubs.c 8.1 (Berkeley) 6/6/93"; #endif -static char rcsid[] = "$OpenBSD: tftpsubs.c,v 1.4 2002/09/06 18:55:04 deraadt Exp $"; +static const char rcsid[] = "$OpenBSD: tftpsubs.c,v 1.5 2003/04/17 17:17:27 henning Exp $"; #endif /* not lint */ /* Simple minded read-ahead/write-behind subroutines for tftp user and |