rcolebaugh / rpms / openssh

Forked from rpms/openssh 2 years ago
Clone
8f2528
diff -up openssh-7.4p1/auth-pam.c.coverity openssh-7.4p1/auth-pam.c
8f2528
diff -up openssh-7.4p1/channels.c.coverity openssh-7.4p1/channels.c
8f2528
--- openssh-7.4p1/channels.c.coverity	2017-02-09 14:58:32.786064600 +0100
8f2528
+++ openssh-7.4p1/channels.c	2017-02-09 15:01:28.869890219 +0100
8f2528
@@ -266,11 +266,11 @@ channel_register_fds(Channel *c, int rfd
8f2528
 	channel_max_fd = MAXIMUM(channel_max_fd, wfd);
8f2528
 	channel_max_fd = MAXIMUM(channel_max_fd, efd);
8f2528
 
8f2528
-	if (rfd != -1)
8f2528
+	if (rfd >= 0)
8f2528
 		fcntl(rfd, F_SETFD, FD_CLOEXEC);
8f2528
-	if (wfd != -1 && wfd != rfd)
8f2528
+	if (wfd >= 0 && wfd != rfd)
8f2528
 		fcntl(wfd, F_SETFD, FD_CLOEXEC);
8f2528
-	if (efd != -1 && efd != rfd && efd != wfd)
8f2528
+	if (efd >= 0 && efd != rfd && efd != wfd)
8f2528
 		fcntl(efd, F_SETFD, FD_CLOEXEC);
8f2528
 
8f2528
 	c->rfd = rfd;
8f2528
@@ -288,11 +288,11 @@ channel_register_fds(Channel *c, int rfd
8f2528
 
8f2528
 	/* enable nonblocking mode */
8f2528
 	if (nonblock) {
8f2528
-		if (rfd != -1)
8f2528
+		if (rfd >= 0)
8f2528
 			set_nonblock(rfd);
8f2528
-		if (wfd != -1)
8f2528
+		if (wfd >= 0)
8f2528
 			set_nonblock(wfd);
8f2528
-		if (efd != -1)
8f2528
+		if (efd >= 0)
8f2528
 			set_nonblock(efd);
8f2528
 	}
8f2528
 }
8f2528
diff -up openssh-7.4p1/clientloop.c.coverity openssh-7.4p1/clientloop.c
8f2528
diff -up openssh-7.4p1/key.c.coverity openssh-7.4p1/key.c
8f2528
diff -up openssh-7.4p1/monitor.c.coverity openssh-7.4p1/monitor.c
8f2528
--- openssh-7.4p1/monitor.c.coverity	2017-02-09 14:58:32.793064593 +0100
8f2528
+++ openssh-7.4p1/monitor.c	2017-02-09 14:58:32.805064581 +0100
8f2528
@@ -411,7 +411,7 @@ monitor_child_preauth(Authctxt *_authctx
8f2528
 	mm_get_keystate(pmonitor);
8f2528
 
8f2528
 	/* Drain any buffered messages from the child */
8f2528
-	while (pmonitor->m_log_recvfd != -1 && monitor_read_log(pmonitor) == 0)
8f2528
+	while (pmonitor->m_log_recvfd >= 0 && monitor_read_log(pmonitor) == 0)
8f2528
 		;
8f2528
 
8f2528
 	close(pmonitor->m_sendfd);
8f2528
diff -up openssh-7.4p1/monitor_wrap.c.coverity openssh-7.4p1/monitor_wrap.c
8f2528
--- openssh-7.4p1/monitor_wrap.c.coverity	2017-02-09 14:58:32.797064589 +0100
8f2528
+++ openssh-7.4p1/monitor_wrap.c	2017-02-09 14:58:32.805064581 +0100
8f2528
@@ -525,10 +525,10 @@ mm_pty_allocate(int *ptyfd, int *ttyfd,
8f2528
 	if ((tmp1 = dup(pmonitor->m_recvfd)) == -1 ||
8f2528
 	    (tmp2 = dup(pmonitor->m_recvfd)) == -1) {
8f2528
 		error("%s: cannot allocate fds for pty", __func__);
8f2528
-		if (tmp1 > 0)
8f2528
+		if (tmp1 >= 0)
8f2528
 			close(tmp1);
8f2528
-		if (tmp2 > 0)
8f2528
-			close(tmp2);
8f2528
+		/*DEAD CODE if (tmp2 >= 0)
8f2528
+			close(tmp2);*/
8f2528
 		return 0;
8f2528
 	}
8f2528
 	close(tmp1);
8f2528
diff -up openssh-7.4p1/openbsd-compat/bindresvport.c.coverity openssh-7.4p1/openbsd-compat/bindresvport.c
8f2528
--- openssh-7.4p1/openbsd-compat/bindresvport.c.coverity	2016-12-19 05:59:41.000000000 +0100
8f2528
+++ openssh-7.4p1/openbsd-compat/bindresvport.c	2017-02-09 14:58:32.805064581 +0100
8f2528
@@ -58,7 +58,7 @@ bindresvport_sa(int sd, struct sockaddr
8f2528
 	struct sockaddr_in6 *in6;
8f2528
 	u_int16_t *portp;
8f2528
 	u_int16_t port;
8f2528
-	socklen_t salen;
8f2528
+	socklen_t salen = sizeof(struct sockaddr_storage);
8f2528
 	int i;
8f2528
 
8f2528
 	if (sa == NULL) {
8f2528
diff -up openssh-7.4p1/packet.c.coverity openssh-7.4p1/packet.c
8f2528
diff -up openssh-7.4p1/progressmeter.c.coverity openssh-7.4p1/progressmeter.c
8f2528
diff -up openssh-7.4p1/scp.c.coverity openssh-7.4p1/scp.c
8f2528
--- openssh-7.4p1/scp.c.coverity	2017-02-09 14:58:32.761064625 +0100
8f2528
+++ openssh-7.4p1/scp.c	2017-02-09 14:58:38.590058852 +0100
8f2528
@@ -157,7 +157,7 @@ killchild(int signo)
8f2528
 {
8f2528
 	if (do_cmd_pid > 1) {
8f2528
 		kill(do_cmd_pid, signo ? signo : SIGTERM);
8f2528
-		waitpid(do_cmd_pid, NULL, 0);
8f2528
+		(void) waitpid(do_cmd_pid, NULL, 0);
8f2528
 	}
8f2528
 
8f2528
 	if (signo)
8f2528
diff -up openssh-7.4p1/servconf.c.coverity openssh-7.4p1/servconf.c
8f2528
--- openssh-7.4p1/servconf.c.coverity	2017-02-09 14:58:32.801064585 +0100
8f2528
+++ openssh-7.4p1/servconf.c	2017-02-09 14:58:38.591058851 +0100
8f2528
@@ -1544,7 +1544,7 @@ process_server_config_line(ServerOptions
8f2528
 			fatal("%s line %d: Missing subsystem name.",
8f2528
 			    filename, linenum);
8f2528
 		if (!*activep) {
8f2528
-			arg = strdelim(&cp;;
8f2528
+			/*arg =*/ (void) strdelim(&cp;;
8f2528
 			break;
8f2528
 		}
8f2528
 		for (i = 0; i < options->num_subsystems; i++)
8f2528
@@ -1635,8 +1635,9 @@ process_server_config_line(ServerOptions
8f2528
 		if (*activep && *charptr == NULL) {
8f2528
 			*charptr = tilde_expand_filename(arg, getuid());
8f2528
 			/* increase optional counter */
8f2528
-			if (intptr != NULL)
8f2528
-				*intptr = *intptr + 1;
8f2528
+			/* DEAD CODE intptr is still NULL ;)
8f2528
+  			 if (intptr != NULL)
8f2528
+				*intptr = *intptr + 1; */
8f2528
 		}
8f2528
 		break;
8f2528
 
8f2528
diff -up openssh-7.4p1/serverloop.c.coverity openssh-7.4p1/serverloop.c
8f2528
--- openssh-7.4p1/serverloop.c.coverity	2016-12-19 05:59:41.000000000 +0100
8f2528
+++ openssh-7.4p1/serverloop.c	2017-02-09 14:58:38.592058850 +0100
8f2528
@@ -125,13 +125,13 @@ notify_setup(void)
8f2528
 static void
8f2528
 notify_parent(void)
8f2528
 {
8f2528
-	if (notify_pipe[1] != -1)
8f2528
+	if (notify_pipe[1] >= 0)
8f2528
 		(void)write(notify_pipe[1], "", 1);
8f2528
 }
8f2528
 static void
8f2528
 notify_prepare(fd_set *readset)
8f2528
 {
8f2528
-	if (notify_pipe[0] != -1)
8f2528
+	if (notify_pipe[0] >= 0)
8f2528
 		FD_SET(notify_pipe[0], readset);
8f2528
 }
8f2528
 static void
8f2528
@@ -139,8 +139,8 @@ notify_done(fd_set *readset)
8f2528
 {
8f2528
 	char c;
8f2528
 
8f2528
-	if (notify_pipe[0] != -1 && FD_ISSET(notify_pipe[0], readset))
8f2528
-		while (read(notify_pipe[0], &c, 1) != -1)
8f2528
+	if (notify_pipe[0] >= 0 && FD_ISSET(notify_pipe[0], readset))
8f2528
+		while (read(notify_pipe[0], &c, 1) >= 0)
8f2528
 			debug2("notify_done: reading");
8f2528
 }
8f2528
 
8f2528
@@ -518,7 +518,7 @@ server_request_tun(void)
8f2528
 	}
8f2528
 
8f2528
 	tun = packet_get_int();
8f2528
-	if (forced_tun_device != -1) {
8f2528
+	if (forced_tun_device >= 0) {
8f2528
 		if (tun != SSH_TUNID_ANY && forced_tun_device != tun)
8f2528
 			goto done;
8f2528
 		tun = forced_tun_device;
8f2528
diff -up openssh-7.4p1/sftp.c.coverity openssh-7.4p1/sftp.c
8f2528
--- openssh-7.4p1/sftp.c.coverity	2016-12-19 05:59:41.000000000 +0100
8f2528
+++ openssh-7.4p1/sftp.c	2017-02-09 14:58:38.598058844 +0100
8f2528
@@ -224,7 +224,7 @@ killchild(int signo)
8f2528
 {
8f2528
 	if (sshpid > 1) {
8f2528
 		kill(sshpid, SIGTERM);
8f2528
-		waitpid(sshpid, NULL, 0);
8f2528
+		(void) waitpid(sshpid, NULL, 0);
8f2528
 	}
8f2528
 
8f2528
 	_exit(1);
8f2528
diff -up openssh-7.4p1/sftp-client.c.coverity openssh-7.4p1/sftp-client.c
8f2528
--- openssh-7.4p1/sftp-client.c.coverity	2017-02-09 14:58:38.596058846 +0100
8f2528
+++ openssh-7.4p1/sftp-client.c	2017-02-09 15:20:18.893624636 +0100
8f2528
@@ -973,7 +973,7 @@ do_symlink(struct sftp_conn *conn, const
8f2528
 }
8f2528
 
8f2528
 int
8f2528
-do_fsync(struct sftp_conn *conn, u_char *handle, u_int handle_len)
8f2528
+do_fsync(struct sftp_conn *conn, const u_char *handle, u_int handle_len)
8f2528
 {
8f2528
 	struct sshbuf *msg;
8f2528
 	u_int status, id;
8f2528
--- openssh-7.4p1/sftp-client.h.coverity        2017-02-10 09:28:10.951155129 +0100
8f2528
+++ openssh-7.4p1/sftp-client.h 2017-02-10 09:27:28.685069870 +0100
8f2528
@@ -107,7 +107,7 @@ int do_hardlink(struct sftp_conn *, cons
8f2528
 int do_symlink(struct sftp_conn *, const char *, const char *);
8f2528
 
8f2528
 /* Call fsync() on open file 'handle' */
8f2528
-int do_fsync(struct sftp_conn *conn, u_char *, u_int);
8f2528
+int do_fsync(struct sftp_conn *conn, const u_char *, u_int);
8f2528
 
8f2528
 /*
8f2528
  * Download 'remote_path' to 'local_path'. Preserve permissions and times
8f2528
diff -up openssh-7.4p1/ssh-agent.c.coverity openssh-7.4p1/ssh-agent.c
8f2528
--- openssh-7.4p1/ssh-agent.c.coverity	2017-02-09 14:58:38.599058843 +0100
8f2528
+++ openssh-7.4p1/ssh-agent.c	2017-02-09 15:29:21.938917065 +0100
8f2528
@@ -1220,8 +1220,8 @@ main(int ac, char **av)
8f2528
 	sanitise_stdfd();
8f2528
 
8f2528
 	/* drop */
8f2528
-	setegid(getgid());
8f2528
-	setgid(getgid());
8f2528
+	(void) setegid(getgid());
8f2528
+	(void) setgid(getgid());
8f2528
 
8f2528
 	platform_disable_tracing(0);	/* strict=no */
8f2528
 
8f2528
diff -up openssh-7.4p1/sshd.c.coverity openssh-7.4p1/sshd.c
8f2528
--- openssh-7.4p1/sshd.c.coverity	2017-02-09 14:58:38.600058842 +0100
8f2528
+++ openssh-7.4p1/sshd.c	2017-02-09 15:30:33.403800831 +0100
8f2528
@@ -679,8 +679,10 @@ privsep_preauth(Authctxt *authctxt)
8f2528
 
8f2528
 		privsep_preauth_child();
8f2528
 		setproctitle("%s", "[net]");
8f2528
-		if (box != NULL)
8f2528
+		if (box != NULL) {
8f2528
 			ssh_sandbox_child(box);
8f2528
+			free(box);
8f2528
+		}
8f2528
 
8f2528
 		return 0;
8f2528
 	}
8f2528
@@ -1382,6 +1384,9 @@ server_accept_loop(int *sock_in, int *so
8f2528
 		if (num_listen_socks < 0)
8f2528
 			break;
8f2528
 	}
8f2528
+
8f2528
+	if (fdset != NULL)
8f2528
+		free(fdset);
8f2528
 }
8f2528
 
8f2528
 /*
8f2528
diff --git a/auth-pam.c b/auth-pam.c
8f2528
index e554ec4..bd16d80 100644
8f2528
--- a/auth-pam.c
8f2528
+++ b/auth-pam.c
8f2528
@@ -834,6 +834,8 @@ fake_password(const char *wire_password)
8f2528
 		fatal("%s: password length too long: %zu", __func__, l);
8f2528
 
8f2528
 	ret = malloc(l + 1);
8f2528
+	if (ret == NULL)
8f2528
+		return NULL;
8f2528
 	for (i = 0; i < l; i++)
8f2528
 		ret[i] = junk[i % (sizeof(junk) - 1)];
8f2528
 	ret[i] = '\0';
8f2528
diff --git a/clientloop.c b/clientloop.c
8f2528
index c6a4138..9b00e12 100644
8f2528
--- a/clientloop.c
8f2528
+++ b/clientloop.c
8f2528
@@ -2290,7 +2290,7 @@ update_known_hosts(struct hostkeys_update_ctx *ctx)
8f2528
 			free(response);
8f2528
 			response = read_passphrase("Accept updated hostkeys? "
8f2528
 			    "(yes/no): ", RP_ECHO);
8f2528
-			if (strcasecmp(response, "yes") == 0)
8f2528
+			if (response != NULL && strcasecmp(response, "yes") == 0)
8f2528
 				break;
8f2528
 			else if (quit_pending || response == NULL ||
8f2528
 			    strcasecmp(response, "no") == 0) {
8f2528
diff --git a/digest-openssl.c b/digest-openssl.c
8f2528
index 13b63c2..dfa9b8d 100644
8f2528
--- a/digest-openssl.c
8f2528
+++ b/digest-openssl.c
8f2528
@@ -158,7 +158,7 @@ ssh_digest_final(struct ssh_digest_ctx *ctx, u_char *d, size_t dlen)
8f2528
 	const struct ssh_digest *digest = ssh_digest_by_alg(ctx->alg);
8f2528
 	u_int l = dlen;
8f2528
 
8f2528
-	if (dlen > UINT_MAX)
8f2528
+	if (digest == NULL || dlen > UINT_MAX)
8f2528
 		return SSH_ERR_INVALID_ARGUMENT;
8f2528
 	if (dlen < digest->digest_len) /* No truncation allowed */
8f2528
 		return SSH_ERR_INVALID_ARGUMENT;
8f2528
diff --git a/kex.c b/kex.c
8f2528
index a30dabe..a8ac91f 100644
8f2528
--- a/kex.c
8f2528
+++ b/kex.c
8f2528
@@ -178,7 +178,7 @@ kex_names_valid(const char *names)
8f2528
 char *
8f2528
 kex_names_cat(const char *a, const char *b)
8f2528
 {
8f2528
-	char *ret = NULL, *tmp = NULL, *cp, *p;
8f2528
+	char *ret = NULL, *tmp = NULL, *cp, *p, *m;
8f2528
 	size_t len;
8f2528
 
8f2528
 	if (a == NULL || *a == '\0')
8f2528
@@ -195,8 +195,10 @@ kex_names_cat(const char *a, const char *b)
8f2528
 	}
8f2528
 	strlcpy(ret, a, len);
8f2528
 	for ((p = strsep(&cp, ",")); p && *p != '\0'; (p = strsep(&cp, ","))) {
8f2528
-		if (match_list(ret, p, NULL) != NULL)
8f2528
+		if ((m = match_list(ret, p, NULL)) != NULL) {
8f2528
+			free(m);
8f2528
 			continue; /* Algorithm already present */
8f2528
+		}
8f2528
 		if (strlcat(ret, ",", len) >= len ||
8f2528
 		    strlcat(ret, p, len) >= len) {
8f2528
 			free(tmp);
8f2528
@@ -651,8 +653,10 @@ choose_enc(struct sshenc *enc, char *client, char *server)
8f2528
 #endif
8f2528
 		return SSH_ERR_NO_CIPHER_ALG_MATCH;
8f2528
 	}
8f2528
-	if ((enc->cipher = cipher_by_name(name)) == NULL)
8f2528
+	if ((enc->cipher = cipher_by_name(name)) == NULL) {
8f2528
+		free(name);
8f2528
 		return SSH_ERR_INTERNAL_ERROR;
8f2528
+	}
8f2528
 	enc->name = name;
8f2528
 	enc->enabled = 0;
8f2528
 	enc->iv = NULL;
8f2528
@@ -670,8 +674,10 @@ choose_mac(struct ssh *ssh, struct sshmac *mac, char *client, char *server)
8f2528
 #endif
8f2528
 		return SSH_ERR_NO_MAC_ALG_MATCH;
8f2528
 	}
8f2528
-	if (mac_setup(mac, name) < 0)
8f2528
+	if (mac_setup(mac, name) < 0) {
8f2528
+		free(name);
8f2528
 		return SSH_ERR_INTERNAL_ERROR;
8f2528
+	}
8f2528
 	/* truncate the key */
8f2528
 	if (ssh->compat & SSH_BUG_HMAC)
8f2528
 		mac->key_len = 16;
8f2528
@@ -695,6 +701,7 @@ choose_comp(struct sshcomp *comp, char *client, char *server)
8f2528
 	} else if (strcmp(name, "none") == 0) {
8f2528
 		comp->type = COMP_NONE;
8f2528
 	} else {
8f2528
+		free(name);
8f2528
 		return SSH_ERR_INTERNAL_ERROR;
8f2528
 	}
8f2528
 	comp->name = name;
8f2528
diff --git a/readconf.c b/readconf.c
8f2528
index 3e7a5d8..acc1391 100644
8f2528
--- a/readconf.c
8f2528
+++ b/readconf.c
8f2528
@@ -1500,6 +1500,7 @@ parse_keytypes:
8f2528
 			if (r == GLOB_NOMATCH) {
8f2528
 				debug("%.200s line %d: include %s matched no "
8f2528
 				    "files",filename, linenum, arg2);
8f2528
+				free(arg2);
8f2528
 				continue;
8f2528
 			} else if (r != 0 || gl.gl_pathc < 0)
8f2528
 				fatal("%.200s line %d: glob failed for %s.",
8f2528
diff --git a/servconf.c b/servconf.c
8f2528
index 6ab1cb4..5f2464a 100644
8f2528
--- a/servconf.c
8f2528
+++ b/servconf.c
8f2528
@@ -2284,8 +2284,6 @@ dump_cfg_fmtint(ServerOpCodes code, int val)
8f2528
 static void
8f2528
 dump_cfg_string(ServerOpCodes code, const char *val)
8f2528
 {
8f2528
-	if (val == NULL)
8f2528
-		return;
8f2528
 	printf("%s %s\n", lookup_opcode_name(code),
8f2528
 	    val == NULL ? "none" : val);
8f2528
 }
8f2528
diff --git a/sshconnect.c b/sshconnect.c
8f2528
index 07f80cd..5d4b41b 100644
8f2528
--- a/sshconnect.c
8f2528
+++ b/sshconnect.c
8f2528
@@ -1533,6 +1533,7 @@ maybe_add_key_to_agent(char *authfile, Key *private, char *comment,
8f2528
 	if (options.add_keys_to_agent == 2 &&
8f2528
 	    !ask_permission("Add key %s (%s) to agent?", authfile, comment)) {
8f2528
 		debug3("user denied adding this key");
8f2528
+		close(auth_sock);
8f2528
 		return;
8f2528
 	}
8f2528
 
8f2528
@@ -1541,4 +1542,5 @@ maybe_add_key_to_agent(char *authfile, Key *private, char *comment,
8f2528
 		debug("identity added to agent: %s", authfile);
8f2528
 	else
8f2528
 		debug("could not add identity to agent: %s (%d)", authfile, r);
8f2528
+	close(auth_sock);
8f2528
 }
8f2528
diff --git a/sshconnect2.c b/sshconnect2.c
8f2528
index f31c24c..aecf765 100644
8f2528
--- a/sshconnect2.c
8f2528
+++ b/sshconnect2.c
8f2528
@@ -1061,6 +1061,7 @@ sign_and_send_pubkey(Authctxt *authctxt, Identity *id)
8f2528
 
8f2528
 	if (key_to_blob(id->key, &blob, &bloblen) == 0) {
8f2528
 		/* we cannot handle this key */
8f2528
+		free(blob);
8f2528
 		debug3("sign_and_send_pubkey: cannot handle key");
8f2528
 		return 0;
8f2528
 	}
8f2528
@@ -1170,6 +1171,7 @@ send_pubkey_test(Authctxt *authctxt, Identity *id)
8f2528
 
8f2528
 	if (key_to_blob(id->key, &blob, &bloblen) == 0) {
8f2528
 		/* we cannot handle this key */
8f2528
+		free(blob);
8f2528
 		debug3("send_pubkey_test: cannot handle key");
8f2528
 		return 0;
8f2528
 	}
8f2528
diff --git a/sshkey.c b/sshkey.c
8f2528
index 85fd1bd..58c1051 100644
8f2528
--- a/sshkey.c
8f2528
+++ b/sshkey.c
8f2528
@@ -1375,8 +1375,6 @@ sshkey_read(struct sshkey *ret, char **cpp)
8f2528
 		retval = 0;
8f2528
 /*XXXX*/
8f2528
 		sshkey_free(k);
8f2528
-		if (retval != 0)
8f2528
-			break;
8f2528
 		break;
8f2528
 	default:
8f2528
 		return SSH_ERR_INVALID_ARGUMENT;
8f2528
diff --git a/krl.c b/krl.c
8f2528
index e271a19..69bec99 100644
8f2528
--- a/krl.c
8f2528
+++ b/krl.c
8f2528
@@ -1089,7 +1089,7 @@ ssh_krl_from_blob(struct sshbuf *buf, struct ssh_krl **krlp,
8f2528
 			break;
8f2528
 		case KRL_SECTION_SIGNATURE:
8f2528
 			/* Handled above, but still need to stay in synch */
8f2528
-			sshbuf_reset(sect);
8f2528
+			sshbuf_free(sect);
8f2528
 			sect = NULL;
8f2528
 			if ((r = sshbuf_skip_string(copy)) != 0)
8f2528
 				goto out;
8f2528
@@ -1288,7 +1288,8 @@ ssh_krl_file_contains_key(const char *path, const struct sshkey *key)
8f2528
 	debug2("%s: checking KRL %s", __func__, path);
8f2528
 	r = ssh_krl_check_key(krl, key);
8f2528
  out:
8f2528
-	close(fd);
8f2528
+	if (fd != -1)
8f2528
+		close(fd);
8f2528
 	sshbuf_free(krlbuf);
8f2528
 	ssh_krl_free(krl);
8f2528
 	if (r != 0)
8f2528
diff --git a/readconf.c b/readconf.c
8f2528
index acc1391..c4dff15 100644
8f2528
--- a/readconf.c
8f2528
+++ b/readconf.c
8f2528
@@ -1185,7 +1185,7 @@ parse_int:
8f2528
 		value = cipher_number(arg);
8f2528
 		if (value == -1)
8f2528
 			fatal("%.200s line %d: Bad cipher '%s'.",
8f2528
-			    filename, linenum, arg ? arg : "<NONE>");
8f2528
+			    filename, linenum, arg);
8f2528
 		if (*activep && *intptr == -1)
8f2528
 			*intptr = value;
8f2528
 		break;
8f2528
@@ -1196,7 +1196,7 @@ parse_int:
8f2528
 			fatal("%.200s line %d: Missing argument.", filename, linenum);
8f2528
 		if (!ciphers_valid(*arg == '+' ? arg + 1 : arg))
8f2528
 			fatal("%.200s line %d: Bad SSH2 cipher spec '%s'.",
8f2528
-			    filename, linenum, arg ? arg : "<NONE>");
8f2528
+			    filename, linenum, arg);
8f2528
 		if (*activep && options->ciphers == NULL)
8f2528
 			options->ciphers = xstrdup(arg);
8f2528
 		break;
8f2528
@@ -1207,7 +1207,7 @@ parse_int:
8f2528
 			fatal("%.200s line %d: Missing argument.", filename, linenum);
8f2528
 		if (!mac_valid(*arg == '+' ? arg + 1 : arg))
8f2528
 			fatal("%.200s line %d: Bad SSH2 Mac spec '%s'.",
8f2528
-			    filename, linenum, arg ? arg : "<NONE>");
8f2528
+			    filename, linenum, arg);
8f2528
 		if (*activep && options->macs == NULL)
8f2528
 			options->macs = xstrdup(arg);
8f2528
 		break;
8f2528
@@ -1220,7 +1220,7 @@ parse_int:
8f2528
 			    filename, linenum);
8f2528
 		if (!kex_names_valid(*arg == '+' ? arg + 1 : arg))
8f2528
 			fatal("%.200s line %d: Bad SSH2 KexAlgorithms '%s'.",
8f2528
-			    filename, linenum, arg ? arg : "<NONE>");
8f2528
+			    filename, linenum, arg);
8f2528
 		if (*activep && options->kex_algorithms == NULL)
8f2528
 			options->kex_algorithms = xstrdup(arg);
8f2528
 		break;
8f2528
@@ -1235,7 +1235,7 @@ parse_keytypes:
8f2528
 			    filename, linenum);
8f2528
 		if (!sshkey_names_valid2(*arg == '+' ? arg + 1 : arg, 1))
8f2528
 			fatal("%s line %d: Bad key types '%s'.",
8f2528
-				filename, linenum, arg ? arg : "<NONE>");
8f2528
+				filename, linenum, arg);
8f2528
 		if (*activep && *charptr == NULL)
8f2528
 			*charptr = xstrdup(arg);
8f2528
 		break;
8f2528
@@ -1248,7 +1248,7 @@ parse_keytypes:
8f2528
 		value = proto_spec(arg);
8f2528
 		if (value == SSH_PROTO_UNKNOWN)
8f2528
 			fatal("%.200s line %d: Bad protocol spec '%s'.",
8f2528
-			    filename, linenum, arg ? arg : "<NONE>");
8f2528
+			    filename, linenum, arg);
8f2528
 		if (*activep && *intptr == SSH_PROTO_UNKNOWN)
8f2528
 			*intptr = value;
8f2528
 		break;
8f2528
diff --git a/servconf.c b/servconf.c
8f2528
index 5f2464a..4564494 100644
8f2528
--- a/servconf.c
8f2528
+++ b/servconf.c
8f2528
@@ -1217,7 +1217,7 @@ process_server_config_line_depth(ServerOptions *options, char *line,
8f2528
 			    filename, linenum);
8f2528
 		if (!sshkey_names_valid2(*arg == '+' ? arg + 1 : arg, 1))
8f2528
 			fatal("%s line %d: Bad key types '%s'.",
8f2528
-			    filename, linenum, arg ? arg : "<NONE>");
8f2528
+			    filename, linenum, arg);
8f2528
 		if (*activep && *charptr == NULL)
8f2528
 			*charptr = xstrdup(arg);
8f2528
 		break;
8f2528
@@ -1476,7 +1476,7 @@ process_server_config_line_depth(ServerOptions *options, char *line,
8f2528
 			fatal("%s line %d: Missing argument.", filename, linenum);
8f2528
 		if (!ciphers_valid(*arg == '+' ? arg + 1 : arg))
8f2528
 			fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
8f2528
-			    filename, linenum, arg ? arg : "<NONE>");
8f2528
+			    filename, linenum, arg);
8f2528
 		if (options->ciphers == NULL)
8f2528
 			options->ciphers = xstrdup(arg);
8f2528
 		break;
8f2528
@@ -1487,7 +1487,7 @@ process_server_config_line_depth(ServerOptions *options, char *line,
8f2528
 			fatal("%s line %d: Missing argument.", filename, linenum);
8f2528
 		if (!mac_valid(*arg == '+' ? arg + 1 : arg))
8f2528
 			fatal("%s line %d: Bad SSH2 mac spec '%s'.",
8f2528
-			    filename, linenum, arg ? arg : "<NONE>");
8f2528
+			    filename, linenum, arg);
8f2528
 		if (options->macs == NULL)
8f2528
 			options->macs = xstrdup(arg);
8f2528
 		break;
8f2528
@@ -1500,7 +1500,7 @@ process_server_config_line_depth(ServerOptions *options, char *line,
8f2528
 			    filename, linenum);
8f2528
 		if (!kex_names_valid(*arg == '+' ? arg + 1 : arg))
8f2528
 			fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
8f2528
-			    filename, linenum, arg ? arg : "<NONE>");
8f2528
+			    filename, linenum, arg);
8f2528
 		if (options->kex_algorithms == NULL)
8f2528
 			options->kex_algorithms = xstrdup(arg);
8f2528
 		break;
8f2528
diff --git a/ssh-pkcs11.c b/ssh-pkcs11.c
8f2528
index aaf712d..62a76b3 100644
8f2528
--- a/ssh-pkcs11.c
8f2528
+++ b/ssh-pkcs11.c
8f2528
@@ -536,8 +536,8 @@ pkcs11_fetch_keys_filter(struct pkcs11_provider *p, CK_ULONG slotidx,
8f2528
 				X509_free(x509);
8f2528
 		}
8f2528
 		if (rsa && rsa->n && rsa->e &&
8f2528
-		    pkcs11_rsa_wrap(p, slotidx, &attribs[0], rsa) == 0) {
8f2528
-			key = sshkey_new(KEY_UNSPEC);
8f2528
+		    pkcs11_rsa_wrap(p, slotidx, &attribs[0], rsa) == 0 &&
8f2528
+		    (key = sshkey_new(KEY_UNSPEC)) != NULL) {
8f2528
 			key->rsa = rsa;
8f2528
 			key->type = KEY_RSA;
8f2528
 			key->flags |= SSHKEY_FLAG_EXT;
8f2528
diff --git a/sshconnect1.c b/sshconnect1.c
8f2528
index a045361..0e1a506 100644
8f2528
--- a/sshconnect1.c
8f2528
+++ b/sshconnect1.c
8f2528
@@ -520,7 +520,8 @@ ssh_kex(char *host, struct sockaddr *hostaddr)
8f2528
 		cookie[i] = packet_get_char();
8f2528
 
8f2528
 	/* Get the public key. */
8f2528
-	server_key = key_new(KEY_RSA1);
8f2528
+	if ((server_key = key_new(KEY_RSA1)) == NULL)
8f2528
+		fatal("%s: key_new(KEY_RSA1) failed", __func__);
8f2528
 	bits = packet_get_int();
8f2528
 	packet_get_bignum(server_key->rsa->e);
8f2528
 	packet_get_bignum(server_key->rsa->n);
8f2528
@@ -532,7 +533,8 @@ ssh_kex(char *host, struct sockaddr *hostaddr)
8f2528
 		logit("Warning: This may be due to an old implementation of ssh.");
8f2528
 	}
8f2528
 	/* Get the host key. */
8f2528
-	host_key = key_new(KEY_RSA1);
8f2528
+	if ((host_key = key_new(KEY_RSA1)) == NULL)
8f2528
+		fatal("%s: key_new(KEY_RSA1) failed", __func__);
8f2528
 	bits = packet_get_int();
8f2528
 	packet_get_bignum(host_key->rsa->e);
8f2528
 	packet_get_bignum(host_key->rsa->n);
8f2528
diff --git a/sshkey.c b/sshkey.c
8f2528
index 58c1051..6afacb5 100644
8f2528
--- a/sshkey.c
8f2528
+++ b/sshkey.c
8f2528
@@ -1239,6 +1239,9 @@ sshkey_read(struct sshkey *ret, char **cpp)
8f2528
 	u_long bits;
8f2528
 #endif /* WITH_SSH1 */
8f2528
 
8f2528
+	if (ret == NULL)
8f2528
+		return SSH_ERR_INVALID_ARGUMENT;
8f2528
+
8f2528
 	cp = *cpp;
8f2528
 
8f2528
 	switch (ret->type) {