git: 9a44e1769b90 - stable/15 - tftpd: Keep proper track of option length
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 16 Nov 2026 15:17:45 UTC
The branch stable/15 has been updated by des:
URL: https://cgit.FreeBSD.org/src/commit/?id=9a44e1769b909328fb064bc16a70e1746f26fac2
commit 9a44e1769b909328fb064bc16a70e1746f26fac2
Author: Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-11-11 19:45:24 +0000
Commit: Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-11-16 14:52:03 +0000
tftpd: Keep proper track of option length
When parsing options, keep track of the length of the unparsed portion
and pass that to get_field() instead of the length of the entire header.
While here, switch both make_options() and parse_options() to using
size_t for sizes and lengths.
MFC after: 1 week
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D61048
(cherry picked from commit 35cd70490f4b7ec1921db980ae3992192e4cbfbb)
---
libexec/tftpd/tftp-options.c | 29 ++++++++++++++---------------
libexec/tftpd/tftp-options.h | 6 +++---
2 files changed, 17 insertions(+), 18 deletions(-)
diff --git a/libexec/tftpd/tftp-options.c b/libexec/tftpd/tftp-options.c
index 7a261ac3d7c3..609ed98a7545 100644
--- a/libexec/tftpd/tftp-options.c
+++ b/libexec/tftpd/tftp-options.c
@@ -365,13 +365,12 @@ option_windowsize(int peer)
/*
* Append the available options to the header
*/
-uint16_t
-make_options(int peer __unused, char *buffer, uint16_t size) {
- int i;
+size_t
+make_options(int peer __unused, char *buffer, size_t size)
+{
char *value;
const char *option;
- uint16_t length;
- uint16_t returnsize = 0;
+ size_t i, length, returnsize = 0;
if (!options_rfc_enabled) return (0);
@@ -392,7 +391,7 @@ make_options(int peer __unused, char *buffer, uint16_t size) {
tftp_log(LOG_ERR,
"Running out of option space for "
"option '%s' with value '%s': "
- "needed %d bytes, got %d bytes",
+ "needed %zu bytes, got %zu bytes",
option, value, size, length);
continue;
}
@@ -410,24 +409,26 @@ make_options(int peer __unused, char *buffer, uint16_t size) {
* Parse the received options in the header
*/
int
-parse_options(int peer, char *buffer, uint16_t size)
+parse_options(int peer, char *buffer, size_t size)
{
+ char *c, *cp, *end, *option, *value;
+ size_t len;
int i, options_failed;
- char *c, *cp, *option, *value;
if (!options_rfc_enabled) return (0);
/* Parse the options */
cp = buffer;
+ end = buffer + size;
options_failed = 0;
- while (size > 0) {
+ while (cp < end) {
option = cp;
- i = get_field(peer, cp, size);
- cp += i;
+ len = get_field(peer, cp, end - cp);
+ cp += len;
value = cp;
- i = get_field(peer, cp, size);
- cp += i;
+ len = get_field(peer, cp, end - cp);
+ cp += len;
/* We are at the end */
if (*option == '\0') break;
@@ -459,8 +460,6 @@ parse_options(int peer, char *buffer, uint16_t size)
if (options[i].o_type == NULL)
tftp_log(LOG_WARNING,
"Unknown option: '%s'", option);
-
- size -= strlen(option) + strlen(value) + 2;
}
return (options_failed);
diff --git a/libexec/tftpd/tftp-options.h b/libexec/tftpd/tftp-options.h
index f1b0a5cfaf32..26f0191b1542 100644
--- a/libexec/tftpd/tftp-options.h
+++ b/libexec/tftpd/tftp-options.h
@@ -29,9 +29,9 @@
* Options
*/
-void init_options(void);
-uint16_t make_options(int peer, char *buffer, uint16_t size);
-int parse_options(int peer, char *buffer, uint16_t size);
+void init_options(void);
+size_t make_options(int peer, char *buffer, size_t size);
+int parse_options(int peer, char *buffer, size_t size);
/* Call back functions */
int option_tsize(int peer, struct tftphdr *, int, struct stat *);