public inbox for [email protected]  
help / color / mirror / Atom feed
From: Zhihong Yu <[email protected]>
To: PostgreSQL-development <[email protected]>
Subject: null iv parameter passed to combo_init()
Date: Fri, 7 Jan 2022 16:32:01 -0800
Message-ID: <CALNJ-vSBb2Ees=KB0frYBh7foK-QNZMbK7Vz66bUJa09D+CHAw@mail.gmail.com> (raw)

Hi,
In contrib/pgcrypto/pgcrypto.c :

    err = px_combo_init(c, (uint8 *) VARDATA_ANY(key), klen, NULL, 0);

Note: NULL is passed as iv.

When combo_init() is called,

        if (ivlen > ivs)
            memcpy(ivbuf, iv, ivs);
        else
            memcpy(ivbuf, iv, ivlen);

It seems we need to consider the case of null being passed as iv for
memcpy() because of this:

/usr/include/string.h:44:28: note: nonnull attribute specified here

What do you think of the following patch ?

Cheers


Attachments:

  [application/octet-stream] memcpy-null-iv.patch (503B, ../CALNJ-vSBb2Ees=KB0frYBh7foK-QNZMbK7Vz66bUJa09D+CHAw@mail.gmail.com/3-memcpy-null-iv.patch)
  download | inline diff:
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)


view thread (4+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected]
  Subject: Re: null iv parameter passed to combo_init()
  In-Reply-To: <CALNJ-vSBb2Ees=KB0frYBh7foK-QNZMbK7Vz66bUJa09D+CHAw@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox