Blame SOURCES/001-review-of-CWE-170-CWE-772.patch

b974d2
From 4bbfd43121e4c1f59074b1b0def9804c1890b2dc Mon Sep 17 00:00:00 2001
b974d2
From: Jan Macku <jamacku@redhat.com>
b974d2
Date: Mon, 19 Jul 2021 09:48:19 +0200
b974d2
Subject: [PATCH] review of CWE-170, CWE-772
b974d2
b974d2
Resolves: #1938887
b974d2
---
b974d2
 libsupp/clif.c          | 2 ++
b974d2
 traceroute/traceroute.c | 7 ++++++-
b974d2
 2 files changed, 8 insertions(+), 1 deletion(-)
b974d2
b974d2
diff --git a/libsupp/clif.c b/libsupp/clif.c
b974d2
index 4ef20e4..60ec291 100644
b974d2
--- a/libsupp/clif.c
b974d2
+++ b/libsupp/clif.c
b974d2
@@ -229,10 +229,12 @@ static void err_bad_arg (const CLIF_option *optn, char c, int n) {
b974d2
 
b974d2
 	if (c) {
b974d2
 	    s = show_short (&tmp);	/*  always without arg...  */
b974d2
+	    /* coverity[buffer_size_warning] - not a bug, s ends with '\0', see line 97 */
b974d2
 	    strncpy (ss, s, sizeof (ss));
b974d2
 	    s = show_short (optn);
b974d2
 	} else {
b974d2
 	    s = show_long (&tmp);	/*  always without arg...  */
b974d2
+	    /* coverity[buffer_size_warning] - not a bug, s ends with '\0', see line 97 */
b974d2
 	    strncpy (ss, s, sizeof (ss));
b974d2
 	    s = show_long (optn);
b974d2
 	}
b974d2
diff --git a/traceroute/traceroute.c b/traceroute/traceroute.c
b974d2
index 4be9b24..0a29e36 100644
b974d2
--- a/traceroute/traceroute.c
b974d2
+++ b/traceroute/traceroute.c
b974d2
@@ -217,8 +217,12 @@ static int getaddr (const char *name, sockaddr_any *addr) {
b974d2
 	}
b974d2
 	if (!ai)  ai = res;	/*  anything...  */
b974d2
 
b974d2
-	if (ai->ai_addrlen > sizeof (*addr))
b974d2
+	if (ai->ai_addrlen > sizeof (*addr)) {
b974d2
+		/* Avoid of leaking res (CWE-772) */
b974d2
+		freeaddrinfo (res);
b974d2
 		return -1;	/*  paranoia   */
b974d2
+	}
b974d2
+
b974d2
 	memcpy (addr, ai->ai_addr, ai->ai_addrlen);
b974d2
 
b974d2
 	freeaddrinfo (res);
b974d2
@@ -244,6 +248,7 @@ static void make_fd_used (int fd) {
b974d2
 	    close (nfd);
b974d2
 	}
b974d2
 
b974d2
+	/* coverity[leaked_handle] - not a bug, see line 665 */
b974d2
 	return;
b974d2
 }
b974d2
 
b974d2
-- 
b974d2
2.31.1
b974d2