Thread: ecpg - GRANT bug

ecpg - GRANT bug

From
Lee Kindness
Date:
I've noticed general buggyness with ecpg on one of my source files for
a while now but it only got really annoying after setting up overnight
build on Linux (output corrupt code), Solaris (output correct code),
AIX (crashed) and HPUX (crashed).

After comparing the output from ecpg on Linux and Solaris the
following type of statement was the root of the crash:

 EXEC SQL GRANT ALL ON exampletable TO PUBLIC;

When the parser code was rebuilding the query to pass onto the server
it was trying to include an extra, non-existent, parameter...

The bug is present in 7.1.2, 7.1.3 and the current CVS sources. The
following patch (against CVS version) corrects this bug:

./interfaces/ecpg/preproc/preproc.y
*** ./interfaces/ecpg/preproc/preproc.y.orig    Fri Oct 12 16:22:05 2001
--- ./interfaces/ecpg/preproc/preproc.y    Fri Oct 12 16:22:09 2001
***************
*** 1693,1699 ****

  GrantStmt:  GRANT privileges ON opt_table relation_name_list TO grantee_list opt_with_grant
                  {
!                     $$ = cat_str(8, make_str("grant"), $2, make_str("on"), $4, $5, make_str("to"), $7);
                  }
          ;

--- 1693,1699 ----

  GrantStmt:  GRANT privileges ON opt_table relation_name_list TO grantee_list opt_with_grant
                  {
!                     $$ = cat_str(7, make_str("grant"), $2, make_str("on"), $4, $5, make_str("to"), $7);
                  }
          ;

Re: ecpg - GRANT bug

From
Bruce Momjian
Date:
Your patch has been added to the PostgreSQL unapplied patches list at:

    http://candle.pha.pa.us/cgi-bin/pgpatches

I will try to apply it within the next 48 hours.

---------------------------------------------------------------------------


> I've noticed general buggyness with ecpg on one of my source files for
> a while now but it only got really annoying after setting up overnight
> build on Linux (output corrupt code), Solaris (output correct code),
> AIX (crashed) and HPUX (crashed).
>
> After comparing the output from ecpg on Linux and Solaris the
> following type of statement was the root of the crash:
>
>  EXEC SQL GRANT ALL ON exampletable TO PUBLIC;
>
> When the parser code was rebuilding the query to pass onto the server
> it was trying to include an extra, non-existent, parameter...
>
> The bug is present in 7.1.2, 7.1.3 and the current CVS sources. The
> following patch (against CVS version) corrects this bug:
>
> ./interfaces/ecpg/preproc/preproc.y
> *** ./interfaces/ecpg/preproc/preproc.y.orig    Fri Oct 12 16:22:05 2001
> --- ./interfaces/ecpg/preproc/preproc.y    Fri Oct 12 16:22:09 2001
> ***************
> *** 1693,1699 ****
>
>   GrantStmt:  GRANT privileges ON opt_table relation_name_list TO grantee_list opt_with_grant
>                   {
> !                     $$ = cat_str(8, make_str("grant"), $2, make_str("on"), $4, $5, make_str("to"), $7);
>                   }
>           ;
>
> --- 1693,1699 ----
>
>   GrantStmt:  GRANT privileges ON opt_table relation_name_list TO grantee_list opt_with_grant
>                   {
> !                     $$ = cat_str(7, make_str("grant"), $2, make_str("on"), $4, $5, make_str("to"), $7);
>                   }
>           ;
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
>

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

Re: ecpg - GRANT bug

From
Tom Lane
Date:
Lee Kindness <lkindness@csl.co.uk> writes:
> ***************
> *** 1693,1699 ****

>   GrantStmt:  GRANT privileges ON opt_table relation_name_list TO grantee_list opt_with_grant
>                   {
> !                     $$ = cat_str(8, make_str("grant"), $2, make_str("on"), $4, $5, make_str("to"), $7);
>                   }
>           ;

> --- 1693,1699 ----

>   GrantStmt:  GRANT privileges ON opt_table relation_name_list TO grantee_list opt_with_grant
>                   {
> !                     $$ = cat_str(7, make_str("grant"), $2, make_str("on"), $4, $5, make_str("to"), $7);
>                   }
>           ;


Uh, isn't the correct fix

!                     $$ = cat_str(8, make_str("grant"), $2, make_str("on"), $4, $5, make_str("to"), $7, $8);

ISTM your patch loses the opt_with_grant clause.  (Of course the backend
doesn't currently accept that clause anyway, but that's no reason for
ecpg to drop it.)

            regards, tom lane

Re: ecpg - GRANT bug

