From 825011ba5f75b71bef8db7ef029f992eea8c1316 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Zaoral?= Date: Fri, 5 Apr 2024 14:44:34 +0200 Subject: [PATCH] apply fixes to true positives reported by static analyzers from RHEL 9 Resolves: RHEL-25853 --- tftp-hpa-5.2-osh.patch | 91 ++++++++++++++++++++++++++++++++++++++++++ tftp.spec | 7 +++- 2 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 tftp-hpa-5.2-osh.patch diff --git a/tftp-hpa-5.2-osh.patch b/tftp-hpa-5.2-osh.patch new file mode 100644 index 0000000..4a955aa --- /dev/null +++ b/tftp-hpa-5.2-osh.patch @@ -0,0 +1,91 @@ +# Fix leaked_handle: Handle variable "fd" going out of scope leaks the handle. +diff --git a/tftpd/tftpd.c b/tftpd/tftpd.c +index 364e7d2..cbd6093 100644 +--- a/tftpd/tftpd.c ++++ b/tftpd/tftpd.c +@@ -1505,6 +1505,7 @@ static int validate_access(char *filename, int mode, + + if (mode == RRQ) { + if (!unixperms && (stbuf.st_mode & (S_IREAD >> 6)) == 0) { ++ close(fd); + *errmsg = "File must have global read permissions"; + return (EACCESS); + } +@@ -1514,6 +1515,7 @@ static int validate_access(char *filename, int mode, + } else { + if (!unixperms) { + if ((stbuf.st_mode & (S_IWRITE >> 6)) == 0) { ++ close(fd); + *errmsg = "File must have global write permissions"; + return (EACCESS); + } +@@ -1522,6 +1524,7 @@ static int validate_access(char *filename, int mode, + #ifdef HAVE_FTRUNCATE + /* We didn't get to truncate the file at open() time */ + if (ftruncate(fd, (off_t) 0)) { ++ close(fd); + *errmsg = "Cannot reset file size"; + return (EACCESS); + } + + +# Patches for negative_returns: "fd" is passed to a parameter of pmtu_discovery_off +# that cannot be negative +From 0b44159b3a2f51d350f309d3f6d14a17e74e8231 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Zaoral?= +Date: Wed, 6 Apr 2022 09:33:33 +0200 +Subject: [PATCH 1/2] tftpd: Correctly disable path MTU discovery in + standalone mode + +--- + tftpd/tftpd.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/tftpd/tftpd.c b/tftpd/tftpd.c +index 364e7d2..00fa1cf 100644 +--- a/tftpd/tftpd.c ++++ b/tftpd/tftpd.c +@@ -769,7 +769,7 @@ int main(int argc, char **argv) + } + + /* Disable path MTU discovery */ +- pmtu_discovery_off(fd); ++ pmtu_discovery_off(fdmax); + + /* This means we don't want to wait() for children */ + #ifdef SA_NOCLDWAIT +-- +2.35.1 + + +From 5f60355c4bd10b866847a0d58a9582bda7db72aa Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Zaoral?= +Date: Wed, 6 Apr 2022 09:34:46 +0200 +Subject: [PATCH 2/2] tftpd: Fix a possible usage of -1 file descriptor in + standalone mode + +--- + tftpd/tftpd.c | 7 +++++++ + 1 file changed, 7 insertions(+) + +diff --git a/tftpd/tftpd.c b/tftpd/tftpd.c +index 00fa1cf..afd595d 100644 +--- a/tftpd/tftpd.c ++++ b/tftpd/tftpd.c +@@ -622,6 +622,13 @@ int main(int argc, char **argv) + exit(EX_USAGE); + } + ai_fam = AF_INET6; ++ ++ if (fd6 < 0) { ++ syslog(LOG_ERR, ++ "IPv6 was disabled but address %s is in address " ++ "family AF_INET6", address); ++ exit(EX_USAGE); ++ } + } + break; + #endif +-- +2.35.1 + diff --git a/tftp.spec b/tftp.spec index 0a02498..83b4628 100644 --- a/tftp.spec +++ b/tftp.spec @@ -3,7 +3,7 @@ Summary: The client for the Trivial File Transfer Protocol (TFTP) Name: tftp Version: 5.2 -Release: 42%{?dist} +Release: 43%{?dist} License: BSD-4-Clause-UC URL: http://www.kernel.org/pub/software/network/tftp/ Source0: http://www.kernel.org/pub/software/network/tftp/tftp-hpa/tftp-hpa-%{version}.tar.bz2 @@ -23,6 +23,7 @@ Patch10: tftp-enhanced-logging.patch Patch11: tftp-hpa-5.2-gcc10.patch Patch12: tftp-off-by-one.patch Patch13: tftp-c99.patch +Patch14: tftp-hpa-5.2-osh.patch BuildRequires: autoconf BuildRequires: gcc @@ -66,6 +67,7 @@ systemd socket activation, and is disabled by default. %patch11 -p1 -b .gcc10 %patch12 -p1 -b .off-by-one %patch13 -p1 +%patch14 -p1 -b .osh %build autoreconf @@ -108,6 +110,9 @@ install -p -m 644 %SOURCE2 ${RPM_BUILD_ROOT}%{_unitdir} %{_unitdir}/* %changelog +* Fri Apr 05 2024 Lukáš Zaoral - 5.2-43 +- apply fixes to true positives reported by static analyzers from RHEL 9 (RHEL-25853) + * Sat Jan 27 2024 Fedora Release Engineering - 5.2-42 - Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild