[PATCH] A grab bag of trivial things.
Markus Schmidt
markus at blueflash.cc
Tue Apr 23 19:15:05 AEST 2019
During porting I found a couple of things in the source, like slightly
wrong types (int vs. LogLevel), a leaking field and calls c-library
functions where x-functions exist (xrecallocarray, xasprintf).
Also includes for xmss which I think should be wrapped in #ifdef.
The patch is attached.
Markus
-------------- next part --------------
diff --git a/authfile.c b/authfile.c
index b1c92f4..d020ff4 100644
--- a/authfile.c
+++ b/authfile.c
@@ -38,6 +38,7 @@
#include <unistd.h>
#include <limits.h>
+#include "xmalloc.h"
#include "cipher.h"
#include "ssh.h"
#include "log.h"
@@ -364,7 +365,7 @@ sshkey_load_cert(const char *filename, struct sshkey **keyp)
if (keyp != NULL)
*keyp = NULL;
- if (asprintf(&file, "%s-cert.pub", filename) == -1)
+ if (xasprintf(&file, "%s-cert.pub", filename) == -1)
return SSH_ERR_ALLOC_FAIL;
if ((pub = sshkey_new(KEY_UNSPEC)) == NULL) {
diff --git a/clientloop.c b/clientloop.c
index 086c0df..a3422cb 100644
--- a/clientloop.c
+++ b/clientloop.c
@@ -1881,7 +1881,7 @@ static void
update_known_hosts(struct hostkeys_update_ctx *ctx)
{
int r, was_raw = 0;
- int loglevel = options.update_hostkeys == SSH_UPDATE_HOSTKEYS_ASK ?
+ LogLevel loglevel = options.update_hostkeys == SSH_UPDATE_HOSTKEYS_ASK ?
SYSLOG_LEVEL_INFO : SYSLOG_LEVEL_VERBOSE;
char *fp, *response;
size_t i;
diff --git a/hostfile.c b/hostfile.c
index e1f826b..f1d6810 100644
--- a/hostfile.c
+++ b/hostfile.c
@@ -251,7 +251,7 @@ record_hostkey(struct hostkey_foreach_line *l, void *_ctx)
l->marker == MRK_NONE ? "" :
(l->marker == MRK_CA ? "ca " : "revoked "),
sshkey_type(l->key), l->path, l->linenum);
- if ((tmp = recallocarray(hostkeys->entries, hostkeys->num_entries,
+ if ((tmp = xrecallocarray(hostkeys->entries, hostkeys->num_entries,
hostkeys->num_entries + 1, sizeof(*hostkeys->entries))) == NULL)
return SSH_ERR_ALLOC_FAIL;
hostkeys->entries = tmp;
diff --git a/misc.c b/misc.c
index 009e02b..d655044 100644
--- a/misc.c
+++ b/misc.c
@@ -550,7 +550,7 @@ put_host_port(const char *host, u_short port)
if (port == 0 || port == SSH_DEFAULT_PORT)
return(xstrdup(host));
- if (asprintf(&hoststr, "[%s]:%d", host, (int)port) < 0)
+ if (xasprintf(&hoststr, "[%s]:%d", host, (int)port) < 0)
fatal("put_host_port: asprintf: %s", strerror(errno));
debug3("put_host_port: %s", hoststr);
return hoststr;
diff --git a/ssh.c b/ssh.c
index 91e7c35..9fe6bd1 100644
--- a/ssh.c
+++ b/ssh.c
@@ -236,7 +236,8 @@ resolve_host(const char *name, int port, int logerr, char *cname, size_t clen)
{
char strport[NI_MAXSERV];
struct addrinfo hints, *res;
- int gaierr, loglevel = SYSLOG_LEVEL_DEBUG1;
+ int gaierr;
+ LogLevel loglevel = SYSLOG_LEVEL_DEBUG1;
if (port <= 0)
port = default_ssh_port();
diff --git a/sshconnect.c b/sshconnect.c
index fdcdcd8..92a0eab 100644
--- a/sshconnect.c
+++ b/sshconnect.c
@@ -1292,6 +1292,7 @@ ssh_login(struct ssh *ssh, Sensitive *sensitive, const char *orighost,
ssh_kex2(ssh, host, hostaddr, port);
ssh_userauth2(ssh, local_user, server_user, host, sensitive);
free(local_user);
+ free(host);
}
/* print all known host keys for a given host, but skip keys of given type */
diff --git a/sshkey.c b/sshkey.c
index ad19577..3a412d8 100644
--- a/sshkey.c
+++ b/sshkey.c
@@ -47,6 +47,7 @@
#include <util.h>
#endif /* HAVE_UTIL_H */
+#include "xmalloc.h"
#include "ssh2.h"
#include "ssherr.h"
#include "misc.h"
@@ -55,10 +56,12 @@
#include "digest.h"
#define SSHKEY_INTERNAL
#include "sshkey.h"
-#include "sshkey-xmss.h"
#include "match.h"
+#ifdef WITH_XMSS
+#include "sshkey-xmss.h"
#include "xmss_fast.h"
+#endif
#include "openbsd-compat/openssl-compat.h"
@@ -1925,7 +1928,7 @@ cert_parse(struct sshbuf *b, struct sshkey *key, struct sshbuf *certbuf)
goto out;
}
oprincipals = key->cert->principals;
- key->cert->principals = recallocarray(key->cert->principals,
+ key->cert->principals = xrecallocarray(key->cert->principals,
key->cert->nprincipals, key->cert->nprincipals + 1,
sizeof(*key->cert->principals));
if (key->cert->principals == NULL) {
More information about the openssh-unix-dev
mailing list