pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #16304: ECPG won't accept input from STDIN
3+ messages / 3 participants
[nested] [flat]

Commits from this thread:
  2020-03-23 980a70b976 036fdf6be2 aae7e8530d c0eb57dd98 5f9eace5db ef7d6d79af  Fix our getopt_long's behavior for a command line argument of just "-".
* BUG #16304: ECPG won't accept input from STDIN
@ 2020-03-16 20:48 PG Bug reporting form <noreply@postgresql.org>
  2020-03-23 02:45 ` Re: BUG #16304: ECPG won't accept input from STDIN Bruce Momjian <bruce@momjian.us>
  0 siblings, 1 reply; 3+ messages in thread

From: PG Bug reporting form @ 2020-03-16 20:48 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: jim_gray@cox.net

The following bug has been logged on the website:

Bug reference:      16304
Logged by:          James Gray
Email address:      jim_gray@cox.net
PostgreSQL version: 11.5
Operating system:   AIX
Description:        

On an older version (9.6.3) of Postgres on CentOS 7.7.1908, ECPG accepts
input from STDIN:

[singha7] (jgray) ~> psql --version
psql (PostgreSQL) 9.6.3
[singha7] (jgray) ~>

[singha7] (jgray) ~> ecpg -o - -
/* Processed by ecpg (4.12.0) */
/* These include files are added by the preprocessor */
#include <ecpglib.h>
#include <ecpgerrno.h>
#include <sqlca.h>
/* End of automatic include section */

#line 1 "stdin"
^C
[singha7] (jgray) ~>

On a newer version (11.5) of Postgres on AIX 7.2, ECPG does NOT accept input
from STDIN:

bash-5.0$ psql --version
psql (PostgreSQL) 11.5
bash-5.0$

bash-5.0$ ecpg -o - -
Try "ecpg --help" for more information.
bash-5.0$

I suspect a problem in the Postgres version of getopt_long.c



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

* Re: BUG #16304: ECPG won't accept input from STDIN
  2020-03-16 20:48 BUG #16304: ECPG won't accept input from STDIN PG Bug reporting form <noreply@postgresql.org>
@ 2020-03-23 02:45 ` Bruce Momjian <bruce@momjian.us>
  2020-03-23 04:20   ` Re: BUG #16304: ECPG won't accept input from STDIN Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 3+ messages in thread

From: Bruce Momjian @ 2020-03-23 02:45 UTC (permalink / raw)
  To: jim_gray@cox.net; pgsql-bugs@lists.postgresql.org

On Mon, Mar 16, 2020 at 08:48:22PM +0000, PG Bug reporting form wrote:
> The following bug has been logged on the website:
> 
> Bug reference:      16304
> Logged by:          James Gray
> Email address:      jim_gray@cox.net
> PostgreSQL version: 11.5
> Operating system:   AIX
> Description:        
> 
> On an older version (9.6.3) of Postgres on CentOS 7.7.1908, ECPG accepts
> input from STDIN:
> 
> [singha7] (jgray) ~> psql --version
> psql (PostgreSQL) 9.6.3
> [singha7] (jgray) ~>
> 
> [singha7] (jgray) ~> ecpg -o - -
> /* Processed by ecpg (4.12.0) */
> /* These include files are added by the preprocessor */
> #include <ecpglib.h>
> #include <ecpgerrno.h>
> #include <sqlca.h>
> /* End of automatic include section */
> 
> #line 1 "stdin"
> ^C
> [singha7] (jgray) ~>
> 
> On a newer version (11.5) of Postgres on AIX 7.2, ECPG does NOT accept input
> from STDIN:
> 
> bash-5.0$ psql --version
> psql (PostgreSQL) 11.5
> bash-5.0$
> 
> bash-5.0$ ecpg -o - -
> Try "ecpg --help" for more information.
> bash-5.0$
> 
> 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.


-- 
  Bruce Momjian  <bruce@momjian.us>        https://momjian.us
  EnterpriseDB                             https://enterprisedb.com

+ As you are, so once was I.  As I am, so you will be. +
+                      Ancient Roman grave inscription +





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

* Re: BUG #16304: ECPG won't accept input from STDIN
  2020-03-16 20:48 BUG #16304: ECPG won't accept input from STDIN PG Bug reporting form <noreply@postgresql.org>
  2020-03-23 02:45 ` Re: BUG #16304: ECPG won't accept input from STDIN Bruce Momjian <bruce@momjian.us>
@ 2020-03-23 04:20   ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 3+ messages in thread

From: Tom Lane @ 2020-03-23 04:20 UTC (permalink / raw)
  To: Bruce Momjian <bruce@momjian.us>; +Cc: jim_gray@cox.net; pgsql-bugs@lists.postgresql.org

Bruce Momjian <bruce@momjian.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

Attachments:

fix-getopt-long-for-bare-dash.patch (text/x-diff, 697B) download diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index ff379db..c989276 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -79,14 +79,22 @@ getopt_long(int argc, char *const argv[], place++; - if (place[0] && place[0] == '-' && place[1] == '\0') - { /* found "--" */ + if (!*place) + { + /* treat "-" as not being an option */ + place = EMSG; + return -1; + } + + if (place[0] == '-' && place[1] == '\0') + { + /* found "--", treat it as end of options */ ++optind; place = EMSG; return -1; } - if (place[0] && place[0] == '-' && place[1]) + if (place[0] == '-' && place[1]) { /* long option */ size_t namelen;
^ permalink raw reply [nested|flat] 3+ messages in thread


end of thread, other threads:[~2020-03-23 04:20 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-03-16 20:48 BUG #16304: ECPG won't accept input from STDIN PG Bug reporting form <noreply@postgresql.org>
2020-03-23 02:45 ` Bruce Momjian <bruce@momjian.us>
2020-03-23 04:20   ` 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