| From: | Ranier Vilela <ranier(dot)vf(at)gmail(dot)com> |
|---|---|
| To: | Japin Li <japinli(at)hotmail(dot)com> |
| Cc: | Pg Hackers <pgsql-hackers(at)postgresql(dot)org> |
| Subject: | Re: Simplifies checks (src/bin/pg_dump/pg_backup_archiver.c) |
| Date: | 2026-03-10 11:09:46 |
| Message-ID: | CAEudQApmqGU_QVTEgESGiL71RryR2f6F_OZcUjYw9PV=_+GNfw@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Em ter., 10 de mar. de 2026 às 03:12, Japin Li <japinli(at)hotmail(dot)com>
escreveu:
> On Mon, 09 Mar 2026 at 10:07, Ranier Vilela <ranier(dot)vf(at)gmail(dot)com> wrote:
> > Hi.
> >
> > Per Coverity.
> >
> > Coverity has some alerts about the function *RestoreArchive*,
> > arguing that there are null variable dereferences.
> >
> > I haven't done in-depth research to determine if this is correct or not.
> > However, the code can be simplified to a single check that would silence
> notifications and protect against this issue.
> >
> > patch attached.
>
> According to _allocAH(), te cannot be null.
>
> AH->toc = pg_malloc0_object(TocEntry);
>
> AH->toc->next = AH->toc;
> AH->toc->prev = AH->toc;
>
> So we can safely remove its null check.
>
> diff --git a/src/bin/pg_dump/pg_backup_archiver.c
> b/src/bin/pg_dump/pg_backup_archiver.c
> index df8a69d3b79..137e5850f8e 100644
> --- a/src/bin/pg_dump/pg_backup_archiver.c
> +++ b/src/bin/pg_dump/pg_backup_archiver.c
> @@ -767,7 +767,7 @@ RestoreArchive(Archive *AHX, bool append_data)
> continue; /* ignore if not
> to be dumped at all */
>
> /* Skip if no-tablespace is given. */
> - if (ropt->noTablespace && te && te->desc &&
> + if (ropt->noTablespace && te->desc &&
> (strcmp(te->desc, "TABLESPACE") == 0))
> continue;
>
> @@ -775,7 +775,7 @@ RestoreArchive(Archive *AHX, bool append_data)
> * Skip DROP DATABASE/ROLES/TABLESPACE if we
> didn't specify
> * --clean
> */
> - if (!ropt->dropSchema && te && te->desc &&
> + if (!ropt->dropSchema && te->desc &&
> strcmp(te->desc, "DROP_GLOBAL") == 0)
> continue;
>
+1
Yeah, *te* It was already dereferenced before these checks.
Therefore, they are useless.
best regards
Ranier Vilela
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Jim Jones | 2026-03-10 11:16:40 | Re: ALTER TABLE: warn when actions do not recurse to partitions |
| Previous Message | Oleg Tselebrovskiy | 2026-03-10 11:01:47 | Re: psql's 001_basic.pl test could fail on very slow machines |