[BUG?] missing array index may result in a wrong constraint name (pg_dump, bin-upgrade, >=18)
George Tarasov <george.v.tarasov@gmail.com>
From: George Tarasov <george.v.tarasov@gmail.com>
To: pgsql-hackers@postgresql.org
Date: 2026-03-07T00:28:14Z
Lists: pgsql-hackers
Greetings!
I performed static code analysis and got an error: ALWAYS FALSE SUBEXPR!
Let's look at a little snippet (pg_dump.c:10203).
/*
* In binary upgrade of inheritance child tables, must have a
* constraint name that we can UPDATE later; same if there's a
* comment on the constraint.
*/
if ((dopt->binary_upgrade &&
!tbinfo->ispartition &&
!tbinfo->notnull_islocal) ||
^^^^^^^^^^^^^^^^^^^^^^^^ ALWAYS FALSE SUBEXPR!
!PQgetisnull(res, r, i_notnull_comment))
{
It seems like index "[j]" is missing for this subexpression to make any
sense.
"notnull_islocal" is an array of bools. It is _always_ created before
this snippet
in function "getTableAttrs()". So, the value of tbinfo->notnull_islocal
is _always_ TRUE
(it is a valid memory pointer), and therefore the entire subexpression
is _always_ FALSE.
And so, in binary upgrade mode this condition may not be evaluated as
expected
(when there's NO comment on the constraint!).
To be honest, I don't fully understand the overall logic behind these
preparations
for further processing (in pg_dump), but it seems like "[j]" index is
definitely missing.
That is how it should be.
/*
* In binary upgrade of inheritance child tables, must have a
* constraint name that we can UPDATE later; same if there's a
* comment on the constraint.
*/
if ((dopt->binary_upgrade &&
!tbinfo->ispartition &&
!tbinfo->notnull_islocal[j]) ||
^^^ MISSING ARRAY INDEX!
!PQgetisnull(res, r, i_notnull_comment))
{
Dear, Hackers! Please review.
Is there a really mistake here or am I wrong to raise this issue?
Thanks!
George Tarasov
Commits
-
Fix invalid boolean if-test
- eb2c867b0aab 19 (unreleased) landed
- 3a9cf1c925a0 18.4 landed