Blame SOURCES/tftp-hpa-5.2-covscan.patch

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