Avoid possible dereference null pointer (src/bin/pg_dump/pg_dump.c)

Started by Ranier Vilelaover 1 year ago5 messages
#1Ranier Vilela
ranier.vf@gmail.com
1 attachment(s)

Hi.

Per Coverity.

I think that commit 6ebeeae
<http://6ebeeae29626e742bbe16db3fa6fccf1186c0dfb&gt; left out an oversight.

The report is:
CID 1559991: (#1 of 1): Dereference null return value (NULL_RETURNS)

The function *findTypeByOid* can return NULL.
It is necessary to check the function's return,
as is already done in other parts of the source.

patch attached.

Best regards,
Ranier Vilela

Attachments:

0001-avoid-possible-dereference-null-pointer-pg_dump.patchapplication/octet-stream; name=0001-avoid-possible-dereference-null-pointer-pg_dump.patchDownload
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index dacb033e98..546e7e4ce1 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -5420,7 +5420,10 @@ binary_upgrade_set_type_oids_by_type_oid(Archive *fout,
 					  pg_type_oid);
 
 	tinfo = findTypeByOid(pg_type_oid);
-	pg_type_array_oid = tinfo->typarray;
+	if (tinfo)
+		pg_type_array_oid = tinfo->typarray;
+	else
+		pg_type_array_oid = InvalidOid;
 
 	if (!OidIsValid(pg_type_array_oid) && force_array_type)
 		pg_type_array_oid = get_next_possible_free_pg_type_oid(fout, upgrade_query);
#2Nathan Bossart
nathandbossart@gmail.com
In reply to: Ranier Vilela (#1)
Re: Avoid possible dereference null pointer (src/bin/pg_dump/pg_dump.c)

On Wed, Sep 04, 2024 at 02:10:28PM -0300, Ranier Vilela wrote:

I think that commit 6ebeeae
<http://6ebeeae29626e742bbe16db3fa6fccf1186c0dfb&gt; left out an oversight.

The report is:
CID 1559991: (#1 of 1): Dereference null return value (NULL_RETURNS)

The function *findTypeByOid* can return NULL.
It is necessary to check the function's return,
as is already done in other parts of the source.

patch attached.

Yeah, that looks like a problem to me. I've cc'd Daniel here.

--
nathan

#3Daniel Gustafsson
daniel@yesql.se
In reply to: Nathan Bossart (#2)
Re: Avoid possible dereference null pointer (src/bin/pg_dump/pg_dump.c)

On 4 Sep 2024, at 19:30, Nathan Bossart <nathandbossart@gmail.com> wrote:

On Wed, Sep 04, 2024 at 02:10:28PM -0300, Ranier Vilela wrote:

I think that commit 6ebeeae
<http://6ebeeae29626e742bbe16db3fa6fccf1186c0dfb&gt; left out an oversight.

The report is:
CID 1559991: (#1 of 1): Dereference null return value (NULL_RETURNS)

The function *findTypeByOid* can return NULL.
It is necessary to check the function's return,
as is already done in other parts of the source.

patch attached.

Yeah, that looks like a problem to me. I've cc'd Daniel here.

Thanks for the report, it does seem genuine to me too. I'll get that handled
later today.

--
Daniel Gustafsson

#4Daniel Gustafsson
daniel@yesql.se
In reply to: Daniel Gustafsson (#3)
Re: Avoid possible dereference null pointer (src/bin/pg_dump/pg_dump.c)

On 4 Sep 2024, at 20:35, Daniel Gustafsson <daniel@yesql.se> wrote:

On 4 Sep 2024, at 19:30, Nathan Bossart <nathandbossart@gmail.com> wrote:
On Wed, Sep 04, 2024 at 02:10:28PM -0300, Ranier Vilela wrote:

patch attached.

Yeah, that looks like a problem to me. I've cc'd Daniel here.

Thanks for the report, it does seem genuine to me too. I'll get that handled
later today.

Applied, thanks!

--
Daniel Gustafsson

#5Ranier Vilela
ranier.vf@gmail.com
In reply to: Daniel Gustafsson (#4)
Re: Avoid possible dereference null pointer (src/bin/pg_dump/pg_dump.c)

Em qui., 5 de set. de 2024 às 10:39, Daniel Gustafsson <daniel@yesql.se>
escreveu:

On 4 Sep 2024, at 20:35, Daniel Gustafsson <daniel@yesql.se> wrote:

On 4 Sep 2024, at 19:30, Nathan Bossart <nathandbossart@gmail.com>

wrote:

On Wed, Sep 04, 2024 at 02:10:28PM -0300, Ranier Vilela wrote:

patch attached.

Yeah, that looks like a problem to me. I've cc'd Daniel here.

Thanks for the report, it does seem genuine to me too. I'll get that

handled

later today.

Applied, thanks!

Thank you Daniel.

best regards,
Ranier Vilela