68076c
# Fix implicit declaration of function 'bsd_signal'; did you mean 'ssignal'?
68076c
#
68076c
# On sufficiently new glibc, signal with defined _DEFAULT_SOURCE is equivalent
68076c
# to bsd_signal.
68076c
--- a/config.h	2022-03-26 01:45:23.602395248 +0100
68076c
+++ b/config.h	2022-03-26 01:45:01.076491553 +0100
68076c
@@ -294,9 +294,6 @@
68076c
 void *xrealloc(void *, size_t);
68076c
 char *xstrdup(const char *);
68076c
 
68076c
-#ifndef HAVE_BSD_SIGNAL
68076c
-void (*bsd_signal(int, void (*)(int))) (int);
68076c
-#endif
68076c
 #ifndef HAVE_DUP2
68076c
 int dup2(int, int);
68076c
 #endif
68076c
--- a/configure.in	2022-03-26 01:56:06.656577548 +0100
68076c
+++ b/configure.in	2022-03-26 01:56:04.739068636 +0100
68076c
@@ -160,7 +160,6 @@
68076c
 PA_SEARCH_LIBS_AND_ADD(xmalloc, iberty)
68076c
 PA_SEARCH_LIBS_AND_ADD(xrealloc, iberty)
68076c
 PA_SEARCH_LIBS_AND_ADD(xstrdup, iberty)
68076c
-PA_SEARCH_LIBS_AND_ADD(bsd_signal, bsd, bsdsignal)
68076c
 PA_SEARCH_LIBS_AND_ADD(getopt_long, getopt, getopt_long)
68076c
 PA_SEARCH_LIBS_AND_ADD(getaddrinfo, [nsl resolv])
68076c
 if $pa_add_getaddrinfo
68076c
diff --git a/tftp/main.c b/tftp/main.c
68076c
index b2f9059..d658230 100644
68076c
--- a/tftp/main.c
68076c
+++ b/tftp/main.c
68076c
@@ -305,7 +305,7 @@ int main(int argc, char *argv[])
68076c
         sp->s_proto = (char *)"udp";
68076c
     }
68076c
 
68076c
-    bsd_signal(SIGINT, intr);
68076c
+    signal(SIGINT, intr);
68076c
 