From
Bruce Momjian
Date:
I saw that change from 8 to 7.  I think in the ecpg code that the first
parameter to cat_str is the number of arguments _after_ the first
parameter.

 preproc.c:{ yyval.str = cat_str(3, yyvsp[-2].str, make_str(","), yyvsp[0].str);

so I think the change from 8 -> 7 is correct.


---------------------------------------------------------------------------

> Lee Kindness <lkindness@csl.co.uk> writes:
> > ***************
> > *** 1693,1699 ****
>
> >   GrantStmt:  GRANT privileges ON opt_table relation_name_list TO grantee_list opt_with_grant
> >                   {
> > !                     $$ = cat_str(8, make_str("grant"), $2, make_str("on"), $4, $5, make_str("to"), $7);
> >                   }
> >           ;
>
> > --- 1693,1699 ----
>
> >   GrantStmt:  GRANT privileges ON opt_table relation_name_list TO grantee_list opt_with_grant
> >                   {
> > !                     $$ = cat_str(7, make_str("grant"), $2, make_str("on"), $4, $5, make_str("to"), $7);
> >                   }
> >           ;
>
>
> Uh, isn't the correct fix
>
> !                     $$ = cat_str(8, make_str("grant"), $2, make_str("on"), $4, $5, make_str("to"), $7, $8);
>
> ISTM your patch loses the opt_with_grant clause.  (Of course the backend
> doesn't currently accept that clause anyway, but that's no reason for
> ecpg to drop it.)
>
>             regards, tom lane
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
>

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

Re: ecpg - GRANT bug

From
Bruce Momjian
Date:
> On Mon, Oct 29, 2001 at 12:44:09PM -0500, Bruce Momjian wrote:
> > I saw that change from 8 to 7.  I think in the ecpg code that the first
> > parameter to cat_str is the number of arguments _after_ the first
> > parameter.
>
> It is indeed.
>
> > so I think the change from 8 -> 7 is correct.
>
> Not exactly. Yes, the cat_str has 7 arguments besides the number, but the
> rule suggests it should have 8.

Sorry, I am lost.  The rule above says to count the number of params
after the first one.  Doesn't that make it 7?

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

Re: ecpg - GRANT bug

From
Lee Kindness
Date:
All in all it doesn't really matter... Michael's already applied a
better fix! For some reason Tom's email has been lost in the system
for weeks!

Lee.

Bruce Momjian writes:
 > > On Mon, Oct 29, 2001 at 12:44:09PM -0500, Bruce Momjian wrote:
 > > > I saw that change from 8 to 7.  I think in the ecpg code that the first
 > > > parameter to cat_str is the number of arguments _after_ the first
 > > > parameter.
 > >
 > > It is indeed.
 > >
 > > > so I think the change from 8 -> 7 is correct.
 > >
 > > Not exactly. Yes, the cat_str has 7 arguments besides the number, but the
 > > rule suggests it should have 8.
 >
 > Sorry, I am lost.  The rule above says to count the number of params
 > after the first one.  Doesn't that make it 7?
 >
 > --
 >   Bruce Momjian                        |  http://candle.pha.pa.us
 >   pgman@candle.pha.pa.us               |  (610) 853-3000
 >   +  If your life is a hard drive,     |  830 Blythe Avenue
 >   +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
 >
 > ---------------------------(end of broadcast)---------------------------
 > TIP 5: Have you checked our extensive FAQ?
 >
 > http://www.postgresql.org/users-lounge/docs/faq.html

Re: ecpg - GRANT bug

From
Michael Meskes
Date:
On Mon, Oct 29, 2001 at 12:44:09PM -0500, Bruce Momjian wrote:
> I saw that change from 8 to 7.  I think in the ecpg code that the first
> parameter to cat_str is the number of arguments _after_ the first
> parameter.

It is indeed.

> so I think the change from 8 -> 7 is correct.

Not exactly. Yes, the cat_str has 7 arguments besides the number, but the
rule suggests it should have 8.

Michael
--
Michael Meskes
Michael@Fam-Meskes.De
Go SF 49ers! Go Rhein Fire!
Use Debian GNU/Linux! Use PostgreSQL!

Re: ecpg - GRANT bug

From
Michael Meskes
Date:
On Tue, Oct 30, 2001 at 01:50:09AM -0500, Bruce Momjian wrote:
> > Not exactly. Yes, the cat_str has 7 arguments besides the number, but the
> > rule suggests it should have 8.
>
> Sorry, I am lost.  The rule above says to count the number of params
> after the first one.  Doesn't that make it 7?

Sorry, I meant the bison rule that has 8 argumenents.

Michael
--
Michael Meskes
Michael@Fam-Meskes.De
Go SF 49ers! Go Rhein Fire!
Use Debian GNU/Linux! Use PostgreSQL!