[BUG FIX] Uninitialized var fargtypes used.

Started by Ranier Vilelaabout 6 years ago5 messages
#1Ranier Vilela
ranier_gyn@hotmail.com
1 attachment(s)

Hi,
Can anyone check this bug fix?

Thanks.
Ranier Vilela

--- \dll\postgresql-12.0\a\backend\commands\event_trigger.c     Mon Sep 30 17:06:55 2019
+++ event_trigger.c     Mon Nov 11 13:52:35 2019
@@ -171,7 +171,7 @@
         HeapTuple       tuple;
         Oid                     funcoid;
         Oid                     funcrettype;
-       Oid                     fargtypes[1];   /* dummy */
+       Oid                     fargtypes[1] = {InvalidOid, InvalidOid};        /* dummy */
         Oid                     evtowner = GetUserId();
         ListCell   *lc;
         List       *tags = NULL;

Attachments:

event_trigger.c.patchapplication/octet-stream; name=event_trigger.c.patchDownload
--- \dll\postgresql-12.0\a\backend\commands\event_trigger.c	Mon Sep 30 17:06:55 2019
+++ event_trigger.c	Mon Nov 11 13:52:35 2019
@@ -171,7 +171,7 @@
 	HeapTuple	tuple;
 	Oid			funcoid;
 	Oid			funcrettype;
-	Oid			fargtypes[1];	/* dummy */
+	Oid			fargtypes[1] = {InvalidOid, InvalidOid};	/* dummy */
 	Oid			evtowner = GetUserId();
 	ListCell   *lc;
 	List	   *tags = NULL;
