Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 6362F1259185 for ; Fri, 27 Jan 2012 02:37:33 -0400 (AST) Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RqfRD-0002W0-BT for pgsql-bugs@postgresql.org; Fri, 27 Jan 2012 06:37:33 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id q0R6bB5p023890; Fri, 27 Jan 2012 01:37:11 -0500 (EST) To: Stefan Kaltenbrunner cc: Postgres-Bugs , Marko Kreen Subject: Re: pgcrypto decrypt_iv() issue In-reply-to: <4F1F23E8.80100@kaltenbrunner.cc> References: <4F1DB7BF.60304@kaltenbrunner.cc> <4F1F23E8.80100@kaltenbrunner.cc> Comments: In-reply-to Stefan Kaltenbrunner message dated "Tue, 24 Jan 2012 22:34:32 +0100" Date: Fri, 27 Jan 2012 01:37:11 -0500 Message-ID: <23889.1327646231@sss.pgh.pa.us> From: Tom Lane X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201201/187 X-Sequence-Number: 32254 Stefan Kaltenbrunner writes: > from some looking at the code in pgcrypto.c it seems to me that the > coding pattern in most functions there only checks for errors from the > corresponding initialization function, in the case of say decrypt_iv() > that means only the IV and the key are actually "validated" because that > is what the init function sees(it never sees that data!), if the actual > decrypt call fails (because the data is maybe a bit weird^broken) it > will happily ignore that and return random data. Yeah. In pg_decrypt() we have err = px_combo_init(c, (uint8 *) VARDATA(key), klen, NULL, 0); if (!err) err = px_combo_decrypt(c, (uint8 *) VARDATA(data), dlen, (uint8 *) VARDATA(res), &rlen); but in pg_decrypt_iv() it's just err = px_combo_init(c, (uint8 *) VARDATA(key), klen, (uint8 *) VARDATA(iv), ivlen); if (!err) px_combo_decrypt(c, (uint8 *) VARDATA(data), dlen, (uint8 *) VARDATA(res), &rlen); It looks to me like the result of px_combo_decrypt should be assigned to "err" here. If I make that change, the test case you provide is rejected: ERROR: decrypt_iv error: Data not a multiple of block size but the module's regression tests all still pass, indicating that this sort of case isn't tested. pg_encrypt_iv() has the identical usage error with respect to px_combo_encrypt. Marko, does this look right to you? regards, tom lane