Commit Graph

49 Commits

Author SHA1 Message Date
John Baldwin
fdf929ff91 Add support for the TFTP windowsize option described in RFC 7440.
The windowsize option permits multiple blocks to be transmitted
before the receiver sends an ACK improving throughput for larger
files.

Reviewed by:	asomers
MFC after:	2 weeks
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D23836
2020-03-02 22:19:30 +00:00
Alan Somers
123d18b5c7 tftp: fix two minor Coverity CIDs
Reported by:	Coverity
CID 1394842: file descriptor leak in an error path
CID 1007603: single byte array overflow
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D21695
2019-10-03 20:22:25 +00:00
Alan Somers
7dbe228c6a tftp(1): switch default transfer mode to binary
netascii is obsolete and inefficient. It isn't even supported by many
clients. Better to use binary mode by default.

Reviewed by:	cem
Relnotes:	yes
Differential Revision:	https://reviews.freebsd.org/D16869
2018-08-23 17:00:07 +00:00
Alan Somers
e40369745c tftp: Close a resource leak when putting files
Reported by:	Coverity
CID:		1394842
MFC after:	2 weeks
2018-08-14 17:20:31 +00:00
Alan Somers
ca2d3691c3 Fix several Coverity warnings in tftp
Some of the changes are in the libexec/tftpd directory, but to functions that
are only used by tftp(1) (they share some code).

* strcpy => strlcpy (1006793, 1006794, 1006796, 1006741)
* Unchecked return value and TOCTTOU (1009314)
* NULL pointer dereference (1018035, 1018036)

Reported by:	Coverity
CID:		1006793, 1006794, 1006796, 1006741, 1009314, 1018035
CID:		1018036
MFC after:	2 weeks
2018-07-22 17:10:12 +00:00
Justin Hibbits
e4803b1c14 Fix uninitialized warning, and work around a bug in gcc over clobbering
Summary:
r329077 caused gcc to emit uninitialized use warnings.  Attempting to
fix those warnings yielded the following warnings:

usr.bin/tftp/main.c: In function 'main':
usr.bin/tftp/main.c:181: warning: variable 'el' might be clobbered by
'longjmp' or 'vfork'
usr.bin/tftp/main.c:182: warning: variable 'hist' might be clobbered by
'longjmp' or 'vfork'

This is a known bug in gcc, found at
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=24239

Work around that by simply marking hist and el as static.

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D14302
2018-02-10 17:17:15 +00:00
Conrad Meyer
51adff9318 tftp(1): Clean up leading and trailing whitespace
Whitespace-only change.

Sponsored by:	Dell EMC Isilon
2018-02-09 20:00:51 +00:00
Conrad Meyer
49fb06154b tftp(1): Fix libedit state corruption involving signals
This bug was first reported 14 years ago.  The problem was understood 8.5
years ago.  A patch that is functionally identical to this one was proposed
almost 8 years ago and languished in the PR system / Bugzilla.

PR:		63197
Submitted by:	lxv AT omut.org, fernando.apesteguia AT gmail.com
Reported by:	freebsd AT nbritton.org
2018-02-09 19:46:51 +00:00
Pedro F. Giffuni
8a16b7a18f General further adoption of SPDX licensing ID tags.
Mainly focus on files that use BSD 3-Clause license.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.
2017-11-20 19:49:47 +00:00
Warner Losh
fbbd9655e5 Renumber copyright clause 4
Renumber cluase 4 to 3, per what everybody else did when BSD granted
them permission to remove clause 3. My insistance on keeping the same
numbering for legal reasons is too pedantic, so give up on that point.

Submitted by:	Jan Schaumann <jschauma@stevens.edu>
Pull Request:	https://github.com/freebsd/freebsd/pull/96
2017-02-28 23:42:47 +00:00
Marcelo Araujo
a9a46bd918 Use MIN() macro from sys/param.h.
MFC after:	2 weeks.
2016-04-27 02:34:25 +00:00
Marcelo Araujo
6b1c46441c Partially revert the change on r298325 where there is an
(-1) casted to a pointer.

Submitted by:	pfg
MFC after:	2 weeks.
2016-04-20 01:38:54 +00:00
Marcelo Araujo
b4b3d271de Use NULL instead of 0 for pointers.
Small cosmetic change.

MFC after:	2 weeks.
2016-04-20 01:28:31 +00:00
Xin LI
32e49abef0 - uri is expected to be nul-terminated (strchr used later),
so use strlcpy instead of strncpy.
 - unroll the other two cases of strncpy+\0 to strlcpy.