#2Michael Paquier
michael@paquier.xyz
In reply to: Ranier Vilela (#1)
Re: [BUG FIX] Uninitialized var fargtypes used.

On Mon, Nov 11, 2019 at 06:28:47PM +0000, Ranier Vilela wrote:

Can anyone check this bug fix?

+++ event_trigger.c     Mon Nov 11 13:52:35 2019
@@ -171,7 +171,7 @@
HeapTuple       tuple;
Oid                     funcoid;
Oid                     funcrettype;
-       Oid                     fargtypes[1];   /* dummy */
+       Oid                     fargtypes[1] = {InvalidOid, InvalidOid};        /* dummy */
Oid                     evtowner = GetUserId();

Yeah, it would be better to fix this initialization.
--
Michael

#3Kyotaro Horiguchi
horikyota.ntt@gmail.com
In reply to: Michael Paquier (#2)
Re: [BUG FIX] Uninitialized var fargtypes used.

At Tue, 12 Nov 2019 12:31:41 +0900, Michael Paquier <michael@paquier.xyz> wrote in

On Mon, Nov 11, 2019 at 06:28:47PM +0000, Ranier Vilela wrote:

Can anyone check this bug fix?

+++ event_trigger.c     Mon Nov 11 13:52:35 2019
@@ -171,7 +171,7 @@
HeapTuple       tuple;
Oid                     funcoid;
Oid                     funcrettype;
-       Oid                     fargtypes[1];   /* dummy */
+       Oid                     fargtypes[1] = {InvalidOid, InvalidOid};        /* dummy */
Oid                     evtowner = GetUserId();

Yeah, it would be better to fix this initialization.

Agreed, but compiler should complain since the initializer is too
long. And I found at least five other instances of the same. Or there
might be similar cases.

find . -type f -exec egrep --color -nH --null -e 'LookupFuncName ?\(.*, ?0,' \{\} +
./pl/tcl/pltcl.c619: procOid = LookupFuncName(namelist, 0, fargtypes, false);
./backend/commands/trigger.c693: funcoid = LookupFuncName(stmt->funcname, 0, fargtypes, false);
./backend/commands/proclang.c108: handlerOid = LookupFuncName(funcname, 0, funcargtypes, true);
./backend/commands/proclang.c266: handlerOid = LookupFuncName(stmt->plhandler, 0, funcargtypes, false);
./backend/commands/event_trigger.c240: funcoid = LookupFuncName(stmt->funcname, 0, fargtypes, false);
./backend/commands/foreigncmds.c484: handlerOid = LookupFuncName((List *) handler->arg, 0, funcargtypes, false);

regards.

--
Kyotaro Horiguchi
NTT Open Source Software Center

#4Michael Paquier
michael@paquier.xyz
In reply to: Kyotaro Horiguchi (#3)
Re: [BUG FIX] Uninitialized var fargtypes used.

On Tue, Nov 12, 2019 at 03:27:35PM +0900, Kyotaro Horiguchi wrote:

At Tue, 12 Nov 2019 12:31:41 +0900, Michael Paquier <michael@paquier.xyz> wrote in

On Mon, Nov 11, 2019 at 06:28:47PM +0000, Ranier Vilela wrote:

Can anyone check this bug fix?

+++ event_trigger.c     Mon Nov 11 13:52:35 2019
@@ -171,7 +171,7 @@
HeapTuple       tuple;
Oid                     funcoid;
Oid                     funcrettype;
-       Oid                     fargtypes[1];   /* dummy */
+       Oid                     fargtypes[1] = {InvalidOid, InvalidOid};        /* dummy */
Oid                     evtowner = GetUserId();

Yeah, it would be better to fix this initialization.

Agreed, but compiler should complain since the initializer is too
long. And I found at least five other instances of the same. Or there
might be similar cases.

Would you like to write a patch with everything you found? I have
commented on a rather similar topic about the style of the
initialization close to here:
/messages/by-id/3378.1571684676@sss.pgh.pa.us

However, if it comes to InvalidOid and if we are talking about only
one element, I think that we should just assign the value without
memset.
--
Michael

#5Ranier Vilela
ranier_gyn@hotmail.com
In reply to: Michael Paquier (#2)
1 attachment(s)
RE: [BUG FIX] Uninitialized var fargtypes used.

Hi,
Sorry by error in the patch.

--- \dll\postgresql-12.0\a\backend\commands\event_trigger.c Mon Sep 30 17:06:55 2019
+++ event_trigger.c Tue Nov 12 08:34:30 2019
@@ -171,7 +171,7 @@
  HeapTuple tuple;
  Oid funcoid;
  Oid funcrettype;
- Oid fargtypes[1]; /* dummy */
+ Oid fargtypes[1] = {InvalidOid}; /* dummy */
  Oid evtowner = GetUserId();
  ListCell   *lc;
  List   *tags = NULL;

________________________________
De: Michael Paquier <michael@paquier.xyz>
Enviado: terça-feira, 12 de novembro de 2019 03:31
Para: Ranier Vilela <ranier_gyn@hotmail.com>
Cc: pgsql-hackers@lists.postgresql.org <pgsql-hackers@lists.postgresql.org>
Assunto: Re: [BUG FIX] Uninitialized var fargtypes used.

On Mon, Nov 11, 2019 at 06:28:47PM +0000, Ranier Vilela wrote:

Can anyone check this bug fix?

+++ event_trigger.c     Mon Nov 11 13:52:35 2019
@@ -171,7 +171,7 @@
HeapTuple       tuple;
Oid                     funcoid;
Oid                     funcrettype;
-       Oid                     fargtypes[1];   /* dummy */
+       Oid                     fargtypes[1] = {InvalidOid, InvalidOid};        /* dummy */
Oid                     evtowner = GetUserId();

Yeah, it would be better to fix this initialization.
--
Michael

Attachments:

event_trigger.c.patchapplication/octet-stream; name=event_trigger.c.patchDownload
--- \dll\postgresql-12.0\a\backend\commands\event_trigger.c	Mon Sep 30 17:06:55 2019
+++ event_trigger.c	Tue Nov 12 08:34:30 2019
@@ -171,7 +171,7 @@
 	HeapTuple	tuple;
 	Oid			funcoid;
 	Oid			funcrettype;
-	Oid			fargtypes[1];	/* dummy */
+	Oid			fargtypes[1] = {InvalidOid};	/* dummy */
 	Oid			evtowner = GetUserId();
 	ListCell   *lc;
 	List	   *tags = NULL;