From e2f93f13b1cf208149426a8dbe90072400733bf5 Mon Sep 17 00:00:00 2001 From: asomers Date: Fri, 3 Aug 2018 14:19:56 +0000 Subject: [PATCH] MFC r330720: tftpd: reject unknown opcodes If tftpd receives a command with an unknown opcode, it simply exits 1. It doesn't send an ERROR packet, and the client will hang waiting for one. Fix it. PR: 226005 git-svn-id: svn://svn.freebsd.org/base/stable/10@337250 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- libexec/tftpd/tests/functional.c | 1 - libexec/tftpd/tftpd.c | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/libexec/tftpd/tests/functional.c b/libexec/tftpd/tests/functional.c index f06346ffb..d36c52dc3 100644 --- a/libexec/tftpd/tests/functional.c +++ b/libexec/tftpd/tests/functional.c @@ -675,7 +675,6 @@ TFTPD_TC_DEFINE(unknown_opcode,) { /* Looks like an RRQ or WRQ request, but with a bad opcode */ SEND_STR("\0\007foo.txt\0octet\0"); - atf_tc_expect_timeout("PR 226005 tftpd ignores bad opcodes but doesn't reject them"); RECV_ERROR(4, "Illegal TFTP operation"); } diff --git a/libexec/tftpd/tftpd.c b/libexec/tftpd/tftpd.c index 677fff586..aaeede428 100644 --- a/libexec/tftpd/tftpd.c +++ b/libexec/tftpd/tftpd.c @@ -419,8 +419,7 @@ main(int argc, char *argv[]) "%s read access denied", peername); exit(1); } - } - if (tp->th_opcode == WRQ) { + } else if (tp->th_opcode == WRQ) { if (allow_wo) tftp_wrq(peer, tp->th_stuff, n - 1); else { @@ -428,7 +427,8 @@ main(int argc, char *argv[]) "%s write access denied", peername); exit(1); } - } + } else + send_error(peer, EBADOP); exit(1); } -- 2.42.0