diff options
author | Mike Pechkin <mpech@cvs.openbsd.org> | 2001-07-31 14:32:16 +0000 |
---|---|---|
committer | Mike Pechkin <mpech@cvs.openbsd.org> | 2001-07-31 14:32:16 +0000 |
commit | 7e869dd08f73eb663a8c4425642b53a970c07585 (patch) | |
tree | a02a8c47bc41eb14abe73792f49caf39d68aaff9 | |
parent | 6486bc2f1faff9954cb6ccfa3cf8281947133020 (diff) |
o) better struct handling;
o) use __progname in openlog(3);
o) better ERROR packets handling;
millert@ ok
-rw-r--r-- | libexec/tftpd/tftpd.c | 16 | ||||
-rw-r--r-- | usr.bin/tftp/main.c | 14 | ||||
-rw-r--r-- | usr.bin/tftp/tftp.c | 11 |
3 files changed, 21 insertions, 20 deletions
diff --git a/libexec/tftpd/tftpd.c b/libexec/tftpd/tftpd.c index 85faa6fa5f0..97536593ee5 100644 --- a/libexec/tftpd/tftpd.c +++ b/libexec/tftpd/tftpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tftpd.c,v 1.18 2001/06/11 15:18:53 mickey Exp $ */ +/* $OpenBSD: tftpd.c,v 1.19 2001/07/31 14:32:15 mpech Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -41,7 +41,7 @@ char copyright[] = #ifndef lint /*static char sccsid[] = "from: @(#)tftpd.c 5.13 (Berkeley) 2/26/91";*/ -static char rcsid[] = "$OpenBSD: tftpd.c,v 1.18 2001/06/11 15:18:53 mickey Exp $: tftpd.c,v 1.6 1997/02/16 23:49:21 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: tftpd.c,v 1.19 2001/07/31 14:32:15 mpech Exp $: tftpd.c,v 1.6 1997/02/16 23:49:21 deraadt Exp $"; #endif /* not lint */ /* @@ -140,7 +140,7 @@ main(argc, argv) int i, j; int c; - openlog("tftpd", LOG_PID | LOG_NDELAY, LOG_DAEMON); + openlog(__progname, LOG_PID | LOG_NDELAY, LOG_DAEMON); while ((c = getopt(argc, argv, "cs")) != -1) switch (c) { @@ -590,7 +590,7 @@ struct errmsg { { EBADID, "Unknown transfer ID" }, { EEXISTS, "File already exists" }, { ENOUSER, "No such user" }, - { -1, 0 } + { -1, NULL } }; /* @@ -617,9 +617,9 @@ nak(error) pe->e_msg = strerror(error - 100); tp->th_code = EUNDEF; /* set 'undef' errorcode */ } - length = strlcpy(tp->th_msg, pe->e_msg, sizeof(buf) - 4); - if (length >= sizeof(buf) - 4) - length = sizeof(buf) - 5; - if (send(peer, buf, length + 5, 0) != length) + length = strlcpy(tp->th_msg, pe->e_msg, sizeof(buf)) + 5; + if (length > sizeof(buf)) + length = sizeof(buf); + if (send(peer, buf, length, 0) != length) syslog(LOG_ERR, "nak: %m"); } diff --git a/usr.bin/tftp/main.c b/usr.bin/tftp/main.c index 35bb9ad673d..fc378f6039b 100644 --- a/usr.bin/tftp/main.c +++ b/usr.bin/tftp/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.7 2001/07/17 02:23:59 pvalchev Exp $ */ +/* $OpenBSD: main.c,v 1.8 2001/07/31 14:32:15 mpech Exp $ */ /* $NetBSD: main.c,v 1.6 1995/05/21 16:54:10 mycroft Exp $ */ /* @@ -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.7 2001/07/17 02:23:59 pvalchev Exp $"; +static char rcsid[] = "$OpenBSD: main.c,v 1.8 2001/07/31 14:32:15 mpech Exp $"; #endif /* not lint */ /* Many bug fixes are from Jim Guyton <guyton@rand-unix> */ @@ -149,7 +149,7 @@ struct cmd cmdtab[] = { { "rexmt", xhelp, setrexmt }, { "timeout", ihelp, settimeout }, { "?", hhelp, help }, - { 0 } + { NULL, NULL, NULL } }; struct cmd *getcmd(); @@ -245,7 +245,7 @@ struct modes { { "image", "octet" }, { "octet", "octet" }, /* { "mail", "mail" }, */ - { 0, 0 } + { NULL, NULL } }; void @@ -261,7 +261,7 @@ modecmd(argc, argv) return; } if (argc == 2) { - for (p = modes; p->m_name; p++) + for (p = modes; p->m_name != NULL; p++) if (strcmp(argv[1], p->m_name) == 0) break; if (p->m_name) { @@ -274,7 +274,7 @@ modecmd(argc, argv) printf("usage: %s [", argv[0]); sep = " "; - for (p = modes; p->m_name; p++) { + for (p = modes; p->m_name != NULL; p++) { printf("%s%s", sep, p->m_name); if (*sep == ' ') sep = " | "; @@ -710,7 +710,7 @@ help(argc, argv) if (argc == 1) { printf("Commands may be abbreviated. Commands are:\n\n"); - for (c = cmdtab; c->name; c++) + for (c = cmdtab; c->name != NULL; c++) printf("%-*s\t%s\n", (int)HELPINDENT, c->name, c->help); return; } diff --git a/usr.bin/tftp/tftp.c b/usr.bin/tftp/tftp.c index c03a88493e0..ffacababc29 100644 --- a/usr.bin/tftp/tftp.c +++ b/usr.bin/tftp/tftp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tftp.c,v 1.7 2001/03/22 01:34:01 mickey Exp $ */ +/* $OpenBSD: tftp.c,v 1.8 2001/07/31 14:32:15 mpech 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.7 2001/03/22 01:34:01 mickey Exp $"; +static char rcsid[] = "$OpenBSD: tftp.c,v 1.8 2001/07/31 14:32:15 mpech Exp $"; #endif /* not lint */ /* Many bug fixes are from Jim Guyton <guyton@rand-unix> */ @@ -336,7 +336,7 @@ struct errmsg { { EBADID, "Unknown transfer ID" }, { EEXISTS, "File already exists" }, { ENOUSER, "No such user" }, - { -1, 0 } + { -1, NULL } }; /* @@ -363,8 +363,9 @@ nak(error) pe->e_msg = strerror(error - 100); tp->th_code = EUNDEF; } - strcpy(tp->th_msg, pe->e_msg); - length = strlen(pe->e_msg) + 4; + length = strlcpy(tp->th_msg, pe->e_msg, sizeof(ackbuf)) + 5; + if (length > sizeof(ackbuf)) + length = sizeof(ackbuf); if (trace) tpacket("sent", tp, length); if (sendto(f, ackbuf, length, 0, (struct sockaddr *)&peeraddr, |