kentpeacock / rpms / openssh

Forked from rpms/openssh 2 years ago
Clone
943807
diff -up openssh-8.5p1/addr.c.coverity openssh-8.5p1/addr.c
943807
--- openssh-8.5p1/addr.c.coverity	2021-03-02 11:31:47.000000000 +0100
943807
+++ openssh-8.5p1/addr.c	2021-03-24 12:03:33.782968159 +0100
943807
@@ -312,8 +312,10 @@ addr_pton(const char *p, struct xaddr *n
943807
 	if (p == NULL || getaddrinfo(p, NULL, &hints, &ai) != 0)
943807
 		return -1;
943807
 
943807
-	if (ai == NULL || ai->ai_addr == NULL)
943807
+	if (ai == NULL || ai->ai_addr == NULL) {
943807
+		freeaddrinfo(ai);
943807
 		return -1;
943807
+	}
943807
 
943807
 	if (n != NULL && addr_sa_to_xaddr(ai->ai_addr, ai->ai_addrlen,
943807
 	    n) == -1) {
943807
@@ -336,12 +338,16 @@ addr_sa_pton(const char *h, const char *
943807
 	if (h == NULL || getaddrinfo(h, s, &hints, &ai) != 0)
943807
 		return -1;
943807
 
943807
-	if (ai == NULL || ai->ai_addr == NULL)
943807
+	if (ai == NULL || ai->ai_addr == NULL) {
943807
+		freeaddrinfo(ai);
943807
 		return -1;
943807
+	}
943807
 
943807
 	if (sa != NULL) {
943807
-		if (slen < ai->ai_addrlen)
943807
+		if (slen < ai->ai_addrlen) {
943807
+			freeaddrinfo(ai);
943807
 			return -1;
943807
+		}
943807
 		memcpy(sa, &ai->ai_addr, ai->ai_addrlen);
943807
 	}
943807
 
943807
diff -up openssh-8.5p1/auth-krb5.c.coverity openssh-8.5p1/auth-krb5.c
943807
--- openssh-8.5p1/auth-krb5.c.coverity	2021-03-24 12:03:33.724967756 +0100
943807
+++ openssh-8.5p1/auth-krb5.c	2021-03-24 12:03:33.782968159 +0100
943807
@@ -426,6 +426,7 @@ ssh_krb5_cc_new_unique(krb5_context ctx,
943807
 		umask(old_umask);
943807
 		if (tmpfd == -1) {
943807
 			logit("mkstemp(): %.100s", strerror(oerrno));
943807
+			free(ccname);
943807
 			return oerrno;
943807
 		}
943807
 
943807
@@ -433,6 +434,7 @@ ssh_krb5_cc_new_unique(krb5_context ctx,
943807
 			oerrno = errno;
943807
 			logit("fchmod(): %.100s", strerror(oerrno));
943807
 			close(tmpfd);
943807
+			free(ccname);
943807
 			return oerrno;
943807
 		}
943807
 		/* make sure the KRB5CCNAME is set for non-standard location */
943807
diff -up openssh-8.5p1/auth-options.c.coverity openssh-8.5p1/auth-options.c
943807
--- openssh-8.5p1/auth-options.c.coverity	2021-03-02 11:31:47.000000000 +0100
943807
+++ openssh-8.5p1/auth-options.c	2021-03-24 12:03:33.782968159 +0100
943807
@@ -706,6 +708,7 @@ serialise_array(struct sshbuf *m, char *
943807
 		return r;
943807
 	}
943807
 	/* success */
943807
+	sshbuf_free(b);
943807
 	return 0;
943807
 }
943807
 
943807
diff -up openssh-7.4p1/channels.c.coverity openssh-7.4p1/channels.c
943807
--- openssh-7.4p1/channels.c.coverity	2016-12-23 16:40:26.881788686 +0100
943807
+++ openssh-7.4p1/channels.c	2016-12-23 16:42:36.244818763 +0100
943807
@@ -1875,7 +1875,7 @@ channel_post_connecting(struct ssh *ssh,
943807
 		debug("channel %d: connection failed: %s",
943807
 		    c->self, strerror(err));
943807
 		/* Try next address, if any */
943807
-		if ((sock = connect_next(&c->connect_ctx)) > 0) {
943807
+		if ((sock = connect_next(&c->connect_ctx)) >= 0) {
943807
 			close(c->sock);
943807
 			c->sock = c->rfd = c->wfd = sock;
943807
 			channel_find_maxfd(ssh->chanctxt);
943807
@@ -3804,7 +3804,7 @@ int
943807
 channel_request_remote_forwarding(struct ssh *ssh, struct Forward *fwd)
943807
 {
943807
 	int r, success = 0, idx = -1;
943807
-	char *host_to_connect, *listen_host, *listen_path;
943807
+	char *host_to_connect = NULL, *listen_host = NULL, *listen_path = NULL;
943807
 	int port_to_connect, listen_port;
943807
 
943807
 	/* Send the forward request to the remote side. */
943807
@@ -3832,7 +3832,6 @@ channel_request_remote_forwarding(struct
943807
 	success = 1;
943807
 	if (success) {
943807
 		/* Record that connection to this host/port is permitted. */
943807
-		host_to_connect = listen_host = listen_path = NULL;
943807
 		port_to_connect = listen_port = 0;
943807
 		if (fwd->connect_path != NULL) {
943807
 			host_to_connect = xstrdup(fwd->connect_path);
943807
@@ -3853,6 +3852,9 @@ channel_request_remote_forwarding(struct
943807
 		    host_to_connect, port_to_connect,
943807
 		    listen_host, listen_path, listen_port, NULL);
943807
 	}
943807
+	free(host_to_connect);
943807
+	free(listen_host);
943807
+	free(listen_path);
943807
 	return idx;
943807
 }
943807
 
943807
diff -up openssh-8.5p1/compat.c.coverity openssh-8.5p1/compat.c
943807
--- openssh-8.5p1/compat.c.coverity	2021-03-24 12:03:33.768968062 +0100
943807
+++ openssh-8.5p1/compat.c	2021-03-24 12:03:33.783968166 +0100
943807
@@ -191,10 +191,12 @@ compat_kex_proposal(struct ssh *ssh, cha
943807
 		return p;
943807
 	debug2_f("original KEX proposal: %s", p);
943807
 	if ((ssh->compat & SSH_BUG_CURVE25519PAD) != 0)
943807
+		/* coverity[overwrite_var : FALSE] */
943807
 		if ((p = match_filter_denylist(p,
943807
 		    "curve25519-sha256@libssh.org")) == NULL)
943807
 			fatal("match_filter_denylist failed");
943807
 	if ((ssh->compat & SSH_OLD_DHGEX) != 0) {
943807
+		/* coverity[overwrite_var : FALSE] */
943807
 		if ((p = match_filter_denylist(p,
943807
 		    "diffie-hellman-group-exchange-sha256,"
943807
 		    "diffie-hellman-group-exchange-sha1")) == NULL)
943807
diff -up openssh-8.5p1/dns.c.coverity openssh-8.5p1/dns.c
943807
--- openssh-8.5p1/dns.c.coverity	2021-03-02 11:31:47.000000000 +0100
943807
+++ openssh-8.5p1/dns.c	2021-03-24 12:03:33.783968166 +0100
943807
@@ -282,6 +282,7 @@ verify_host_key_dns(const char *hostname
5dbb6f
		    &hostkey_digest, &hostkey_digest_len, hostkey)) {
5dbb6f
			error("Error calculating key fingerprint.");
5dbb6f
			freerrset(fingerprints);
943807
+				free(dnskey_digest);
5dbb6f
			return -1;
5dbb6f
		}
5dbb6f
943807
diff -up openssh-8.5p1/gss-genr.c.coverity openssh-8.5p1/gss-genr.c
943807
--- openssh-8.5p1/gss-genr.c.coverity	2021-03-26 11:52:46.613942552 +0100
943807
+++ openssh-8.5p1/gss-genr.c	2021-03-26 11:54:37.881726318 +0100
943807
@@ -167,8 +167,9 @@ ssh_gssapi_kex_mechs(gss_OID_set gss_sup
943807
 			enclen = __b64_ntop(digest,
943807
 			    ssh_digest_bytes(SSH_DIGEST_MD5), encoded,
943807
 			    ssh_digest_bytes(SSH_DIGEST_MD5) * 2);
943807
-
943807
+#pragma GCC diagnostic ignored "-Wstringop-overflow"
943807
 			cp = strncpy(s, kex, strlen(kex));
943807
+#pragma pop
943807
 			for ((p = strsep(&cp, ",")); p && *p != '\0';
943807
 				(p = strsep(&cp, ","))) {
943807
 				if (sshbuf_len(buf) != 0 &&
943807
diff -up openssh-8.5p1/krl.c.coverity openssh-8.5p1/krl.c
943807
--- openssh-8.5p1/krl.c.coverity	2021-03-02 11:31:47.000000000 +0100
943807
+++ openssh-8.5p1/krl.c	2021-03-24 12:03:33.783968166 +0100
943807
@@ -1209,6 +1209,7 @@ ssh_krl_from_blob(struct sshbuf *buf, st
943807
 	sshkey_free(key);
943807
 	sshbuf_free(copy);
943807
 	sshbuf_free(sect);
943807
+	/* coverity[leaked_storage : FALSE] */
943807
 	return r;
943807
 }
943807
 
943807
@@ -1261,6 +1262,7 @@ is_key_revoked(struct ssh_krl *krl, cons
943807
 		return r;
943807
 	erb = RB_FIND(revoked_blob_tree, &krl->revoked_sha1s, &rb);
943807
 	free(rb.blob);
943807
+	rb.blob = NULL; /* make coverity happy */
943807
 	if (erb != NULL) {
943807
 		KRL_DBG(("revoked by key SHA1"));
943807
 		return SSH_ERR_KEY_REVOKED;
943807
@@ -1271,6 +1273,7 @@ is_key_revoked(struct ssh_krl *krl, cons
943807
 		return r;
943807
 	erb = RB_FIND(revoked_blob_tree, &krl->revoked_sha256s, &rb);
943807
 	free(rb.blob);
943807
+	rb.blob = NULL; /* make coverity happy */
943807
 	if (erb != NULL) {
943807
 		KRL_DBG(("revoked by key SHA256"));
943807
 		return SSH_ERR_KEY_REVOKED;
943807
@@ -1282,6 +1285,7 @@ is_key_revoked(struct ssh_krl *krl, cons
943807
 		return r;
943807
 	erb = RB_FIND(revoked_blob_tree, &krl->revoked_keys, &rb);
943807
 	free(rb.blob);
943807
+	rb.blob = NULL; /* make coverity happy */
943807
 	if (erb != NULL) {
943807
 		KRL_DBG(("revoked by explicit key"));
943807
 		return SSH_ERR_KEY_REVOKED;
943807
diff -up openssh-8.5p1/loginrec.c.coverity openssh-8.5p1/loginrec.c
943807
--- openssh-8.5p1/loginrec.c.coverity	2021-03-24 13:18:53.793225885 +0100
943807
+++ openssh-8.5p1/loginrec.c	2021-03-24 13:21:27.948404751 +0100
943807
@@ -690,9 +690,11 @@ construct_utmp(struct logininfo *li,
943807
 	 */
943807
 
943807
 	/* Use strncpy because we don't necessarily want null termination */
943807
+	/* coverity[buffer_size_warning : FALSE] */
943807
 	strncpy(ut->ut_name, li->username,
943807
 	    MIN_SIZEOF(ut->ut_name, li->username));
943807
 # ifdef HAVE_HOST_IN_UTMP
943807
+	/* coverity[buffer_size_warning : FALSE] */
943807
 	strncpy(ut->ut_host, li->hostname,
943807
 	    MIN_SIZEOF(ut->ut_host, li->hostname));
943807
 # endif
943807
@@ -1690,6 +1692,7 @@ record_failed_login(struct ssh *ssh, con
943807
 
943807
 	memset(&ut, 0, sizeof(ut));
943807
 	/* strncpy because we don't necessarily want nul termination */
943807
+	/* coverity[buffer_size_warning : FALSE] */
943807
 	strncpy(ut.ut_user, username, sizeof(ut.ut_user));
943807
 	strlcpy(ut.ut_line, "ssh:notty", sizeof(ut.ut_line));
943807
 
943807
@@ -1699,6 +1702,7 @@ record_failed_login(struct ssh *ssh, con
943807
 	ut.ut_pid = getpid();
943807
 
943807
 	/* strncpy because we don't necessarily want nul termination */
943807
+	/* coverity[buffer_size_warning : FALSE] */
943807
 	strncpy(ut.ut_host, hostname, sizeof(ut.ut_host));
943807
 
943807
 	if (ssh_packet_connection_is_on_socket(ssh) &&
943807
diff -up openssh-8.5p1/misc.c.coverity openssh-8.5p1/misc.c
943807
--- openssh-8.5p1/misc.c.coverity	2021-03-24 12:03:33.745967902 +0100
943807
+++ openssh-8.5p1/misc.c	2021-03-24 13:31:47.037079617 +0100
943807
@@ -1425,6 +1425,8 @@ sanitise_stdfd(void)
943807
 	}
943807
 	if (nullfd > STDERR_FILENO)
943807
 		close(nullfd);
943807
+	/* coverity[leaked_handle : FALSE]*/
943807
+	/* coverity[leaked_handle : FALSE]*/
943807
 }
943807
 
943807
 char *
943807
@@ -2511,6 +2513,7 @@ stdfd_devnull(int do_stdin, int do_stdou
943807
 	}
943807
 	if (devnull > STDERR_FILENO)
943807
 		close(devnull);
943807
+	/* coverity[leaked_handle : FALSE]*/
943807
 	return ret;
943807
 }
943807
 
943807
diff -up openssh-8.5p1/moduli.c.coverity openssh-8.5p1/moduli.c
943807
--- openssh-8.5p1/moduli.c.coverity	2021-03-02 11:31:47.000000000 +0100
943807
+++ openssh-8.5p1/moduli.c	2021-03-24 12:03:33.784968173 +0100
943807
@@ -476,6 +476,7 @@ write_checkpoint(char *cpfile, u_int32_t
943807
 	else
943807
 		logit("failed to write to checkpoint file '%s': %s", cpfile,
943807
 		    strerror(errno));
943807
+	/* coverity[leaked_storage : FALSE] */
943807
 }
943807
 
943807
 static unsigned long
943807
diff -up openssh-7.4p1/monitor.c.coverity openssh-7.4p1/monitor.c
943807
--- openssh-7.4p1/monitor.c.coverity	2016-12-23 16:40:26.888788688 +0100
943807
+++ openssh-7.4p1/monitor.c	2016-12-23 16:40:26.900788691 +0100
943807
@@ -411,7 +411,7 @@ monitor_child_preauth(Authctxt *_authctx
943807
 	mm_get_keystate(ssh, pmonitor);
943807
 
943807
 	/* Drain any buffered messages from the child */
943807
-	while (pmonitor->m_log_recvfd != -1 && monitor_read_log(pmonitor) == 0)
943807
+	while (pmonitor->m_log_recvfd >= 0 && monitor_read_log(pmonitor) == 0)
943807
 		;
943807
 
943807
 	if (pmonitor->m_recvfd >= 0)
943807
@@ -1678,7 +1678,7 @@ mm_answer_pty(struct ssh *ssh, int sock,
943807
 	s->ptymaster = s->ptyfd;
943807
 
943807
 	debug3_f("tty %s ptyfd %d", s->tty, s->ttyfd);
943807
-
943807
+	/* coverity[leaked_handle : FALSE] */
943807
 	return (0);
943807
 
943807
  error:
943807
diff -up openssh-7.4p1/monitor_wrap.c.coverity openssh-7.4p1/monitor_wrap.c
943807
--- openssh-7.4p1/monitor_wrap.c.coverity	2016-12-23 16:40:26.892788689 +0100
943807
+++ openssh-7.4p1/monitor_wrap.c	2016-12-23 16:40:26.900788691 +0100
943807
@@ -525,10 +525,10 @@ mm_pty_allocate(int *ptyfd, int *ttyfd,
943807
 	if ((tmp1 = dup(pmonitor->m_recvfd)) == -1 ||
943807
 	    (tmp2 = dup(pmonitor->m_recvfd)) == -1) {
943807
 		error_f("cannot allocate fds for pty");
943807
-		if (tmp1 > 0)
943807
+		if (tmp1 >= 0)
943807
 			close(tmp1);
943807
-		if (tmp2 > 0)
943807
-			close(tmp2);
943807
+		/*DEAD CODE if (tmp2 >= 0)
943807
+			close(tmp2);*/
943807
 		return 0;
943807
 	}
943807
 	close(tmp1);
943807
diff -up openssh-7.4p1/openbsd-compat/bindresvport.c.coverity openssh-7.4p1/openbsd-compat/bindresvport.c
943807
--- openssh-7.4p1/openbsd-compat/bindresvport.c.coverity	2016-12-19 05:59:41.000000000 +0100
943807
+++ openssh-7.4p1/openbsd-compat/bindresvport.c	2016-12-23 16:40:26.901788691 +0100
943807
@@ -58,7 +58,7 @@ bindresvport_sa(int sd, struct sockaddr
943807
 	struct sockaddr_in6 *in6;
943807
 	u_int16_t *portp;
943807
 	u_int16_t port;
943807
-	socklen_t salen;
943807
+	socklen_t salen = sizeof(struct sockaddr_storage);
943807
 	int i;
943807
 
943807
 	if (sa == NULL) {
5dbb6f
diff -up openssh-8.7p1/openbsd-compat/bsd-pselect.c.coverity openssh-8.7p1/openbsd-compat/bsd-pselect.c
5dbb6f
--- openssh-8.7p1/openbsd-compat/bsd-pselect.c.coverity	2021-08-30 16:36:11.357288009 +0200
5dbb6f
+++ openssh-8.7p1/openbsd-compat/bsd-pselect.c	2021-08-30 16:37:21.791897976 +0200
5dbb6f
@@ -113,13 +113,13 @@ pselect_notify_setup(void)
5dbb6f
 static void
5dbb6f
 pselect_notify_parent(void)
5dbb6f
 {
5dbb6f
-	if (notify_pipe[1] != -1)
5dbb6f
+	if (notify_pipe[1] >= 0)
5dbb6f
 		(void)write(notify_pipe[1], "", 1);
5dbb6f
 }
5dbb6f
 static void
5dbb6f
 pselect_notify_prepare(fd_set *readset)
5dbb6f
 {
5dbb6f
-	if (notify_pipe[0] != -1)
5dbb6f
+	if (notify_pipe[0] >= 0)
5dbb6f
 		FD_SET(notify_pipe[0], readset);
5dbb6f
 }
5dbb6f
 static void
5dbb6f
@@ -127,8 +127,8 @@ pselect_notify_done(fd_set *readset)
5dbb6f
 {
5dbb6f
 	char c;
5dbb6f
 
5dbb6f
-	if (notify_pipe[0] != -1 && FD_ISSET(notify_pipe[0], readset)) {
5dbb6f
-		while (read(notify_pipe[0], &c, 1) != -1)
5dbb6f
+	if (notify_pipe[0] >= 0 && FD_ISSET(notify_pipe[0], readset)) {
5dbb6f
+		while (read(notify_pipe[0], &c, 1) >= 0)
5dbb6f
 			debug2_f("reading");
5dbb6f
 		FD_CLR(notify_pipe[0], readset);
5dbb6f
 	}
943807
diff -up openssh-8.5p1/readconf.c.coverity openssh-8.5p1/readconf.c
943807
--- openssh-8.5p1/readconf.c.coverity	2021-03-24 12:03:33.778968131 +0100
943807
+++ openssh-8.5p1/readconf.c	2021-03-24 12:03:33.785968180 +0100
943807
@@ -1847,6 +1847,7 @@ parse_pubkey_algos:
943807
 			} else if (r != 0) {
943807
 				error("%.200s line %d: glob failed for %s.",
943807
 				    filename, linenum, arg2);
943807
+				free(arg2);
5dbb6f
 				goto out;
943807
 			}
943807
 			free(arg2);
5dbb6f
diff -up openssh-8.7p1/scp.c.coverity openssh-8.7p1/scp.c
5dbb6f
--- openssh-8.7p1/scp.c.coverity	2021-08-30 16:23:35.389741329 +0200
5dbb6f
+++ openssh-8.7p1/scp.c	2021-08-30 16:27:04.854555296 +0200
5dbb6f
@@ -186,11 +186,11 @@ killchild(int signo)
943807
 {
943807
 	if (do_cmd_pid > 1) {
943807
 		kill(do_cmd_pid, signo ? signo : SIGTERM);
943807
-		waitpid(do_cmd_pid, NULL, 0);
943807
+		(void) waitpid(do_cmd_pid, NULL, 0);
943807
 	}
5dbb6f
 	if (do_cmd_pid2 > 1) {
5dbb6f
 		kill(do_cmd_pid2, signo ? signo : SIGTERM);
5dbb6f
-		waitpid(do_cmd_pid2, NULL, 0);
5dbb6f
+		(void) waitpid(do_cmd_pid2, NULL, 0);
5dbb6f
 	}
943807
 
943807
 	if (signo)
943807
diff -up openssh-7.4p1/servconf.c.coverity openssh-7.4p1/servconf.c
943807
--- openssh-7.4p1/servconf.c.coverity	2016-12-23 16:40:26.896788690 +0100
943807
+++ openssh-7.4p1/servconf.c	2016-12-23 16:40:26.901788691 +0100
943807
@@ -1638,8 +1638,9 @@ process_server_config_line(ServerOptions
943807
 		if (*activep && *charptr == NULL) {
943807
 			*charptr = tilde_expand_filename(arg, getuid());
943807
 			/* increase optional counter */
943807
-			if (intptr != NULL)
943807
-				*intptr = *intptr + 1;
943807
+			/* DEAD CODE intptr is still NULL ;)
943807
+  			 if (intptr != NULL)
943807
+				*intptr = *intptr + 1; */
943807
 		}
943807
 		break;
943807
 
5dbb6f
diff -up openssh-8.7p1/serverloop.c.coverity openssh-8.7p1/serverloop.c
5dbb6f
--- openssh-8.7p1/serverloop.c.coverity	2021-08-20 06:03:49.000000000 +0200
5dbb6f
+++ openssh-8.7p1/serverloop.c	2021-08-30 16:28:22.416226981 +0200
5dbb6f
@@ -547,7 +547,7 @@ server_request_tun(struct ssh *ssh)
943807
 		debug_f("invalid tun");
943807
 		goto done;
943807
 	}
943807
-	if (auth_opts->force_tun_device != -1) {
943807
+	if (auth_opts->force_tun_device >= 0) {
943807
 		if (tun != SSH_TUNID_ANY &&
943807
 		    auth_opts->force_tun_device != (int)tun)
943807
 			goto done;
943807
diff -up openssh-8.5p1/session.c.coverity openssh-8.5p1/session.c
943807
--- openssh-8.5p1/session.c.coverity	2021-03-24 12:03:33.777968124 +0100
943807
+++ openssh-8.5p1/session.c	2021-03-24 12:03:33.786968187 +0100
943807
@@ -1223,12 +1223,14 @@ do_setup_env(struct ssh *ssh, Session *s
943807
 	/* Environment specified by admin */
943807
 	for (i = 0; i < options.num_setenv; i++) {
943807
 		cp = xstrdup(options.setenv[i]);
943807
+		/* coverity[overwrite_var : FALSE] */
943807
 		if ((value = strchr(cp, '=')) == NULL) {
943807
 			/* shouldn't happen; vars are checked in servconf.c */
943807
 			fatal("Invalid config SetEnv: %s", options.setenv[i]);
943807
 		}
943807
 		*value++ = '\0';
943807
 		child_set_env(&env, &envsize, cp, value);
943807
+		free(cp);
943807
 	}
943807
 
943807
 	/* SSH_CLIENT deprecated */
943807
diff -up openssh-7.4p1/sftp.c.coverity openssh-7.4p1/sftp.c
943807
--- openssh-7.4p1/sftp.c.coverity	2016-12-19 05:59:41.000000000 +0100
943807
+++ openssh-7.4p1/sftp.c	2016-12-23 16:40:26.903788691 +0100
943807
@@ -224,7 +224,7 @@ killchild(int signo)
943807
 	pid = sshpid;
943807
 	if (pid > 1) {
943807
 		kill(pid, SIGTERM);
943807
-		waitpid(pid, NULL, 0);
943807
+		(void) waitpid(pid, NULL, 0);
943807
 	}
943807
 
943807
 	_exit(1);
943807
@@ -762,6 +762,8 @@ process_put(struct sftp_conn *conn, cons
943807
 			    fflag || global_fflag) == -1)
943807
 				err = -1;
943807
 		}
943807
+		free(abs_dst);
943807
+		abs_dst = NULL;
943807
 	}
943807
 
943807
 out:
943807
@@ -985,6 +987,7 @@ do_globbed_ls(struct sftp_conn *conn, co
943807
 		if (lflag & LS_LONG_VIEW) {
943807
 			if (g.gl_statv[i] == NULL) {
943807
 				error("no stat information for %s", fname);
943807
+				free(fname);
943807
 				continue;
943807
 			}
943807
 			lname = ls_file(fname, g.gl_statv[i], 1,
5dbb6f
diff --git a/sftp-client.c b/sftp-client.c
5dbb6f
index 9de9afa20f..ea98d9f8d0 100644
5dbb6f
--- a/sftp-client.c
5dbb6f
+++ b/sftp-client.c
5dbb6f
@@ -2195,6 +2195,7 @@ handle_dest_replies(struct sftp_conn *to, const char *to_path, int synchronous,
5dbb6f
 		(*nreqsp)--;
5dbb6f
 	}
5dbb6f
 	debug3_f("done: %u outstanding replies", *nreqsp);
5dbb6f
+	sshbuf_free(msg);
5dbb6f
 }
5dbb6f
 
5dbb6f
 int
5dbb6f
diff --git a/sftp-server.c b/sftp-server.c
5dbb6f
index 18d1949112..6380c4dd23 100644
5dbb6f
--- a/sftp-server.c
5dbb6f
+++ b/sftp-server.c
5dbb6f
@@ -1553,6 +1553,7 @@ process_extended_expand(u_int32_t id)
5dbb6f
 			npath = xstrdup(path + 2);
5dbb6f
 			free(path);
5dbb6f
 			xasprintf(&path, "%s/%s", cwd, npath);
5dbb6f
+			free(npath);
5dbb6f
 		} else {
5dbb6f
 			/* ~user expansions */
5dbb6f
 			if (tilde_expand(path, pw->pw_uid, &npath) != 0) {
943807
diff -up openssh-8.5p1/sk-usbhid.c.coverity openssh-8.5p1/sk-usbhid.c
943807
--- openssh-8.5p1/sk-usbhid.c.coverity	2021-03-02 11:31:47.000000000 +0100
943807
+++ openssh-8.5p1/sk-usbhid.c	2021-03-24 12:03:33.786968187 +0100
943807
@@ -1256,6 +1256,7 @@ sk_load_resident_keys(const char *pin, s
943807
 		freezero(rks[i], sizeof(*rks[i]));
943807
 	}
943807
 	free(rks);
943807
+	free(device);
943807
 	return ret;
943807
 }
943807
 
943807
diff -up openssh-7.4p1/ssh-agent.c.coverity openssh-7.4p1/ssh-agent.c
943807
--- openssh-7.4p1/ssh-agent.c.coverity	2016-12-19 05:59:41.000000000 +0100
943807
+++ openssh-7.4p1/ssh-agent.c	2016-12-23 16:40:26.903788691 +0100
943807
@@ -869,6 +869,7 @@ sanitize_pkcs11_provider(const char *pro
943807
 
943807
 		if (pkcs11_uri_parse(provider, uri) != 0) {
943807
 			error("Failed to parse PKCS#11 URI");
943807
+			pkcs11_uri_cleanup(uri);
943807
 			return NULL;
943807
 		}
943807
 		/* validate also provider from URI */
943807
@@ -1220,8 +1220,8 @@ main(int ac, char **av)
943807
 	sanitise_stdfd();
943807
 
943807
 	/* drop */
943807
-	setegid(getgid());
943807
-	setgid(getgid());
943807
+	(void) setegid(getgid());
943807
+	(void) setgid(getgid());
943807
 
943807
 	platform_disable_tracing(0);	/* strict=no */
943807
 
943807
diff -up openssh-8.5p1/ssh.c.coverity openssh-8.5p1/ssh.c
943807
--- openssh-8.5p1/ssh.c.coverity	2021-03-24 12:03:33.779968138 +0100
943807
+++ openssh-8.5p1/ssh.c	2021-03-24 12:03:33.786968187 +0100
943807
@@ -1746,6 +1746,7 @@ control_persist_detach(void)
943807
 		close(muxserver_sock);
943807
 		muxserver_sock = -1;
943807
 		options.control_master = SSHCTL_MASTER_NO;
943807
+		/* coverity[leaked_handle: FALSE]*/
943807
 		muxclient(options.control_path);
943807
 		/* muxclient() doesn't return on success. */
943807
 		fatal("Failed to connect to new control master");
943807
diff -up openssh-7.4p1/sshd.c.coverity openssh-7.4p1/sshd.c
943807
--- openssh-7.4p1/sshd.c.coverity	2016-12-23 16:40:26.897788690 +0100
943807
+++ openssh-7.4p1/sshd.c	2016-12-23 16:40:26.904788692 +0100
943807
@@ -691,8 +691,10 @@ privsep_preauth(Authctxt *authctxt)
943807
 
943807
 		privsep_preauth_child(ssh);
943807
 		setproctitle("%s", "[net]");
943807
-		if (box != NULL)
943807
+		if (box != NULL) {
943807
 			ssh_sandbox_child(box);
943807
+			free(box);
943807
+		}
943807
 
943807
 		return 0;
943807
 	}
943807
@@ -1386,6 +1388,9 @@ server_accept_loop(int *sock_in, int *so
943807
 			explicit_bzero(rnd, sizeof(rnd));
943807
 		}
943807
 	}
943807
+
943807
+	if (fdset != NULL)
943807
+		free(fdset);
943807
 }
943807
 
943807
 /*
943807
@@ -2474,7 +2479,7 @@ do_ssh2_kex(struct ssh *ssh)
943807
 	if (options.rekey_limit || options.rekey_interval)
943807
 		ssh_packet_set_rekey_limits(ssh, options.rekey_limit,
943807
 		    options.rekey_interval);
943807
-
943807
+	/* coverity[leaked_storage : FALSE]*/
943807
 	myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] = compat_pkalg_proposal(
943807
 	    ssh, list_hostkey_types());
943807
 
943807
@@ -2519,8 +2524,11 @@ do_ssh2_kex(struct ssh *ssh)
943807
 
943807
 	if (newstr)
943807
 		myproposal[PROPOSAL_KEX_ALGS] = newstr;
943807
-	else
943807
+	else {
943807
 		fatal("No supported key exchange algorithms");
943807
+		free(gss);
943807
+	     }
943807
+	     /* coverity[leaked_storage: FALSE]*/
943807
 	}
943807
 #endif
943807
 
943807
diff -up openssh-8.5p1/ssh-keygen.c.coverity openssh-8.5p1/ssh-keygen.c
943807
--- openssh-8.5p1/ssh-keygen.c.coverity	2021-03-24 12:03:33.780968145 +0100
943807
+++ openssh-8.5p1/ssh-keygen.c	2021-03-24 12:03:33.787968194 +0100
943807
@@ -2332,6 +2332,9 @@ update_krl_from_file(struct passwd *pw,
943807
 			r = ssh_krl_revoke_key_sha256(krl, blob, blen);
943807
 			if (r != 0)
943807
 				fatal_fr(r, "revoke key failed");
943807
+			freezero(blob, blen);
943807
+			blob = NULL;
943807
+			blen = 0;
943807
 		} else {
943807
 			if (strncasecmp(cp, "key:", 4) == 0) {
943807
 				cp += 4;
943807
@@ -2879,6 +2882,7 @@ do_moduli_screen(const char *out_file, c
943807
 		} else if (strncmp(opts[i], "start-line=", 11) == 0) {
943807
 			start_lineno = strtoul(opts[i]+11, NULL, 10);
943807
 		} else if (strncmp(opts[i], "checkpoint=", 11) == 0) {
943807
+			free(checkpoint);
943807
 			checkpoint = xstrdup(opts[i]+11);
943807
 		} else if (strncmp(opts[i], "generator=", 10) == 0) {
943807
 			generator_wanted = (u_int32_t)strtonum(
943807
@@ -2920,6 +2924,9 @@ do_moduli_screen(const char *out_file, c
943807
 #else /* WITH_OPENSSL */
943807
 	fatal("Moduli screening is not supported");
943807
 #endif /* WITH_OPENSSL */
943807
+	free(checkpoint);
943807
+	if (in != stdin)
943807
+		fclose(in);
943807
 }
943807
 
943807
 static char *
943807
diff -up openssh-8.5p1/sshsig.c.coverity openssh-8.5p1/sshsig.c
943807
--- openssh-8.5p1/sshsig.c.coverity	2021-03-02 11:31:47.000000000 +0100
943807
+++ openssh-8.5p1/sshsig.c	2021-03-24 12:03:33.787968194 +0100
943807
@@ -515,6 +515,7 @@ hash_file(int fd, const char *hashalg, s
943807
 			oerrno = errno;
943807
 			error_f("read: %s", strerror(errno));
943807
 			ssh_digest_free(ctx);
943807
+			ctx = NULL;
943807
 			errno = oerrno;
943807
 			r = SSH_ERR_SYSTEM_ERROR;
943807
 			goto out;