git: 14541ca2bf37 - main - tftpd: Fix off-by-one in get_field()
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 11 Nov 2026 19:46:00 UTC
The branch main has been updated by des:
URL: https://cgit.FreeBSD.org/src/commit/?id=14541ca2bf3766e659a22c5ea9ed3dc2d5f11fa5
commit 14541ca2bf3766e659a22c5ea9ed3dc2d5f11fa5
Author: Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-11-11 19:45:14 +0000
Commit: Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-11-11 19:45:14 +0000
tftpd: Fix off-by-one in get_field()
Due to a logic error, get_field() would behave as if the passed-in size
was one greater than it actually is. Fix it so it always fails if no
terminating NUL is found within the buffer, instead of succeeding if the
first byte past the end is a NUL.
MFC after: 1 week
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D61032
---
libexec/tftpd/tftp-utils.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/libexec/tftpd/tftp-utils.c b/libexec/tftpd/tftp-utils.c
index 8ce7c09c9992..9cda798462e6 100644
--- a/libexec/tftpd/tftp-utils.c
+++ b/libexec/tftpd/tftp-utils.c
@@ -109,16 +109,15 @@ get_field(int peer, char *buffer, size_t size)
{
char *cp = buffer;
- while (cp < buffer + size) {
- if (*cp == '\0') break;
+ while (size > 0) {
+ if (*cp == '\0')
+ return (cp - buffer + 1);
cp++;
+ size--;
}
- if (*cp != '\0') {
- tftp_log(LOG_ERR, "Bad option - no trailing \\0 found");
- send_error(peer, EBADOP);
- exit(1);
- }
- return (cp - buffer + 1);
+ tftp_log(LOG_ERR, "Bad option - no trailing \\0 found");
+ send_error(peer, EBADOP);
+ exit(1);
}
/*