When given oversized key, encrypt/decrypt corrupted
authorBruce Momjian <[email protected]>
Thu, 8 Nov 2001 15:56:58 +0000 (15:56 +0000)
committerBruce Momjian <[email protected]>
Thu, 8 Nov 2001 15:56:58 +0000 (15:56 +0000)
memory.  This fixes it.  Also a free() was missing.

marko

contrib/pgcrypto/px.c

index 5f9f0834ad659c272060a2e2a7efe815f0ce2c2b..19253bac16fe8ba0db7e5e2c1b34ff16f47f2aa5 100644 (file)
@@ -88,6 +88,8 @@ combo_init(PX_Combo * cx, const uint8 *key, uint klen,
                        memcpy(ivbuf, iv, ivlen);
        }
 
+       if (klen > ks)
+               klen = ks;
        keybuf = px_alloc(ks);
        memset(keybuf, 0, ks);
        memcpy(keybuf, key, klen);
@@ -96,6 +98,7 @@ combo_init(PX_Combo * cx, const uint8 *key, uint klen,
 
        if (ivbuf)
                px_free(ivbuf);
+       px_free(keybuf);
 
        return err;
 }