From 036196b0b07ca8bdb5be9d59eef679e7cc72feff Mon Sep 17 00:00:00 2001 From: Marc Hoersken Date: Sun, 6 Dec 2015 21:30:01 +0100 Subject: [PATCH] hostkey.c: fix invalid memory access if libssh2_dsa_new fails Reported by dimmaq, fixes #66 --- src/hostkey.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/hostkey.c b/src/hostkey.c index add4495..faad8c9 100644 --- a/src/hostkey.c +++ b/src/hostkey.c @@ -274,6 +274,8 @@ hostkey_method_ssh_dss_init(LIBSSH2_SESSION * session, libssh2_dsa_ctx *dsactx; const unsigned char *p, *q, *g, *y, *s; unsigned long p_len, q_len, g_len, y_len, len; + int ret; + (void) hostkey_data_len; if (*abstract) { @@ -306,7 +308,11 @@ hostkey_method_ssh_dss_init(LIBSSH2_SESSION * session, y = s; /* s += y_len; */ - _libssh2_dsa_new(&dsactx, p, p_len, q, q_len, g, g_len, y, y_len, NULL, 0); + ret = _libssh2_dsa_new(&dsactx, p, p_len, q, q_len, + g, g_len, y, y_len, NULL, 0); + if (ret) { + return -1; + } *abstract = dsactx;