Bug 1389052 - Fix aligned_alloc emulation on i686, r=franziskus
authorDaiki Ueno <dueno@redhat.com>
Thu, 10 Aug 2017 11:54:47 +0200
changeset 13526 8019abedc833059e7333aadb269a2412fe6a14f5
parent 13523 990be4e30bf8a5f5619e0e6630ef7cc0784905fb
child 13527 431b37b7225c1ec796e7381bf37702070a643f55
push id2319
push userfranziskuskiefer@gmail.com
push dateFri, 11 Aug 2017 07:25:52 +0000
reviewersfranziskus
bugs1389052
Bug 1389052 - Fix aligned_alloc emulation on i686, r=franziskus
lib/freebl/gcm.c
lib/freebl/rijndael.c
--- a/lib/freebl/gcm.c
+++ b/lib/freebl/gcm.c
@@ -569,17 +569,17 @@ struct GCMContextStr {
     unsigned char tagKey[MAX_BLOCK_SIZE];
 };
 
 GCMContext *
 GCM_CreateContext(void *context, freeblCipherFunc cipher,
                   const unsigned char *params)
 {
     GCMContext *gcm = NULL;
-    gcmHashContext *ghash = NULL;
+    gcmHashContext *ghash = NULL, *ghashmem = NULL;
     unsigned char H[MAX_BLOCK_SIZE];
     unsigned int tmp;
     PRBool freeCtr = PR_FALSE;
     const CK_GCM_PARAMS *gcmParams = (const CK_GCM_PARAMS *)params;
     CK_AES_CTR_PARAMS ctrParams;
     SECStatus rv;
 #ifdef DISABLE_HW_GCM
     const PRBool sw = PR_TRUE;
@@ -591,23 +591,23 @@ GCM_CreateContext(void *context, freeblC
         PORT_SetError(SEC_ERROR_INVALID_ARGS);
         return NULL;
     }
     gcm = PORT_ZNew(GCMContext);
     if (gcm == NULL) {
         return NULL;
     }
     /* aligned_alloc is C11 so we have to do it the old way. */
-    ghash = PORT_ZAlloc(sizeof(gcmHashContext) + 15);
-    if (ghash == NULL) {
+    ghashmem = PORT_ZAlloc(sizeof(gcmHashContext) + 15);
+    if (ghashmem == NULL) {
         PORT_SetError(SEC_ERROR_NO_MEMORY);
         goto loser;
     }
-    ghash->mem = ghash;
-    ghash = (gcmHashContext *)(((uintptr_t)ghash + 15) & ~(uintptr_t)0x0F);
+    ghash = (gcmHashContext *)(((uintptr_t)ghashmem + 15) & ~(uintptr_t)0x0F);
+    ghash->mem = ghashmem;
 
     /* first plug in the ghash context */
     gcm->ghash_context = ghash;
     PORT_Memset(H, 0, AES_BLOCK_SIZE);
     rv = (*cipher)(context, H, &tmp, AES_BLOCK_SIZE, H, AES_BLOCK_SIZE, AES_BLOCK_SIZE);
     if (rv != SECSuccess) {
         goto loser;
     }
--- a/lib/freebl/rijndael.c
+++ b/lib/freebl/rijndael.c
@@ -1013,23 +1013,25 @@ rijndael_decryptCBC(AESContext *cx, unsi
  * BLAPI for the AES cipher, Rijndael.
  *
  ***********************************************************************/
 
 AESContext *
 AES_AllocateContext(void)
 {
     /* aligned_alloc is C11 so we have to do it the old way. */
-    AESContext *ctx = PORT_ZAlloc(sizeof(AESContext) + 15);
-    if (ctx == NULL) {
+    AESContext *ctx, *ctxmem;
+    ctxmem = PORT_ZAlloc(sizeof(AESContext) + 15);
+    if (ctxmem == NULL) {
         PORT_SetError(SEC_ERROR_NO_MEMORY);
         return NULL;
     }
-    ctx->mem = ctx;
-    return (AESContext *)(((uintptr_t)ctx + 15) & ~(uintptr_t)0x0F);
+    ctx = (AESContext *)(((uintptr_t)ctxmem + 15) & ~(uintptr_t)0x0F);
+    ctx->mem = ctxmem;
+    return ctx;
 }
 
 /*
 ** Initialize a new AES context suitable for AES encryption/decryption in
 ** the ECB or CBC mode.
 **  "mode" the mode of operation, which must be NSS_AES or NSS_AES_CBC
 */
 static SECStatus