Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id A99481259185 for ; Fri, 27 Jan 2012 13:43:33 -0400 (AST) Received: from mail-ee0-f46.google.com ([74.125.83.46]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Rqppl-0004UG-0R for pgsql-bugs@postgresql.org; Fri, 27 Jan 2012 17:43:33 +0000 Received: by eekc14 with SMTP id c14so646223eek.19 for ; Fri, 27 Jan 2012 09:43:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to; bh=DjcOkxYkcSaFhuPx+TTECFbPl+v/1E0L0rVs3UMPf/Y=; b=pc6ZNDH7+nrJ3keEwI35DfqpDyuIGaWcwES4jTn9m8A/ROC0uipb5ffU/H1gaRblR5 kNYuRZXmcbyfCcj5WkK6HZJbYCKIkC1Mmp4YzdVxgH3p6oKQvEGpPTAlHhofzAup+k4e aMkfdYKgHseP3dReih2GCNSkTyEtrWaI6R+nU= Received: by 10.14.3.154 with SMTP id 26mr2484103eeh.40.1327686199967; Fri, 27 Jan 2012 09:43:19 -0800 (PST) Received: from gmail.com (turu7.ee. [217.159.207.194]) by mx.google.com with ESMTPS id c16sm31959983eei.1.2012.01.27.09.43.18 (version=SSLv3 cipher=OTHER); Fri, 27 Jan 2012 09:43:19 -0800 (PST) Date: Fri, 27 Jan 2012 19:43:16 +0200 From: Marko Kreen To: Tom Lane Cc: Stefan Kaltenbrunner , Postgres-Bugs Subject: Re: pgcrypto decrypt_iv() issue Message-ID: <20120127174316.GA5955@gmail.com> References: <4F1DB7BF.60304@kaltenbrunner.cc> <4F1F23E8.80100@kaltenbrunner.cc> <23889.1327646231@sss.pgh.pa.us> <20120127152056.GA4107@gmail.com> <10056.1327684401@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="AhhlLboLdkugWU4S" Content-Disposition: inline In-Reply-To: <10056.1327684401@sss.pgh.pa.us> X-Pg-Spam-Score: -2.6 (--) X-Archive-Number: 201201/195 X-Sequence-Number: 32262 --AhhlLboLdkugWU4S Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Jan 27, 2012 at 12:13:21PM -0500, Tom Lane wrote: > Marko Kreen writes: > > pgcrypto.c is easily fixable and internal.c has proper checks. > > But openssl.c does not. And I have a bigger openssl.c cleanup > > pending. So I would prefer to add missing checks to cleaned-up > > openssl.c and post them together (soonish). > > > But I'm bit unclear about fate of /contrib cleanup patches vs. 9.2, > > so if they won't get in, it's ok to apply quick fixes to current tree, > > it won't inconvinience me much. > > I think we should fix and back-patch these two specific bugs. The > openssl.c change sounds like it might be something for HEAD only. Now I looked more in-depth and seems my comments were off - error detection for encrypt()/decrypt() happens in px.c not in internal.c/openssl.c. Latter ones simply validate internal APIs. So attached patch should be enough to fix the issue. And it should be quite backportable. -- marko --AhhlLboLdkugWU4S Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="encrypt_iv.diff" diff --git a/contrib/pgcrypto/pgcrypto.c b/contrib/pgcrypto/pgcrypto.c index c758853..a441ca7 100644 --- a/contrib/pgcrypto/pgcrypto.c +++ b/contrib/pgcrypto/pgcrypto.c @@ -341,8 +341,8 @@ pg_encrypt_iv(PG_FUNCTION_ARGS) err = px_combo_init(c, (uint8 *) VARDATA(key), klen, (uint8 *) VARDATA(iv), ivlen); if (!err) - px_combo_encrypt(c, (uint8 *) VARDATA(data), dlen, - (uint8 *) VARDATA(res), &rlen); + err = px_combo_encrypt(c, (uint8 *) VARDATA(data), dlen, + (uint8 *) VARDATA(res), &rlen); px_combo_free(c); @@ -395,8 +395,8 @@ pg_decrypt_iv(PG_FUNCTION_ARGS) 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); + err = px_combo_decrypt(c, (uint8 *) VARDATA(data), dlen, + (uint8 *) VARDATA(res), &rlen); px_combo_free(c); --AhhlLboLdkugWU4S--