pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Make initdb's suggested "pg_ctl start" command line more reliabl
8+ messages / 4 participants
[nested] [flat]

* pgsql: Make initdb's suggested "pg_ctl start" command line more reliabl
@ 2016-08-20 19:05 Tom Lane <tgl@sss.pgh.pa.us>
  2016-09-06 16:19 ` Re: [COMMITTERS] pgsql: Make initdb's suggested "pg_ctl start" command line more reliabl Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  0 siblings, 1 reply; 8+ messages in thread

From: Tom Lane @ 2016-08-20 19:05 UTC (permalink / raw)
  To: pgsql-committers

Make initdb's suggested "pg_ctl start" command line more reliable.

The original coding here was not nearly careful enough about quoting
special characters, and it didn't get corner cases right for constructing
the pg_ctl path either.  Use join_path_components() and appendShellString()
to do it honestly, so that the string will more likely work if blindly
copied-and-pasted.

While at it, teach appendShellString() not to quote strings that clearly
don't need it, so that the output from initdb doesn't become uglier than
it was before in typical cases where quoting is not needed.

Ryan Murphy, reviewed by Michael Paquier and myself

Discussion: <CAHeEsBeAe1FeBypT3E8R1ZVZU0e8xv3A-7BHg6bEOi=jZny2Uw@mail.gmail.com>

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/a00c58314745772f6c6a49b6d02a9572cd600bda

Modified Files
--------------
src/bin/initdb/Makefile     |  3 +++
src/bin/initdb/initdb.c     | 43 ++++++++++++++++++++++++++++---------------
src/fe_utils/string_utils.c | 17 +++++++++++++++--
3 files changed, 46 insertions(+), 17 deletions(-)


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: [COMMITTERS] pgsql: Make initdb's suggested "pg_ctl start" command line more reliabl
  2016-08-20 19:05 pgsql: Make initdb's suggested "pg_ctl start" command line more reliabl Tom Lane <tgl@sss.pgh.pa.us>
@ 2016-09-06 16:19 ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  2016-09-06 17:08   ` Re: Re: [COMMITTERS] pgsql: Make initdb's suggested "pg_ctl start" command line more reliabl Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 8+ messages in thread

From: Peter Eisentraut @ 2016-09-06 16:19 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-hackers <pgsql-hackers@postgresql.org>

On 8/20/16 3:05 PM, Tom Lane wrote:
> Make initdb's suggested "pg_ctl start" command line more reliable.
> 
> The original coding here was not nearly careful enough about quoting
> special characters, and it didn't get corner cases right for constructing
> the pg_ctl path either.  Use join_path_components() and appendShellString()
> to do it honestly, so that the string will more likely work if blindly
> copied-and-pasted.
> 
> While at it, teach appendShellString() not to quote strings that clearly
> don't need it, so that the output from initdb doesn't become uglier than
> it was before in typical cases where quoting is not needed.

A couple of problems with this:

The not-quoting-if-not-needed doesn't appear to do anything useful for me:

    'pg-install/bin/pg_ctl' -D 'pg-install/var/data' -l logfile start

The indentation of that line was changed from 4 to 10.  I don't think
that was a good change.

