summaryrefslogtreecommitdiffstats
path: root/apps/pkeyutl.c
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2018-05-17 12:53:07 +0100
committerMatt Caswell <matt@openssl.org>2018-05-24 17:26:03 +0100
commita0abb6a10f4c5fc6dd20c487aa0db085fbfb3562 (patch)
tree711cca97bea1c2b1a25d66496c246e1592332282 /apps/pkeyutl.c
parent07824f304a220ea09ec369bad60f4fcfd01d5d14 (diff)
Add a sanity check on the length of pkeyutl inputs
When signing or verifying a file using pkeyutl the input is supposed to be a hash. Some algorithms sanity check the length of the input, while others don't and silently truncate. To avoid accidents we check that the length of the input looks sane. Reviewed-by: Rich Salz <rsalz@openssl.org> (Merged from https://github.com/openssl/openssl/pull/6284)
Diffstat (limited to 'apps/pkeyutl.c')
-rw-r--r--apps/pkeyutl.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/apps/pkeyutl.c b/apps/pkeyutl.c
index 911cc57642..2c4e524b69 100644
--- a/apps/pkeyutl.c
+++ b/apps/pkeyutl.c
@@ -282,7 +282,7 @@ int pkeyutl_main(int argc, char **argv)
buf_inlen = bio_to_mem(&buf_in, keysize * 10, in);
if (buf_inlen < 0) {
BIO_printf(bio_err, "Error reading input Data\n");
- exit(1);
+ goto end;
}
if (rev) {
size_t i;
@@ -296,6 +296,16 @@ int pkeyutl_main(int argc, char **argv)
}
}
+ /* Sanity check the input */
+ if (buf_inlen > EVP_MAX_MD_SIZE
+ && (pkey_op == EVP_PKEY_OP_SIGN
+ || pkey_op == EVP_PKEY_OP_VERIFY
+ || pkey_op == EVP_PKEY_OP_VERIFYRECOVER)) {
+ BIO_printf(bio_err,
+ "Error: The input data looks too long to be a hash\n");
+ goto end;
+ }
+
if (pkey_op == EVP_PKEY_OP_VERIFY) {
rv = EVP_PKEY_verify(ctx, sig, (size_t)siglen,
buf_in, (size_t)buf_inlen);