From 9331f5590baf731a4da45e4ff44f269ae71fd8dc Mon Sep 17 00:00:00 2001 From: =?utf8?q?Love=20H=C3=B6rnquist=20=C3=85strand?= Date: Sun, 24 Jul 2011 12:34:51 -0700 Subject: [PATCH] make sure keylen is a multiple of 2 --- lib/hcrypto/pkcs12.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/hcrypto/pkcs12.c b/lib/hcrypto/pkcs12.c index a890f01a3..ff0f77644 100644 --- a/lib/hcrypto/pkcs12.c +++ b/lib/hcrypto/pkcs12.c @@ -55,6 +55,13 @@ PKCS12_key_gen(const void *key, size_t keylen, unsigned char *outp = out; int i, vlen; + /** + * The argument key is pointing to an utf16 string, and thus + * keylen that is no a multiple of 2 is invalid. + */ + if (keylen & 1) + return 0; + ctx = EVP_MD_CTX_create(); if (ctx == NULL) return 0; @@ -83,7 +90,7 @@ PKCS12_key_gen(const void *key, size_t keylen, * empty string, in the empty string the UTF16 NUL terminator is * included into the string. */ - if (key && keylen >= 0) { + if (key) { for (i = 0; i < vlen / 2; i++) { I[(i * 2) + size_I] = 0; I[(i * 2) + size_I + 1] = ((unsigned char*)key)[i % (keylen + 1)]; -- 2.11.4.GIT