diff --git a/contrib/pgcrypto/px.c b/contrib/pgcrypto/px.c
index 4205e9c3ef..d3e057a453 100644
--- a/contrib/pgcrypto/px.c
+++ b/contrib/pgcrypto/px.c
@@ -198,10 +198,13 @@ combo_init(PX_Combo *cx, const uint8 *key, unsigned klen,
 	if (ivs > 0)
 	{
 		ivbuf = palloc0(ivs);
-		if (ivlen > ivs)
-			memcpy(ivbuf, iv, ivs);
-		else
-			memcpy(ivbuf, iv, ivlen);
+		if (iv != NULL)
+		{
+			if (ivlen > ivs)
+				memcpy(ivbuf, iv, ivs);
+			else
+				memcpy(ivbuf, iv, ivlen);
+		}
 	}
 
 	if (klen > ks)