As just mentioned elsewhere, this accidentally introduces a failure if
the PostgreSQL installation path contains LF/CR, because of the use of
appendShellString().

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Re: [COMMITTERS] pgsql: Make initdb's suggested "pg_ctl start" command line more reliabl
  2016-08-20 19:05 pgsql: Make initdb's suggested "pg_ctl start" command line more reliabl Tom Lane <tgl@sss.pgh.pa.us>
  2016-09-06 16:19 ` Re: [COMMITTERS] pgsql: Make initdb's suggested "pg_ctl start" command line more reliabl Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
@ 2016-09-06 17:08   ` Tom Lane <tgl@sss.pgh.pa.us>
  2016-09-06 17:20     ` Re: Re: [COMMITTERS] pgsql: Make initdb's suggested "pg_ctl start" command line more reliabl Claudio Freire <klaussfreire@gmail.com>
  2016-09-06 17:23     ` Re: Re: [COMMITTERS] pgsql: Make initdb's suggested "pg_ctl start" command line more reliabl Andres Freund <andres@anarazel.de>
  2016-09-08 16:07     ` Re: Re: [COMMITTERS] pgsql: Make initdb's suggested "pg_ctl start" command line more reliabl Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  0 siblings, 3 replies; 8+ messages in thread

From: Tom Lane @ 2016-09-06 17:08 UTC (permalink / raw)
  To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; +Cc: pgsql-hackers <pgsql-hackers@postgresql.org>

Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:
> On 8/20/16 3:05 PM, Tom Lane wrote:
>> Make initdb's suggested "pg_ctl start" command line more reliable.

> A couple of problems with this:

> The not-quoting-if-not-needed doesn't appear to do anything useful for me:
>     'pg-install/bin/pg_ctl' -D 'pg-install/var/data' -l logfile start

Dash is considered a character that needs quoting.  It might be possible
to avoid that if we could be certain that appendShellString's output would
never be placed in a spot where it could be taken for a switch, but that
seems like a large assumption to me.  Or maybe we could treat it as
forcing quotes only if it starts the string; but I don't personally care
enough to write the code for that.  Feel free if you want to.

> The indentation of that line was changed from 4 to 10.  I don't think
> that was a good change.

Hmm, not intentional ... [ looks closely... ]  Looks like a tab got in
there somehow.  Will fix.

> As just mentioned elsewhere, this accidentally introduces a failure if
> the PostgreSQL installation path contains LF/CR, because of the use of
> appendShellString().

I think that's intentional, not accidental.  What actual use case is
there for allowing such paths?

			regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Re: [COMMITTERS] pgsql: Make initdb's suggested "pg_ctl start" command line more reliabl
  2016-08-20 19:05 pgsql: Make initdb's suggested "pg_ctl start" command line more reliabl Tom Lane <tgl@sss.pgh.pa.us>
  2016-09-06 16:19 ` Re: [COMMITTERS] pgsql: Make initdb's suggested "pg_ctl start" command line more reliabl Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  2016-09-06 17:08   ` Re: Re: [COMMITTERS] pgsql: Make initdb's suggested "pg_ctl start" command line more reliabl Tom Lane <tgl@sss.pgh.pa.us>
@ 2016-09-06 17:20     ` Claudio Freire <klaussfreire@gmail.com>
  2016-09-06 17:41       ` Re: Re: [COMMITTERS] pgsql: Make initdb's suggested "pg_ctl start" command line more reliabl Tom Lane <tgl@sss.pgh.pa.us>
  2 siblings, 1 reply; 8+ messages in thread

From: Claudio Freire @ 2016-09-06 17:20 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; pgsql-hackers <pgsql-hackers@postgresql.org>

On Tue, Sep 6, 2016 at 2:08 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> The not-quoting-if-not-needed doesn't appear to do anything useful for me:
>>     'pg-install/bin/pg_ctl' -D 'pg-install/var/data' -l logfile start
>
> Dash is considered a character that needs quoting.  It might be possible
> to avoid that if we could be certain that appendShellString's output would
> never be placed in a spot where it could be taken for a switch, but that
> seems like a large assumption to me.  Or maybe we could treat it as
> forcing quotes only if it starts the string; but I don't personally care
> enough to write the code for that.  Feel free if you want to.


Wouldn't it be taken for a switch even with quoting?

