From d0ffeba72e7100ea5af8a099660e90e74a4f1619 Mon Sep 17 00:00:00 2001 From: Marc Hoersken Date: Tue, 22 Dec 2015 13:36:56 +0100 Subject: [PATCH] wincng.c: fixed possible memory leak in _libssh2_wincng_hash If _libssh2_wincng_hash_update failed _libssh2_wincng_hash_final would never have been called before. Reported by Zenju. --- src/wincng.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/wincng.c b/src/wincng.c index 11dbbe3..6fa59d2 100755 --- a/src/wincng.c +++ b/src/wincng.c @@ -415,16 +415,15 @@ _libssh2_wincng_hash(unsigned char *data, unsigned long datalen, unsigned char *hash, unsigned long hashlen) { _libssh2_wincng_hash_ctx ctx; + int ret; - if (!_libssh2_wincng_hash_init(&ctx, hAlg, hashlen, NULL, 0)) { - if (!_libssh2_wincng_hash_update(&ctx, data, datalen)) { - if (!_libssh2_wincng_hash_final(&ctx, hash)) { - return 0; - } - } + ret = _libssh2_wincng_hash_init(&ctx, hAlg, hashlen, NULL, 0); + if (!ret) { + ret = _libssh2_wincng_hash_update(&ctx, data, datalen); + ret |= _libssh2_wincng_hash_final(&ctx, hash); } - return -1; + return ret; }