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

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