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

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