Commit graph

163 commits

Author SHA1 Message Date
Dag-Erling Smørgrav 25945af47e tftpd: silence gcc overflow warnings
GCC 13 complains that we might be writing too much to an on-stack buffer
when createing a filename.

In practice there is a check that filename isn't too long given the
time format and other static characters so GCC is incorrect, but GCC
isn't wrong that we're potentially trying to put a MAXPATHLEN length
string + some other characters into a MAXPATHLEN buffer (if you ignore
the check GCC can't realistically evaluate at compile time).

Switch to snprintf to populate filename to ensure that future logic
errors don't result in a stack overflow.

Shorten the questionably named yyyymmdd buffer enough to slience the
warning (checking the snprintf return value isn't sufficent) while
preserving maximum flexibility for admins who use the -F option.

MFC after:	3 days
Sponsored by:	Klara, Inc.
Reviewed by:	brooks
Differential Revision:	https://reviews.freebsd.org/D45086
2024-05-10 23:16:26 +02:00
Dag-Erling Smørgrav 4d09eb87c5 tftpd: Satisfy clang-analyzer.
* Replace `random()` with `arc4random()`.
* Change some variable types.
* Drop some unused assignments.

MFC after:	3 days
Sponsored by:	Klara, Inc.
Reviewed by:	imp, markj
Differential Revision:	https://reviews.freebsd.org/D45132
2024-05-10 23:16:26 +02:00
Dag-Erling Smørgrav ae285a8cbf tftpd: Add missing include.
This went unnoticed due to namespace pollution in our headers.

MFC after:	3 days
Sponsored by:	Klara, Inc.
Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D45131
2024-05-10 23:16:26 +02:00
Dag-Erling Smørgrav 1111da6b7c tftpd: Drop unneeded includes.
MFC after:	3 days
Sponsored by:	Klara, Inc.
Reviewed by:	imp, markj
Differential Revision:	https://reviews.freebsd.org/D45130
2024-05-10 23:16:26 +02:00
Dag-Erling Smørgrav 816c4d3dcf tftpd: Add missing -S option to synopsis.
MFC after:	3 days
Sponsored by:	Klara, Inc.
Reviewed by:	imp, markj
Differential Revision:	https://reviews.freebsd.org/D45129
2024-05-10 23:16:26 +02:00
Dag-Erling Smørgrav 21b5829d28 tftpd: Untangle a conditional.
MFC after:	1 week
Sponsored by:	Klara, Inc.
Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D45026
2024-04-30 16:56:17 +02:00
Dag-Erling Smørgrav 9f231af307 tftpd: Immediately reject any request shorter than 4 bytes.
MFC after:	1 week
Sponsored by:	Klara, Inc.
Reviewed by:	kevans
Differential Revision:	https://reviews.freebsd.org/D44957
2024-04-25 20:36:13 +02:00
Dag-Erling Smørgrav 83a6e984ac tftpd: Check the server status after each test.
* In the setup phase, wait for the server to start (or fail to start)
  before proceeding with the test.  This makes it possible to write test
  cases that don't expect a response from the server without ending up
  in a race over the server PID file.
* After running each test, wait up to 30 seconds for the server to exit
  and check that the exit status matches what the test case says to
  expect (usually 0).
* We still kill and collect the server in the cleanup phase, in case the
  test ended early.

MFC after:	1 week
Sponsored by:	Klara, Inc.
Reviewed by:	kevans
Differential Revision:	https://reviews.freebsd.org/D44956
2024-04-25 20:36:13 +02:00
Dag-Erling Smørgrav 7ab7ecfcfe tftpd: Clean up the tests.
MFC after:	1 week
Sponsored by:	Klara, Inc.
Reviewed by:	kevans
Differential Revision:	https://reviews.freebsd.org/D44955
2024-04-25 20:36:13 +02:00
Dag-Erling Smørgrav 1ed44fcc44 tftpd: Use size_t where appropriate.
* Limit the use of `ssize_t` to only where it's needed.
* Correct one case of `int` being used for a length.

MFC after:	1 week
Sponsored by:	Klara, Inc.
Reviewed by:	kevans
Differential Revision:	https://reviews.freebsd.org/D44954
2024-04-25 20:36:12 +02:00
Warner Losh a6fe717c2a libexec: Automated cleanup of cdefs and other formatting
Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by:		Netflix
2023-11-26 22:23:59 -07:00
Warner Losh 0b8224d1cc Remove copyright strings ifdef'd out
We've ifdef'd out the copyright strings for some time now. Go ahead and
remove the ifdefs. Plus whatever other detritis was left over from other
recent removals. These copyright strings are present in the comments and
are largely from CSRG's attempt at adding their copyright to every
binary file (which modern interpretations of the license doesn't
require).

Sponsored by:		Netflix
2023-11-26 22:23:58 -07:00
Warner Losh 43581d7b66 libexec: Remove ancient SCCS tags.
Remove ancient SCCS tags from the tree, automated scripting, with two
minor fixup to keep things compiling. All the common forms in the tree
were removed with a perl script.

Sponsored by:		Netflix
2023-11-26 22:23:28 -07:00
Warner Losh b2c76c41be Remove $FreeBSD$: one-line nroff pattern
Remove /^\.\\"\s*\$FreeBSD\$$\n/
2023-08-16 11:55:15 -06:00
Warner Losh d0b2dbfa0e Remove $FreeBSD$: one-line sh pattern
Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
2023-08-16 11:55:03 -06:00
Warner Losh 1d386b48a5 Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-16 11:54:42 -06:00
Dmitry Morozovsky 615d167cb8 Revert "tftpd: fix double-colon typo in option string"
It was not a typo: -d takes an optional argument, which is indicated with
a double colon.

This reverts commit 3cbc8e752b.

Spotted by:	kevans
2023-07-21 00:38:30 +03:00
Dmitry Morozovsky 3cbc8e752b tftpd: fix double-colon typo in option string
MFC after:	1 month
X-MFC-With:	273a307d0b
X-MFC-With:	03c2616dc5
2023-07-21 00:24:28 +03:00
Eugene Grosbein 03c2616dc5 tftpd: unbreak getopt()
Unbreak getopt() broken by recent commit.

Fixes:		273a307d0b
MFC after:	1 month
2023-07-21 03:26:32 +07:00
Eugene Grosbein 273a307d0b tftpd: introduce new option -S
Historically, tftpd disallowed write requests to existing files
that are not publicly writable. Such requirement is questionable at least.
Let us make it possible to run tftpd in chrooted environment
keeping files non-world writable.

New option -S enables write requests to existing files
for chrooted run according to generic file permissions.
It is ignored unless tftpd runs chrooted.

MFC after:	1 month
Requested by:	marck
Differential:	https://reviews.freebsd.org/D41090 (based on)
2023-07-21 03:23:35 +07:00
Warner Losh 4d846d260e spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD
The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with:		pfg
MFC After:		3 days
Sponsored by:		Netflix
2023-05-12 10:44:03 -06:00
Dag-Erling Smørgrav 1955ad42b3 tftpd: Gracefully skip tests if networking is not enabled.
Sponsored by:	Klara, Inc.
Reviewed by:	asomers
Differential Revision:	https://reviews.freebsd.org/D39012
2023-03-10 13:25:16 +00:00
Dag-Erling Smørgrav 77e83935b7 tftpd: Don't forget to close stderr on startup.
Just like stdin and stdout, stderr is a copy of the listen socket inherited from inetd.  We need to close it so inetd can process further requests, be restarted, etc.

Sponsored by:	Klara, Inc.
Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D38968
2023-03-10 13:25:16 +00:00
Dag-Erling Smørgrav b4736c90ad tftpd: Don't consume arbitrary requests when failing to fork.
We've already consumed one request, which is sufficient to prevent inetd from endlessly restarting us in this particular and extremely unlikely case.

Sponsored by:	Klara, Inc.
Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D38967
2023-03-10 13:25:16 +00:00
Dag-Erling Smørgrav e3b4cb1b32 tftpd: Use poll() instead of alarm() + setjmp().
While there, don't log an error when timing out waiting for a possible retransmit after a successful transfer.

Sponsored by:	Klara, Inc.
Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D38966
2023-03-10 13:25:16 +00:00
Dag-Erling Smørgrav 9f6f64941c tftpd: Make the -d option behave as documented.
Sponsored by:	Klara, Inc.
Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D38965
2023-03-10 13:25:16 +00:00
Dag-Erling Smørgrav 36242fc0e5 tftpd: Make the transfer functions return success / failure.
Sponsored by:	Klara, Inc.
Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D38957
2023-03-10 13:25:16 +00:00
Dag-Erling Smørgrav 7c21545c46 tftpd: Ensure that tftp_log() preserves errno.
Sponsored by:	Klara, Inc.
Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D38956
2023-03-10 13:25:16 +00:00
Dag-Erling Smørgrav a6dfd2015c tftpd: Fix max block size calculation.
Sponsored by:	Klara, Inc.
Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D38953
2023-03-10 13:25:15 +00:00
John Baldwin fd5882e1f2 tftpd: Disable -Wformat-nonliteral for GCC.
GCC warns about the non-literal format string passed to strftime().  A
warning here seems a bit odd as strftime() does not take varargs so
there is not a risk of missing args.
2022-11-22 11:12:06 -08:00
John Baldwin 8576f84bc1 tftp: Use printf0 attribute for options_set_request/reply.
These functions accept a NULL format argument so should use the printf0
attribute rather than plain printf.

Reported by:	GCC -Wformat
2022-11-22 08:37:26 -08:00
Dag-Erling Smørgrav cf325fda86 tftpd: type nit
Sponsored by:	Klara, Inc.
2022-11-18 17:26:54 +01:00
Dag-Erling Smørgrav b15e052e74 tftpd: Plug memory leaks in option handling code.
Sponsored by:	Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D37423
2022-11-18 16:39:44 +01:00
Dag-Erling Smørgrav bacb00ab40 tftpd: whitespace cleanup 2022-11-17 16:42:30 +00:00
Dag-Erling Smørgrav eb0292d929 tftpd: cleanup
Sponsored by:	Klara, Inc.
2022-11-15 23:37:54 +01:00
Michael Tuexen 1d0272a600 When receiving a file having a length, which is a mulitple of the blocksize,
close the file once it is received.

Reported by:	Timo Voelker
MFC after:	1 week
2020-12-15 09:43:18 +00:00
Michael Tuexen 3696db923f Improve the counting of blocks used to transfer a file from the
server to the client in case of not using an OACK: Don't miss
the first block in case of it is not also the last one.

MFC after:		1 week
2020-12-14 22:13:58 +00:00
Michael Tuexen 1f67c37c1f Fix the TFTP client when performing a RRQ for files smaller than 512 bytes
and the server not sending an OACK:
* Close the file.
* Report the correct the number of received blocks.

MFC after:		1 week
2020-12-10 19:36:33 +00:00
Michael Tuexen a1c4a3eaf1 When dropping packets (RRQ or WRQ) for debugging, report the send
operation as successful. Reporting a failure stops the transfer
instead of using timeouts.

MFC after:		1 week
2020-12-06 18:43:12 +00:00
Kyle Evans 7cc42f6d25 Do a sweep and remove most WARNS=6 settings
Repeating the default WARNS here makes it slightly more difficult to
experiment with default WARNS changes, e.g. if we did something absolutely
bananas and introduced a WARNS=7 and wanted to try lifting the default to
that.

Drop most of them; there is one in the blake2 kernel module, but I suspect
it should be dropped -- the default WARNS in the rest of the build doesn't
currently apply to kernel modules, and I haven't put too much thought into
whether it makes sense to make it so.
2020-10-01 01:10:51 +00:00
Mark Johnston 0aabff2880 tftpd: Check for errors from chdir()
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2020-09-22 15:54:05 +00:00
Eric van Gyzen fac6dee9eb Remove tests for obsolete compilers in the build system
Assume gcc is at least 6.4, the oldest xtoolchain in the ports tree.
Assume clang is at least 6, which was in 11.2-RELEASE.  Drop conditions
for older compilers.

Reviewed by:	imp (earlier version), emaste, jhb
MFC after:	2 weeks
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D24802
2020-05-12 15:22:40 +00:00
John Baldwin 0c0119856b Abort transfer if fseeko() fails.
CID:		1420215
Reviewed by:	asomers
MFC after:	1 week
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D24454
2020-04-21 17:32:57 +00:00
Kyle Evans 924e10b809 tftpd: tests: raise targeted cstd to c11
r358556 added alignas() use to the functional tests, which isn't defined
until C11. Raise the -std to C11 to fix the build under freebsd-gcc{6,9}.

Reported by:	mhorne, Jenkins/CI
2020-03-05 22:45:16 +00:00
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
Simon J. Gerraty 2c9a9dfc18 Update Makefile.depend files
Update a bunch of Makefile.depend files as
a result of adding Makefile.depend.options files

Reviewed by:	 bdrewery
MFC after:	1 week
Sponsored by:   Juniper Networks
Differential Revision:  https://reviews.freebsd.org/D22494
2019-12-11 17:37:53 +00:00
Simon J. Gerraty 5ab1c5846f Add Makefile.depend.options
Leaf directories that have dependencies impacted
by options need a Makefile.depend.options file
to avoid churn in Makefile.depend

DIRDEPS for cases such as OPENSSL, TCP_WRAPPERS etc
can be set in local.dirdeps-options.mk
which can add to those set in Makefile.depend.options

See share/mk/dirdeps-options.mk

Reviewed by:	 bdrewery
MFC after:	1 week
Sponsored by:   Juniper Networks
Differential Revision:  https://reviews.freebsd.org/D22469
2019-12-11 17:37:37 +00:00
Alan Somers 809a8352dd Drop "All rights reserved" from the files I own
Also, add SPDX tags where needed.

MFC after:	2 weeks
2019-03-11 22:23:56 +00:00
Alan Somers 76e8e459e4 tftpd: Fix data corruption bug with netascii
Transferring files in netascii format requires, among other things,
translating all CR characters to a CR,NUL pair. tftpd does this correctly
except when the CR occurs as the last octet of a packet. In that case, it
erroneously drops the NUL which should be part of the following packet. The
bug was caused by using 0 as a sentinel value in a variable that could
legitimately hold 0. Fix it by switching the sentinel value to -1.

PR:		178055
Reported by:	Richard <rsitze@gmail.com>
Reviewed by:	cem
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D16853
2018-08-22 23:31:27 +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