From d152e81e42c82ab9211141c73b0c1fc304c97106 Mon Sep 17 00:00:00 2001 From: Simon Kelley Date: Mon, 30 Mar 2026 21:18:11 +0100 Subject: [PATCH] Tighten check on TFTP pathnames to avoid directory escape. --- src/tftp.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/tftp.c b/src/tftp.c index 966e696..b035a43 100644 --- a/src/tftp.c +++ b/src/tftp.c @@ -545,8 +545,13 @@ static struct tftp_file *check_tftp_fileperm(char *packet, ssize_t *len, char *p int fd = -1; /* trick to ban moving out of the subtree */ - if (prefix && strstr(namebuff, "/../")) - goto perm; + if (prefix) + { + char *suspect = strstr(namebuff, "/.."); + + if (suspect && (suspect[3] == '/' || suspect[3] == 0)) + goto perm; + } if ((fd = open(namebuff, O_RDONLY)) == -1) {