8000 Fix combo_decrypt() to throw an error for zero-length input when using a · larkly/postgres-docker@10a81b3 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 10a81b3

Browse files
committed
Fix combo_decrypt() to throw an error for zero-length input when using a
padded encryption scheme. Formerly it would try to access res[(unsigned) -1], which resulted in core dumps on 64-bit machines, and was certainly trouble waiting to happen on 32-bit machines (though in at least the known case it was harmless because that byte would be overwritten after return). Per report from Ken Colson; fix by Marko Kreen.
1 parent ffaaaf9 commit 10a81b3

File tree

1 file changed

+13
-1
lines changed
  • contrib/pgcrypto

1 file changed

+13
-1
lines changed

contrib/pgcrypto/px.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2727
* SUCH DAMAGE.
2828
*
29-
* $Id: px.c,v 1.7 2002/03/06 06:09:10 momjian Exp $
29+
* $Id: px.c,v 1.7.2.1 2007/08/23 16:16:27 tgl Exp $
3030
*/
3131

3232
#include <postgres.h>
@@ -185,6 +185,18 @@ combo_decrypt(PX_Combo * cx, const uint8 *data, unsigned dlen,
185185

186186
PX_Cipher *c = cx->cipher;
187187

188+
/* decide whether zero-length input is allowed */
189+
if (dlen == 0)
190+
{
191+
/* with padding, empty ciphertext is not allowed */
192+
if (cx->padding)
193+
return -1;
194+
195+
/* without padding, report empty result */
196+
*rlen = 0;
197+
return 0;
198+
}
199+
188200
bs = px_cipher_block_size(c);
189201
if (bs > 1 && (dlen % bs) != 0)
190202
goto block_error;

0 commit comments

Comments
 (0)
0