Quoting "-D" seems to work fine, which would suggest the above is true.


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Re: [COMMITTERS] pgsql: Make initdb's suggested "pg_ctl start" command line more reliabl
  2016-08-20 19:05 pgsql: Make initdb's suggested "pg_ctl start" command line more reliabl Tom Lane <tgl@sss.pgh.pa.us>
  2016-09-06 16:19 ` Re: [COMMITTERS] pgsql: Make initdb's suggested "pg_ctl start" command line more reliabl Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  2016-09-06 17:08   ` Re: Re: [COMMITTERS] pgsql: Make initdb's suggested "pg_ctl start" command line more reliabl Tom Lane <tgl@sss.pgh.pa.us>
  2016-09-06 17:20     ` Re: Re: [COMMITTERS] pgsql: Make initdb's suggested "pg_ctl start" command line more reliabl Claudio Freire <klaussfreire@gmail.com>
@ 2016-09-06 17:41       ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 8+ messages in thread

From: Tom Lane @ 2016-09-06 17:41 UTC (permalink / raw)
  To: Claudio Freire <klaussfreire@gmail.com>; +Cc: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; pgsql-hackers <pgsql-hackers@postgresql.org>

Claudio Freire <klaussfreire@gmail.com> writes:
> On Tue, Sep 6, 2016 at 2:08 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> Dash is considered a character that needs quoting.  It might be possible
>> to avoid that if we could be certain that appendShellString's output would
>> never be placed in a spot where it could be taken for a switch, but that
>> seems like a large assumption to me.

> Wouldn't it be taken for a switch even with quoting?
> Quoting "-D" seems to work fine, which would suggest the above is true.

[ thinks about that... ]  Oh, you're right, brain fade on my part.  The
shell doesn't care whether words are switches or not.  So actually the
risk-factor for us is whether we have designed any command-line syntaxes
in a way that would allow a path starting with a dash to cause bad things
to happen.  I have a feeling the answer is "yes", even without considering
the prospect that GNU getopt will arbitrarily rearrange the command words
on us depending on what it thinks is a switch.  (Maybe leading-dash is
another one of the things we'd better make a policy against.)

But meanwhile, yes, the argument for treating it as quotable in
appendShellString seems completely bogus.  I'll go change that.

			regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Re: [COMMITTERS] pgsql: Make initdb's suggested "pg_ctl start" command line more reliabl
  2016-08-20 19:05 pgsql: Make initdb's suggested "pg_ctl start" command line more reliabl Tom Lane <tgl@sss.pgh.pa.us>
  2016-09-06 16:19 ` Re: [COMMITTERS] pgsql: Make initdb's suggested "pg_ctl start" command line more reliabl Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  2016-09-06 17:08   ` Re: Re: [COMMITTERS] pgsql: Make initdb's suggested "pg_ctl start" command line more reliabl Tom Lane <tgl@sss.pgh.pa.us>
@ 2016-09-06 17:23     ` Andres Freund <andres@anarazel.de>
  2 siblings, 0 replies; 8+ messages in thread

From: Andres Freund @ 2016-09-06 17:23 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; pgsql-hackers <pgsql-hackers@postgresql.org>

On 2016-09-06 13:08:51 -0400, Tom Lane wrote:
> Dash is considered a character that needs quoting.  It might be possible
> to avoid that if we could be certain that appendShellString's output would
> never be placed in a spot where it could be taken for a switch, but that
> seems like a large assumption to me.  Or maybe we could treat it as
> forcing quotes only if it starts the string; but I don't personally care
> enough to write the code for that.  Feel free if you want to.

But quotes are interpreted by the shell, not by the called program. So I
don't think putting --whatnot in quotes changes anything here?


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Re: [COMMITTERS] pgsql: Make initdb's suggested "pg_ctl start" command line more reliabl
  2016-08-20 19:05 pgsql: Make initdb's suggested "pg_ctl start" command line more reliabl Tom Lane <tgl@sss.pgh.pa.us>
  2016-09-06 16:19 ` Re: [COMMITTERS] pgsql: Make initdb's suggested "pg_ctl start" command line more reliabl Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  2016-09-06 17:08   ` Re: Re: [COMMITTERS] pgsql: Make initdb's suggested "pg_ctl start" command line more reliabl Tom Lane <tgl@sss.pgh.pa.us>
