git: 5d0e1aee4c52 - stable/14 - tftpd: Keep proper track of header length
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 16 Nov 2026 15:17:55 UTC
The branch stable/14 has been updated by des:
URL: https://cgit.FreeBSD.org/src/commit/?id=5d0e1aee4c52d2cf3959263cf3b777785ac038a1
commit 5d0e1aee4c52d2cf3959263cf3b777785ac038a1
Author: Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-11-11 19:45:18 +0000
Commit: Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-11-16 14:52:03 +0000
tftpd: Keep proper track of header length
When parsing a header, keep track of the length of the unparsed portion
and pass that to get_field() instead of the length of the entire header.
Reported by: n0ps1ed
MFC after: 1 week
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D60902
(cherry picked from commit 579e428a551a11b43e341297dd0ef9d38c4fcda7)
---
libexec/tftpd/tftpd.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/libexec/tftpd/tftpd.c b/libexec/tftpd/tftpd.c
index d27054b757f8..43e892f605bf 100644
--- a/libexec/tftpd/tftpd.c
+++ b/libexec/tftpd/tftpd.c
@@ -471,23 +471,24 @@ parse_header(int peer, char *recvbuffer, size_t size,
char **filename, char **mode)
{
struct formats *pf;
- char *cp;
- size_t i;
+ char *cp, *end;
+ size_t len;
*mode = NULL;
cp = recvbuffer;
+ end = recvbuffer + size;
- i = get_field(peer, recvbuffer, size);
- if (i >= PATH_MAX) {
+ len = get_field(peer, cp, end - cp);
+ if (len >= PATH_MAX) {
tftp_log(LOG_ERR, "Bad option - filename too long");
send_error(peer, EBADOP);
exit(1);
}
*filename = recvbuffer;
tftp_log(LOG_INFO, "Filename: '%s'", *filename);
- cp += i;
+ cp += len;
- i = get_field(peer, cp, size);
+ len = get_field(peer, cp, end - cp);
*mode = cp;
/* Find the file transfer mode */