68076c
     if (peerargc) {
68076c
         /* Set peer */
68076c
@@ -768,7 +768,7 @@ void intr(int sig)
68076c
 {
68076c
     (void)sig;                  /* Quiet unused warning */
68076c
 
68076c
-    bsd_signal(SIGALRM, SIG_IGN);
68076c
+    signal(SIGALRM, SIG_IGN);
68076c
     alarm(0);
68076c
     siglongjmp(toplevel, -1);
68076c
 }
68076c
diff --git a/tftp/tftp.c b/tftp/tftp.c
68076c
index d15da22..52f5be0 100644
68076c
--- a/tftp/tftp.c
68076c
+++ b/tftp/tftp.c
68076c
@@ -85,7 +85,7 @@ void tftp_sendfile(int fd, const char *name, const char *mode)
68076c
     is_request = 1;             /* First packet is the actual WRQ */
68076c
     amount = 0;
68076c
 
68076c
-    bsd_signal(SIGALRM, timer);
68076c
+    signal(SIGALRM, timer);
68076c
     do {
68076c
         if (is_request) {
68076c
             size = makerequest(WRQ, name, dp, mode) - 4;
68076c
@@ -191,7 +191,7 @@ void tftp_recvfile(int fd, const char *name, const char *mode)
68076c
     firsttrip = 1;
68076c
     amount = 0;
68076c
 
68076c
-    bsd_signal(SIGALRM, timer);
68076c
+    signal(SIGALRM, timer);
68076c
     do {
68076c
         if (firsttrip) {
68076c
             size = makerequest(RRQ, name, ap, mode);
68076c
68076c
# Fix leaked_handle: Handle variable "fd" going out of scope leaks the handle.
68076c
diff --git a/tftpd/tftpd.c b/tftpd/tftpd.c
68076c
index 364e7d2..cbd6093 100644
68076c
--- a/tftpd/tftpd.c
68076c
+++ b/tftpd/tftpd.c
68076c
@@ -1505,6 +1505,7 @@ static int validate_access(char *filename, int mode,
68076c
 
68076c
     if (mode == RRQ) {
68076c
         if (!unixperms && (stbuf.st_mode & (S_IREAD >> 6)) == 0) {
68076c
+            close(fd);
68076c
             *errmsg = "File must have global read permissions";
68076c
             return (EACCESS);
68076c
         }
68076c
@@ -1514,6 +1515,7 @@ static int validate_access(char *filename, int mode,
68076c
     } else {
68076c
         if (!unixperms) {
68076c
             if ((stbuf.st_mode & (S_IWRITE >> 6)) == 0) {
68076c
+                close(fd);
68076c
                 *errmsg = "File must have global write permissions";
68076c
                 return (EACCESS);
68076c
             }
68076c
@@ -1522,6 +1524,7 @@ static int validate_access(char *filename, int mode,
68076c
 #ifdef HAVE_FTRUNCATE
68076c
 	/* We didn't get to truncate the file at open() time */
68076c
 	if (ftruncate(fd, (off_t) 0)) {
68076c
+	  close(fd);
68076c
 	  *errmsg = "Cannot reset file size";
68076c
 	  return (EACCESS);
68076c
 	}
68076c
68076c
# Fix warnings about useless inline in int usage(int)
68076c
From 8ddf0d87d7463c21e28dd2bea6f3f42d4c92cb1d Mon Sep 17 00:00:00 2001
68076c
From: "H. Peter Anvin" <hpa@zytor.com>
68076c
Date: Sat, 7 Jun 2014 13:00:46 -0700
68076c
Subject: [PATCH] tftp: drop "inline" from definition of usage()
68076c
68076c
It is pointless and newer gcc say it is a lose.
68076c
68076c
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
68076c
---
68076c
 tftp/main.c | 2 +-
68076c
 1 file changed, 1 insertion(+), 1 deletion(-)
68076c
68076c
diff --git a/tftp/main.c b/tftp/main.c
68076c
index 1b8a881..b2f9059 100644
68076c
--- a/tftp/main.c
68076c
+++ b/tftp/main.c
68076c
@@ -188,7 +188,7 @@ char *xstrdup(const char *);
68076c
 
68076c
 const char *program;
68076c
 
68076c
-static inline void usage(int errcode)
68076c
+static void usage(int errcode)
68076c
 {
68076c
     fprintf(stderr,
68076c
 #ifdef HAVE_IPV6
68076c
-- 
68076c
2.35.1
68076c
68076c
# Fix Calling "setsockopt" without checking return value. This library
68076c
# function may fail and return an error code.
68076c
diff --git a/tftpd/recvfrom.c b/tftpd/recvfrom.c
68076c
index d7ef500..e0074d8 100644
68076c
--- a/tftpd/recvfrom.c
68076c
+++ b/tftpd/recvfrom.c
68076c
@@ -26,6 +26,7 @@
68076c
 
68076c
 #if defined(HAVE_RECVMSG) && defined(HAVE_MSGHDR_MSG_CONTROL)
68076c
 
68076c
+#include <syslog.h>
68076c
 #include <sys/uio.h>
68076c
 
68076c
 #ifdef IP_PKTINFO
68076c
@@ -151,16 +151,19 @@ myrecvfrom(int s, void *buf, int len, unsigned int flags,
68076c
     /* Try to enable getting the return address */
68076c
 #ifdef IP_RECVDSTADDR
68076c
     if (from->sa_family == AF_INET || !from->sa_family)
68076c
-        setsockopt(s, IPPROTO_IP, IP_RECVDSTADDR, &on, sizeof(on));
68076c
+        if (setsockopt(s, IPPROTO_IP, IP_RECVDSTADDR, &on, sizeof(on)) == -1)
68076c
+            syslog(LOG_ERR, "cannot setsockopt IP_RECVDSTADDR %m");
68076c
 #endif
68076c
 #ifdef IP_PKTINFO
68076c
     if (from->sa_family == AF_INET || !from->sa_family)
68076c
-        setsockopt(s, IPPROTO_IP, IP_PKTINFO, &on, sizeof(on));
68076c
+        if (setsockopt(s, IPPROTO_IP, IP_PKTINFO, &on, sizeof(on)) == -1)
68076c
+            syslog(LOG_ERR, "cannot setsockopt IP_PKTINFO %m");
68076c
 #endif
68076c
 #ifdef HAVE_IPV6
68076c
 #ifdef IPV6_RECVPKTINFO
68076c
     if (from->sa_family == AF_INET6 || !from->sa_family)
68076c
-        setsockopt(s, IPPROTO_IPV6, IPV6_RECVPKTINFO, &on, sizeof(on));
68076c
+        if (setsockopt(s, IPPROTO_IPV6, IPV6_RECVPKTINFO, &on, sizeof(on)) == -1)
68076c
+            syslog(LOG_ERR, "cannot setsockopt IPV6_RECVPKTINFO %m");
68076c
 #endif
68076c
 #endif
68076c
     bzero(&msg, sizeof msg);    /* Clear possible system-dependent fields */
68076c
diff --git a/tftpd/tftpd.c b/tftpd/tftpd.c
68076c
index 364e7d2..36d6dec 100644
68076c
--- a/tftpd/tftpd.c
68076c
+++ b/tftpd/tftpd.c
68076c
@@ -224,7 +224,9 @@ static void pmtu_discovery_off(int fd)
68076c
 #if defined(IP_MTU_DISCOVER) && defined(IP_PMTUDISC_DONT)
68076c
     int pmtu = IP_PMTUDISC_DONT;
68076c
 
68076c
-    setsockopt(fd, IPPROTO_IP, IP_MTU_DISCOVER, &pmtu, sizeof(pmtu));
68076c
+    if (setsockopt(fd, IPPROTO_IP, IP_MTU_DISCOVER, &pmtu, sizeof(pmtu)) == -1)
68076c
+        syslog(LOG_ERR, "cannot setsockopt IP_MTU_DISCOVER to "
68076c
+                        "IP_PMTUDISC_DONT %m");
68076c
 #endif
68076c
 }
68076c
 
68076c
# Fixes negative_returns: "fd" is passed to a parameter of pmtu_discovery_off
68076c
# that cannot be negative
68076c
From 0b44159b3a2f51d350f309d3f6d14a17e74e8231 Mon Sep 17 00:00:00 2001
68076c
From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Zaoral?= <lzaoral@redhat.com>
68076c
Date: Wed, 6 Apr 2022 09:33:33 +0200
68076c
Subject: [PATCH 1/2] tftpd: Correctly disable path MTU discovery in
68076c
 standalone mode
68076c
68076c
---
68076c
 tftpd/tftpd.c | 2 +-
68076c
 1 file changed, 1 insertion(+), 1 deletion(-)
68076c
68076c
diff --git a/tftpd/tftpd.c b/tftpd/tftpd.c
68076c
index 364e7d2..00fa1cf 100644
68076c
--- a/tftpd/tftpd.c
68076c
+++ b/tftpd/tftpd.c
68076c
@@ -769,7 +769,7 @@ int main(int argc, char **argv)
68076c
     }
68076c
 
68076c
     /* Disable path MTU discovery */
68076c
-    pmtu_discovery_off(fd);
68076c
+    pmtu_discovery_off(fdmax);
68076c
 
68076c
     /* This means we don't want to wait() for children */
68076c
 #ifdef SA_NOCLDWAIT
68076c
-- 
68076c
2.35.1
68076c
68076c
68076c
From 5f60355c4bd10b866847a0d58a9582bda7db72aa Mon Sep 17 00:00:00 2001
68076c
From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Zaoral?= <lzaoral@redhat.com>
68076c
Date: Wed, 6 Apr 2022 09:34:46 +0200
68076c
Subject: [PATCH 2/2] tftpd: Fix a possible usage of -1 file descriptor in
68076c
 standalone mode
68076c
68076c
---
68076c
 tftpd/tftpd.c | 7 +++++++
68076c
 1 file changed, 7 insertions(+)
68076c
68076c
diff --git a/tftpd/tftpd.c b/tftpd/tftpd.c
68076c
index 00fa1cf..afd595d 100644
68076c
--- a/tftpd/tftpd.c
68076c
+++ b/tftpd/tftpd.c
68076c
@@ -622,6 +622,13 @@ int main(int argc, char **argv)
68076c
                         exit(EX_USAGE);
68076c
                     }
68076c
                     ai_fam = AF_INET6;
68076c
+
68076c
+                    if (fd6 < 0) {
68076c
+                        syslog(LOG_ERR,
68076c
+                               "IPv6 was disabled but address %s is in address "
68076c
+                               "family AF_INET6", address);
68076c
+                        exit(EX_USAGE);
68076c
+                    }
68076c
                 }
68076c
                 break;
68076c
 #endif
68076c
-- 
68076c
2.35.1
68076c