@ 2016-09-08 16:07     ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  2016-09-08 16:48       ` Re: Re: [COMMITTERS] pgsql: Make initdb's suggested "pg_ctl start" command line more reliabl Tom Lane <tgl@sss.pgh.pa.us>
  2 siblings, 1 reply; 8+ messages in thread

From: Peter Eisentraut @ 2016-09-08 16:07 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-hackers <pgsql-hackers@postgresql.org>

On 9/6/16 1:08 PM, Tom Lane wrote:
>> As just mentioned elsewhere, this accidentally introduces a failure if
>> > the PostgreSQL installation path contains LF/CR, because of the use of
>> > appendShellString().
> I think that's intentional, not accidental.  What actual use case is
> there for allowing such paths?

There probably isn't one.  But we ought to be introducing this change in
a more intentional and consistent way.

For example, pg_basebackup has no such restriction.  So using
pg_basebackup, then promote, then pg_upgrade will (probably) fail now
for some paths.

More generally, I'm concerned that appendShellString() looks pretty
attractive for future use.  It's not inconceivable that someone will
want to use it for say calling pg_dump from pg_dumpall or pg_upgrade at
some point, and then maybe we'll accidentally disallow LF/CR in
tablespace names, say.

Also, if we're concerned about the potential for confusion that these
characters can cause, maybe we should be disallowing more control
characters in similar places.

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Re: [COMMITTERS] pgsql: Make initdb's suggested "pg_ctl start" command line more reliabl
  2016-08-20 19:05 pgsql: Make initdb's suggested "pg_ctl start" command line more reliabl Tom Lane <tgl@sss.pgh.pa.us>
  2016-09-06 16:19 ` Re: [COMMITTERS] pgsql: Make initdb's suggested "pg_ctl start" command line more reliabl Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  2016-09-06 17:08   ` Re: Re: [COMMITTERS] pgsql: Make initdb's suggested "pg_ctl start" command line more reliabl Tom Lane <tgl@sss.pgh.pa.us>
  2016-09-08 16:07     ` Re: Re: [COMMITTERS] pgsql: Make initdb's suggested "pg_ctl start" command line more reliabl Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
@ 2016-09-08 16:48       ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 8+ messages in thread

From: Tom Lane @ 2016-09-08 16:48 UTC (permalink / raw)
  To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; +Cc: pgsql-hackers <pgsql-hackers@postgresql.org>

Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:
> More generally, I'm concerned that appendShellString() looks pretty
> attractive for future use.  It's not inconceivable that someone will
> want to use it for say calling pg_dump from pg_dumpall or pg_upgrade at
> some point, and then maybe we'll accidentally disallow LF/CR in
> tablespace names, say.

That's fair, but I'm not sure how you propose to avoid it, given that
we don't have a method for safely quoting those characters on Windows.

I would certainly far rather find a way to do that and then remove the
prohibition.  But lacking such a solution, we're going to be forced into
messy compromises.

			regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



^ permalink  raw  reply  [nested|flat] 8+ messages in thread


end of thread, other threads:[~2016-09-08 16:48 UTC | newest]

Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-08-20 19:05 pgsql: Make initdb's suggested "pg_ctl start" command line more reliabl Tom Lane <tgl@sss.pgh.pa.us>
2016-09-06 16:19 ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2016-09-06 17:08   ` Tom Lane <tgl@sss.pgh.pa.us>
2016-09-06 17:20     ` Claudio Freire <klaussfreire@gmail.com>
2016-09-06 17:41       ` Tom Lane <tgl@sss.pgh.pa.us>
2016-09-06 17:23     ` Andres Freund <andres@anarazel.de>
2016-09-08 16:07     ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2016-09-08 16:48       ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox