Find dangling membership roles in pg_dumpall

Started by Andreas 'ads' Scherbaumalmost 3 years ago4 messageshackers
Jump to latest
#1Andreas 'ads' Scherbaum
adsmail@wars-nicht.de

Hello,

pg_dumpall.c has a function dumpRoleMembership() which dumps all
membership roles. This function includes a piece of code which checks
if the membership tree has an open end which can't be resolved.
However that code is never used.

The variable prev_remaining is initially set to 0, and then never changed.
Which in turn never executes this code:

if (remaining == prev_remaining)

because the loop is only entered while "remaining > 0".

The attached patch fixes this problem, and updates prev_remaining inside
the loop.

Co-Author: Artur Zakirov <zaartur@gmail.com>
who reviewed the patch.

Regards

--
Andreas 'ads' Scherbaum
German PostgreSQL User Group
European PostgreSQL User Group - Board of Directors
Volunteer Regional Contact, Germany - PostgreSQL Project

Attachments:

pg_dumpall.patchtext/x-patch; charset=UTF-8; name=pg_dumpall.patchDownload+4-0
#2Daniel Gustafsson
daniel@yesql.se
In reply to: Andreas 'ads' Scherbaum (#1)
Re: Find dangling membership roles in pg_dumpall

On 26 Apr 2023, at 12:18, Andreas 'ads' Scherbaum <ads@pgug.de> wrote:

Hello,

pg_dumpall.c has a function dumpRoleMembership() which dumps all
membership roles. This function includes a piece of code which checks
if the membership tree has an open end which can't be resolved.
However that code is never used.

The variable prev_remaining is initially set to 0, and then never changed.
Which in turn never executes this code:

if (remaining == prev_remaining)

because the loop is only entered while "remaining > 0".

The attached patch fixes this problem, and updates prev_remaining inside
the loop.

Nice catch, that indeed seems like a proper fix. This was introduced in
ce6b672e44 and so doesn't need a backpatch.

--
Daniel Gustafsson

#3Daniel Gustafsson
daniel@yesql.se
In reply to: Daniel Gustafsson (#2)
Re: Find dangling membership roles in pg_dumpall

On 26 Apr 2023, at 13:02, Daniel Gustafsson <daniel@yesql.se> wrote:

On 26 Apr 2023, at 12:18, Andreas 'ads' Scherbaum <ads@pgug.de> wrote:

The attached patch fixes this problem, and updates prev_remaining inside
the loop.

Nice catch, that indeed seems like a proper fix. This was introduced in
ce6b672e44 and so doesn't need a backpatch.

Pushed, but without the comment extension as I felt the existing comment aptly
discussed the codepath. Thanks!

--
Daniel Gustafsson

#4Robert Haas
robertmhaas@gmail.com
In reply to: Daniel Gustafsson (#3)
Re: Find dangling membership roles in pg_dumpall

On Wed, Apr 26, 2023 at 8:29 AM Daniel Gustafsson <daniel@yesql.se> wrote:

Pushed, but without the comment extension as I felt the existing comment aptly
discussed the codepath. Thanks!

Woopsie. Thanks to both of you.

--
Robert Haas
EDB: http://www.enterprisedb.com