From 02be4802d5f036e777671e188781e11c9bd7ad9e Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Sun, 6 Nov 2016 11:15:23 +0100 Subject: [PATCH] pki_ed25519: Do paranoia checks before we allocate memory Signed-off-by: Andreas Schneider --- src/pki_ed25519.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/pki_ed25519.c b/src/pki_ed25519.c index a51f6c6b..393948ac 100644 --- a/src/pki_ed25519.c +++ b/src/pki_ed25519.c @@ -76,16 +76,18 @@ int pki_ed25519_sign(const ssh_key privkey, if (rc != 0) { goto error; } - sig->ed25519_sig = malloc(ED25519_SIG_LEN); - if (sig->ed25519_sig == NULL) { - goto error; - } /* This shouldn't happen */ if (dlen - hlen != ED25519_SIG_LEN) { goto error; } - memcpy(sig->ed25519_sig, buffer, dlen - hlen); + + sig->ed25519_sig = malloc(ED25519_SIG_LEN); + if (sig->ed25519_sig == NULL) { + goto error; + } + + memcpy(sig->ed25519_sig, buffer, ED25519_SIG_LEN); SAFE_FREE(buffer); return SSH_OK;