From ce5af731b6d0313ef957df6cb6ca70746614d7e1 Mon Sep 17 00:00:00 2001 From: djm Date: Sun, 12 Aug 2018 20:19:13 +0000 Subject: [PATCH] better diagnosics on alg list assembly errors; ok deraadt@ markus@ --- usr.bin/ssh/readconf.c | 27 +++++++++++++++------------ usr.bin/ssh/servconf.c | 28 ++++++++++++++-------------- 2 files changed, 29 insertions(+), 26 deletions(-) diff --git a/usr.bin/ssh/readconf.c b/usr.bin/ssh/readconf.c index 8115da393db..b2103575206 100644 --- a/usr.bin/ssh/readconf.c +++ b/usr.bin/ssh/readconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: readconf.c,v 1.296 2018/07/27 05:34:42 dtucker Exp $ */ +/* $OpenBSD: readconf.c,v 1.297 2018/08/12 20:19:13 djm Exp $ */ /* * Author: Tatu Ylonen * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland @@ -38,6 +38,7 @@ #include "xmalloc.h" #include "ssh.h" +#include "ssherr.h" #include "compat.h" #include "cipher.h" #include "pathnames.h" @@ -1909,6 +1910,7 @@ void fill_default_options(Options * options) { char *all_cipher, *all_mac, *all_kex, *all_key; + int r; if (options->forward_agent == -1) options->forward_agent = 0; @@ -2058,17 +2060,18 @@ fill_default_options(Options * options) all_mac = mac_alg_list(','); all_kex = kex_alg_list(','); all_key = sshkey_alg_list(0, 0, 1, ','); - if (kex_assemble_names(&options->ciphers, - KEX_CLIENT_ENCRYPT, all_cipher) != 0 || - kex_assemble_names(&options->macs, - KEX_CLIENT_MAC, all_mac) != 0 || - kex_assemble_names(&options->kex_algorithms, - KEX_CLIENT_KEX, all_kex) != 0 || - kex_assemble_names(&options->hostbased_key_types, - KEX_DEFAULT_PK_ALG, all_key) != 0 || - kex_assemble_names(&options->pubkey_key_types, - KEX_DEFAULT_PK_ALG, all_key) != 0) - fatal("%s: kex_assemble_names failed", __func__); +#define ASSEMBLE(what, defaults, all) \ + do { \ + if ((r = kex_assemble_names(&options->what, \ + defaults, all)) != 0) \ + fatal("%s: %s: %s", __func__, #what, ssh_err(r)); \ + } while (0) + ASSEMBLE(ciphers, KEX_SERVER_ENCRYPT, all_cipher); + ASSEMBLE(macs, KEX_SERVER_MAC, all_mac); + ASSEMBLE(kex_algorithms, KEX_SERVER_KEX, all_kex); + ASSEMBLE(hostbased_key_types, KEX_DEFAULT_PK_ALG, all_key); + ASSEMBLE(pubkey_key_types, KEX_DEFAULT_PK_ALG, all_key); +#undef ASSEMBLE free(all_cipher); free(all_mac); free(all_kex); diff --git a/usr.bin/ssh/servconf.c b/usr.bin/ssh/servconf.c index 73efd7f8b38..fa1b760a7a6 100644 --- a/usr.bin/ssh/servconf.c +++ b/usr.bin/ssh/servconf.c @@ -1,5 +1,5 @@ -/* $OpenBSD: servconf.c,v 1.339 2018/07/11 18:53:29 markus Exp $ */ +/* $OpenBSD: servconf.c,v 1.340 2018/08/12 20:19:13 djm Exp $ */ /* * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland * All rights reserved @@ -178,24 +178,24 @@ static void assemble_algorithms(ServerOptions *o) { char *all_cipher, *all_mac, *all_kex, *all_key; + int r; all_cipher = cipher_alg_list(',', 0); all_mac = mac_alg_list(','); all_kex = kex_alg_list(','); all_key = sshkey_alg_list(0, 0, 1, ','); - if (kex_assemble_names(&o->ciphers, - KEX_SERVER_ENCRYPT, all_cipher) != 0 || - kex_assemble_names(&o->macs, - KEX_SERVER_MAC, all_mac) != 0 || - kex_assemble_names(&o->kex_algorithms, - KEX_SERVER_KEX, all_kex) != 0 || - kex_assemble_names(&o->hostkeyalgorithms, - KEX_DEFAULT_PK_ALG, all_key) != 0 || - kex_assemble_names(&o->hostbased_key_types, - KEX_DEFAULT_PK_ALG, all_key) != 0 || - kex_assemble_names(&o->pubkey_key_types, - KEX_DEFAULT_PK_ALG, all_key) != 0) - fatal("kex_assemble_names failed"); +#define ASSEMBLE(what, defaults, all) \ + do { \ + if ((r = kex_assemble_names(&o->what, defaults, all)) != 0) \ + fatal("%s: %s: %s", __func__, #what, ssh_err(r)); \ + } while (0) + ASSEMBLE(ciphers, KEX_SERVER_ENCRYPT, all_cipher); + ASSEMBLE(macs, KEX_SERVER_MAC, all_mac); + ASSEMBLE(kex_algorithms, KEX_SERVER_KEX, all_kex); + ASSEMBLE(hostkeyalgorithms, KEX_DEFAULT_PK_ALG, all_key); + ASSEMBLE(hostbased_key_types, KEX_DEFAULT_PK_ALG, all_key); + ASSEMBLE(pubkey_key_types, KEX_DEFAULT_PK_ALG, all_key); +#undef ASSEMBLE free(all_cipher); free(all_mac); free(all_kex); -- 2.20.1