Re: BUG #16304: ECPG won't accept input from STDIN

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: jim_gray(at)cox(dot)net, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #16304: ECPG won't accept input from STDIN
Date: 2020-03-23 04:20:51
Message-ID: 18355.1584937251@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Bruce Momjian <bruce(at)momjian(dot)us> writes:
> On Mon, Mar 16, 2020 at 08:48:22PM +0000, PG Bug reporting form wrote:
>> On an older version (9.6.3) of Postgres on CentOS 7.7.1908, ECPG accepts
>> input from STDIN:
>> ...
>> On a newer version (11.5) of Postgres on AIX 7.2, ECPG does NOT accept input
>> from STDIN:
>> I suspect a problem in the Postgres version of getopt_long.c

> Yeah, you might be right. In some cases we use the libc (maybe GNU)
> getopt-long, and in other cases we use our own version, and there are
> behavioral differences between the two. The fact you are testing on
> CentOS and the other on AIX probably explains it. I think using
> /dev/stdin should work on both.

Oooh! I'd looked at this report and figured that somebody broke ecpg's
command parsing, not thinking hard about the platform dependence angle.
But you are both right: our version of getopt_long() fails to treat
bare "-" correctly. It starts parsing it as options, fails to find
'\0' in the options string, and returns BADCH. This is

(a) useless; there's no possible value in that behavior

(b) unlike what GNU getopt_long does

(c) clearly not what ecpg is expecting. Although it's not documented
(also our bad), a look at ecpg.c clearly shows that it intends to
treat bare "-" as a filename argument meaning stdin

(d) arguably wrong according to POSIX. POSIX doesn't specify getopt_long
of course, but it does specify getopt(), and that page is absolutely
unambiguous that an argv element containing just "-" is to be treated
as a non-switch argument. (Which indeed our version of getopt does)

So I think we ought to fix it, as attached. I've verified that on
a platform using our getopt_long, ecpg misbehaves as reported, and
this fixes it.

We should also fix ecpg's documentation...

regards, tom lane

Attachment Content-Type Size
fix-getopt-long-for-bare-dash.patch text/x-diff 698 bytes

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Richard Guo 2020-03-23 13:13:48 Negative cost is seen for plan node
Previous Message Bruce Momjian 2020-03-23 02:45:09 Re: BUG #16304: ECPG won't accept input from STDIN