MFC after:	2 weeks
2015-08-31 06:11:39 +00:00
Marcel Moolenaar
0f8d6cfc15 Increase MAXLINE to deal with longer paths.
Obtained from:	Juniper Networks, Inc.
2014-03-04 01:14:37 +00:00
Ed Schouten
bf70becee6 More -Wmissing-variable-declarations fixes.
In addition to adding `static' where possible:

- bin/date: Move `retval' into extern.h to make it visible to date.c.
- bin/ed: Move globally used variables into ed.h.
- sbin/camcontrol: Move `verbose' into camcontrol.h and fix shadow warnings.
- usr.bin/calendar: Remove unneeded variables.
- usr.bin/chat: Make `line' local instead of global.
- usr.bin/elfdump: Comment out unneeded function.
- usr.bin/rlogin: Use _Noreturn instead of __dead2.
- usr.bin/tset: Pull `Ospeed' into extern.h.
- usr.sbin/mfiutil: Put global variables in mfiutil.h.
- usr.sbin/pkg: Remove unused `os_corres'.
- usr.sbin/quotaon, usr.sbin/repquota: Remove unused `qfname'.
2012-10-19 14:49:42 +00:00
Kevin Lo
a3a2bf4b67 fgets(3) returns a pointer, so compare against NULL, not integer 0. 2012-01-13 06:51:15 +00:00
Ed Schouten
b3608ae18f Replace index() and rindex() calls with strchr() and strrchr().
The index() and rindex() functions were marked LEGACY in the 2001
revision of POSIX and were subsequently removed from the 2008 revision.
The strchr() and strrchr() functions are part of the C standard.

This makes the source code a lot more consistent, as most of these C
files also call into other str*() routines. In fact, about a dozen
already perform strchr() calls.
2012-01-03 18:51:58 +00:00
Xin LI
7c9acc776a peeraddr is only used in sizeof() evaluations, so instead of declaring it
a variable, use typedef.

MFC after:	1 month
2011-07-11 05:57:49 +00:00
Kevin Lo
aa7e4bb466 Remove duplicated header files 2011-06-24 07:18:44 +00:00
Craig Rodrigues
f4b7e64d7a Specify correct RFC2347 for TFTP options in diagnostic message. 2011-06-16 02:16:53 +00:00
Warner Losh
f471745a98 Fix a couple of spelling errors.
Submitted by:	bcr@
2011-05-31 16:59:14 +00:00
Joel Dahl
da52b4caaf Remove the advertising clause from UCB copyrighted files in usr.bin. This
is in accordance with the information provided at
ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change

Also add $FreeBSD$ to a few files to keep svn happy.

Discussed with:	imp, rwatson
2010-12-11 08:32:16 +00:00
Marius Strobl
04ebad3842 Make WARNS=6 clean.
MFC after:	1 week
2010-09-24 10:40:17 +00:00
Warner Losh
752fa69402 Go ahead and merge the work edwin@ on tftpd into the tree. It is a
lot better than what's in the tree now.  Edwin tested it at a prior
employer, but can't test it today.  I've found that it works a lot
better with the various uboot versions that I've used in my embedded
work.  Here's the pkg-descr from the port that describes the changes:

It all started when we got some new routers, which told me the
following when trying to upload configuration or download images
from it: The TFTP server doesn't support the blocksize option.

My curiousity was triggered, it took me some reading of RFCs and
other documentation to find out what was possible and what could
be done. Was plain TFTP very simple in its handshake, TFTP with
options was kind of messy because of its backwards capability: The
first packet returned could either be an acknowledgement of options,
or the first data packet.

Going through the source code of src/libexec/tftpd and going through
the code of src/usr.bin/tftp showed that there was a lot of duplicate
code, and the addition of options would only increase the amount
of duplicate code. After all, both the client and the server can
act as a sender and receiver.

At the end, it ended up with a nearly complete rewrite of the tftp
client and server. It has been tested against the following TFTP
clients and servers:

- Itself (yay!)
- The standard FreeBSD tftp client and server
- The Fedora Core 6 tftp client and server
- Cisco router tftp client
- Extreme Networks tftp client

It supports the following RFCs:

RFC1350 - THE TFTP PROTOCOL (REVISION 2)
RFC2347 - TFTP Option Extension
RFC2348 - TFTP Blocksize Option
RFC2349 - TFTP Timeout Interval and Transfer Size Options
RFC3617 - Uniform Resource Identifier (URI) Scheme and Applicability
          Statement for the Trivial File Transfer Protocol (TFTP)

It supports the following unofficial TFTP Options as described at
http://www.compuphase.com/tftp.htm:

blksize2 - Block size restricted to powers of 2, excluding protocol headers
rollover - Block counter roll-over (roll back to zero or to one)

From the tftp program point of view the following things are changed:

- New commands: "blocksize", "blocksize2", "rollover" and "options"
- Development features: "debug" and "packetdrop"

If you try this tftp/tftpd implementation, please let me know if
it works (or doesn't work) and against which implementaion so I can
get a list of confirmed working systems.

Author: Edwin Groothuis <edwin@FreeBSD.org>
2010-05-04 06:13:17 +00:00
Xin LI
1b0fa6fa40 ANSIfy, plus constify interfaces where possible. 2008-10-13 23:10:19 +00:00
Xin LI
3a4e1f4703 Use strlcpy() instead of strncpy() when we want the string to be
NUL-terminated.
2008-10-13 22:50:38 +00:00
Stefan Farfeleder
2110d9c31a Use the new name H_SETSIZE instead of the old H_EVENT to set the history
size.

PR:	86355
2005-10-19 15:37:43 +00:00
Tim J. Robbins
7f3a5689e7 Fix BSS buffer overflow in makeargv(). 2003-10-12 00:27:55 +00:00
Simon L. B. Nielsen
891ca8cf3b tftp.1:
- Add the optional port argument to SYNOPSIS.
main.c:
- Sync usage with the manual page.

Approved by:	trhodes (main.c part)
Obtained from:	OpenBSD (jmc)
MFC after:	2 weeks
2003-10-01 21:01:14 +00:00
Jonathan Chen
2e34a0f429 fix reverse logic in "connect" command that cause port specifications to be ignored.
MFC after:	1 week
2003-03-25 02:33:35 +00:00
Brian S. Dean
73f899cae1 To perform even basic error checking, one must have an exit code that
indicates that not everything worked as expected.  Exit non-zero if we
timed out while transmitting or receiving a file or if the file did
not exist, etc.

MFC After:	3 days (re@ willing)
2002-05-12 01:47:50 +00:00
David Malone
8da9a6b0c5 Add some constness to make this WARNS clean again. 2002-04-13 18:38:16 +00:00
Hajimu UMEMOTO
4dac6235cf IPv6 support for tftp/tftpd.
Obtained from:	KAME
MFC after:	2 weeks
2002-04-11 17:14:22 +00:00
Warner Losh
3f330d7d1a remove __P 2002-03-22 01:42:45 +00:00
David Malone
8f4c8256b2 1) Move FreeBSD ID below vendor ID and don't compile vendor ID.
2) Cast some numbers we know to be positive to size_t before we MIN them
   with the result of a sizeof.
3) Compare result of inet_addr to INADDR_NONE, not -1.
2002-02-27 15:22:12 +00:00
Guido van Rooij
b50764b00b Argh...argv->argc 2002-01-04 13:46:57 +00:00
Guido van Rooij
57aa7d5027 Fix the coredump that occurs when, from the tfpt prompt, a 'c' command is
issued without an argument.
2002-01-04 13:42:14 +00:00
Mark Murray
8049f797e3 WARNS=2 fixes. NO_WERROR set as there are some hard-to-fix
signed/unsigned comparisons. Use __FBSDID().
2001-12-11 23:43:15 +00:00
Bruce Evans
8979160a62 Fixed most style bugs in previous commit. 2001-10-19 12:27:26 +00:00
Matthew N. Dodd
c33ed45032 Add libedit support to tftp. 2001-10-19 00:23:07 +00:00
Peter Wemm
c3aac50f28 $Id$ -> $FreeBSD$ 1999-08-28 01:08:13 +00:00
David Greenman
8692ad469b Rename a function name so that it doesn't conflict with a future system call. 1998-10-30 16:17:50 +00:00
Warner Losh
a716ad6693 Don't assume that hp->h_lenght == 4. Be conservative in its use.
Submitted by:	 J. Assange a long time ago.
1998-06-09 04:31:02 +00:00
Philippe Charnier
fd129a0245 Use err(3). 100 -> MAXHOSTNAMELEN from OpenBSD.
Obtained from: OpenBSD
1997-08-14 06:47:41 +00:00
Bruce Evans
eaa86f9d7f Don't use __dead or __pure in user code. They were obfuscations
for gcc >= 2.5 and no-ops for gcc >= 2.6.  Converted to use __dead2
or __pure2 where it wasn't already done, except in math.h where use
of __pure was mostly wrong.
1996-09-14 03:00:32 +00:00
Joerg Wunsch
ca22ff9ec7 Kill the (hopefully) last occurance of gets(3) in the base source tree. 1995-12-27 23:23:43 +00:00
Rodney W. Grimes
7799f52a32 Remove trailing whitespace. 1995-05-30 06:41:30 +00:00
Rodney W. Grimes
9b50d90275 BSD 4.4 Lite Usr.bin Sources 1994-05-27 12:33:43 +00:00