[BUG?] missing array index may result in a wrong constraint name (pg_dump, bin-upgrade, >=18) - Mailing list pgsql-hackers

From George Tarasov
Subject [BUG?] missing array index may result in a wrong constraint name (pg_dump, bin-upgrade, >=18)
Date
Msg-id f3029f25-acc9-4cb9-a74f-fe93bcfb3a27@gmail.com
Whole thread Raw
Responses Re: [BUG?] missing array index may result in a wrong constraint name (pg_dump, bin-upgrade, >=18)
List 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




pgsql-hackers by date:

Previous
From: Jacob Champion
Date:
Subject: Re: [oauth] Stabilize the libpq-oauth ABI (and allow alternative implementations?)
Next
From: Amit Kapila
Date:
Subject: Re: Skipping schema changes in publication