initdb --pwfile /dev/zero

Started by Andres Freundover 4 years ago4 messageshackers
Jump to latest
#1Andres Freund
andres@anarazel.de

Hi,

A colleague tried PG 14 internally and it failed during cluster creation, when
using the PGDG rpm packages. A bit of debugging shows that the problem is
that the packaging script specifies the password using --pwfile /dev/zero.

In 14+ this turns out to lead to an endless loop in pg_get_line_append().

The --pwfile /dev/zero was added in
https://git.postgresql.org/gitweb/?p=pgrpms.git;a=commitdiff;h=8ca418709ef49a1781f0ea8e6166b139106135ff

Devrim, what was the goal? Even in 13 this didn't achieve anything?

While I don't think passing /dev/zero is a good idea (it mostly seems to
circumvent ""password file \"%s\" is empty", without achieving anything, given
the password will be empty). I think we still ought to make pg_get_line() a
bit more resilient against '\0'?

Greetings,

Andres Freund

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Andres Freund (#1)
Re: initdb --pwfile /dev/zero

Andres Freund <andres@anarazel.de> writes:

A colleague tried PG 14 internally and it failed during cluster creation, when
using the PGDG rpm packages. A bit of debugging shows that the problem is
that the packaging script specifies the password using --pwfile /dev/zero.

In 14+ this turns out to lead to an endless loop in pg_get_line_append().

Well, that's because that file will source an infinite amount of stuff.

I think we still ought to make pg_get_line() a
bit more resilient against '\0'?

I don't think '\0' is the problem. The only fix for this would be to
re-introduce some fixed limit on how long a line we'll read, which
I'm not too thrilled about. I think this is better classified as
user error.

regards, tom lane

#3Andres Freund
andres@anarazel.de
In reply to: Tom Lane (#2)
Re: initdb --pwfile /dev/zero

Hi,

On 2021-09-17 14:48:42 -0400, Tom Lane wrote:

Andres Freund <andres@anarazel.de> writes:

A colleague tried PG 14 internally and it failed during cluster creation, when
using the PGDG rpm packages. A bit of debugging shows that the problem is
that the packaging script specifies the password using --pwfile /dev/zero.

In 14+ this turns out to lead to an endless loop in pg_get_line_append().

Well, that's because that file will source an infinite amount of stuff.

I think we still ought to make pg_get_line() a
bit more resilient against '\0'?

I don't think '\0' is the problem. The only fix for this would be to
re-introduce some fixed limit on how long a line we'll read, which
I'm not too thrilled about.

Well, '\0' can be classified as the end of a line imo. So I don't think it'd
require a line lenght limit.

I think this is better classified as user error.

I also can live with that.

I don't really understand how the current PGDG rpms work given this? Does
nobody use the provided /usr/pgsql-14/bin/postgresql-14-setup?

https://git.postgresql.org/gitweb/?p=pgrpms.git;a=blob;f=rpm/redhat/master/non-common/postgresql-14/main/postgresql-14-setup;h=d111033fc3f3bc03c243f424fd60c3e8ddf2e466;hb=HEAD#l139

Greetings,

Andres Freund

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Andres Freund (#3)
Re: initdb --pwfile /dev/zero

Andres Freund <andres@anarazel.de> writes:

On 2021-09-17 14:48:42 -0400, Tom Lane wrote:

I don't think '\0' is the problem. The only fix for this would be to
re-introduce some fixed limit on how long a line we'll read, which
I'm not too thrilled about.

Well, '\0' can be classified as the end of a line imo. So I don't think it'd
require a line lenght limit.

Meh. Those functions are specified to act like fgets(), which does not
think that \0 terminates a line AFAIK.

regards, tom lane