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

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