1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-11-27 13:21:11 +03:00

pki_ed25519: Do paranoia checks before we allocate memory

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
Andreas Schneider
2016-11-06 11:15:23 +01:00
parent 5437deed1b
commit 02be4802d5

View File

@@ -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;