From 6af24baf38d360e45a85f63c3135acfc24939fe2 Mon Sep 17 00:00:00 2001 From: John Safranek Date: Mon, 24 Oct 2016 15:24:04 -0700 Subject: [PATCH] Fixed a missed set of wolfCrypt functions whose return values weren't getting checked. --- src/internal.c | 50 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/src/internal.c b/src/internal.c index 35f93d03..8685abf9 100644 --- a/src/internal.c +++ b/src/internal.c @@ -3424,30 +3424,46 @@ int SendKexDhReply(WOLFSSH* ssh) wc_FreeDhKey(&dhKey); /* Hash in the server's DH f-value. */ - c32toa(fSz + fPad, scratchLen); - wc_ShaUpdate(&ssh->handshake->hash, scratchLen, LENGTH_SZ); - if (fPad) { - scratchLen[0] = 0; - wc_ShaUpdate(&ssh->handshake->hash, scratchLen, 1); + if (ret == 0) { + c32toa(fSz + fPad, scratchLen); + ret = wc_ShaUpdate(&ssh->handshake->hash, + scratchLen, LENGTH_SZ); } - wc_ShaUpdate(&ssh->handshake->hash, f, fSz); + if (ret == 0) { + if (fPad) { + scratchLen[0] = 0; + ret = wc_ShaUpdate(&ssh->handshake->hash, scratchLen, 1); + } + } + if (ret == 0) + ret = wc_ShaUpdate(&ssh->handshake->hash, f, fSz); /* Hash in the shared secret k. */ - c32toa(ssh->kSz + kPad, scratchLen); - wc_ShaUpdate(&ssh->handshake->hash, scratchLen, LENGTH_SZ); - if (kPad) { - scratchLen[0] = 0; - wc_ShaUpdate(&ssh->handshake->hash, scratchLen, 1); + if (ret == 0) { + c32toa(ssh->kSz + kPad, scratchLen); + ret = wc_ShaUpdate(&ssh->handshake->hash, + scratchLen, LENGTH_SZ); } - wc_ShaUpdate(&ssh->handshake->hash, ssh->k, ssh->kSz); + if (ret == 0) { + if (kPad) { + scratchLen[0] = 0; + ret = wc_ShaUpdate(&ssh->handshake->hash, scratchLen, 1); + } + } + if (ret == 0) + ret = wc_ShaUpdate(&ssh->handshake->hash, ssh->k, ssh->kSz); /* Save the handshake hash value h, and session ID. */ - wc_ShaFinal(&ssh->handshake->hash, ssh->h); - ssh->hSz = SHA_DIGEST_SIZE; - if (ssh->sessionIdSz == 0) { - WMEMCPY(ssh->sessionId, ssh->h, ssh->hSz); - ssh->sessionIdSz = ssh->hSz; + if (ret == 0) + ret = wc_ShaFinal(&ssh->handshake->hash, ssh->h); + if (ret == 0) { + ssh->hSz = SHA_DIGEST_SIZE; + if (ssh->sessionIdSz == 0) { + WMEMCPY(ssh->sessionId, ssh->h, ssh->hSz); + ssh->sessionIdSz = ssh->hSz; + } } + if (ret != WS_SUCCESS) ret = WS_CRYPTO_FAILED; }