From 41becb5ff46f11690d427f353f7504a51e74e210 Mon Sep 17 00:00:00 2001 From: Ryan Sleevi Date: Fri, 9 Jan 2015 14:49:18 -0800 Subject: Bug 1094492 - Avoid corrupting memory if the allocator fails. r=wtc --- lib/pk11wrap/pk11mech.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'lib/pk11wrap/pk11mech.c') diff --git a/lib/pk11wrap/pk11mech.c b/lib/pk11wrap/pk11mech.c index e15a286b1..b7a7296b3 100644 --- a/lib/pk11wrap/pk11mech.c +++ b/lib/pk11wrap/pk11mech.c @@ -1378,12 +1378,13 @@ pk11_GenerateNewParamWithKeyLen(CK_MECHANISM_TYPE type, int keyLen) SECItem iv; SECStatus rv; - mech = (SECItem *) PORT_Alloc(sizeof(SECItem)); if (mech == NULL) return NULL; rv = SECSuccess; mech->type = siBuffer; + mech->data = NULL; + mech->len = 0; switch (type) { case CKM_RC4: case CKM_SEED_ECB: @@ -1396,8 +1397,6 @@ pk11_GenerateNewParamWithKeyLen(CK_MECHANISM_TYPE type, int keyLen) case CKM_CAST_ECB: case CKM_CAST3_ECB: case CKM_CAST5_ECB: - mech->data = NULL; - mech->len = 0; break; case CKM_RC2_ECB: rc2_ecb_params = (CK_RC2_PARAMS *)PORT_Alloc(sizeof(CK_RC2_PARAMS)); @@ -1445,8 +1444,6 @@ pk11_GenerateNewParamWithKeyLen(CK_MECHANISM_TYPE type, int keyLen) return PK11_ParamFromIV(type,&iv); default: if (pk11_lookup(type)->iv == 0) { - mech->data = NULL; - mech->len = 0; break; } case CKM_SEED_CBC: -- cgit v1.2.1