pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #6212: PREPARE(pseudotype) should be blocked off
4+ messages / 3 participants
[nested] [flat]

* BUG #6212: PREPARE(pseudotype) should be blocked off
@ 2011-09-16 17:10 Caleb Welton <Caleb.Welton@emc.com>
  2011-09-16 18:11 ` Re: BUG #6212: PREPARE(pseudotype) should be blocked off Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 4+ messages in thread

From: Caleb Welton @ 2011-09-16 17:10 UTC (permalink / raw)
  To: pgsql-bugs


The following bug has been logged online:

Bug reference:      6212
Logged by:          Caleb Welton
Email address:      Caleb.Welton@emc.com
PostgreSQL version: 9.0
Operating system:   OSX
Description:        PREPARE(pseudotype) should be blocked off
Details: 

statements such as:
  PREPARE p1(anyelement) AS SELECT quote_literal($1);
  PREPARE p2(internal) AS SELECT int2recv($1);

Should not be allowed.

They can result in peculiar behavior such as the following:

execute p1('hello')
ERROR:  cannot display a value of type anyelement



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

* Re: BUG #6212: PREPARE(pseudotype) should be blocked off
  2011-09-16 17:10 BUG #6212: PREPARE(pseudotype) should be blocked off Caleb Welton <Caleb.Welton@emc.com>
@ 2011-09-16 18:11 ` Tom Lane <tgl@sss.pgh.pa.us>
  2011-09-16 19:35   ` Re: BUG #6212: PREPARE(pseudotype) should be blocked off Caleb.Welton@emc.com
  0 siblings, 1 reply; 4+ messages in thread

From: Tom Lane @ 2011-09-16 18:11 UTC (permalink / raw)
  To: Caleb Welton <Caleb.Welton@emc.com>; +Cc: pgsql-bugs

"Caleb Welton" <Caleb.Welton@emc.com> writes:
> statements such as:
>   PREPARE p1(anyelement) AS SELECT quote_literal($1);
>   PREPARE p2(internal) AS SELECT int2recv($1);
> Should not be allowed.

Hmm.  It would require an extra catalog lookup per parameter to enforce
that.  Not sure that it's worth it just to prevent "peculiar" errors.
Can you point to any worse consequences?

			regards, tom lane



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

* Re: BUG #6212: PREPARE(pseudotype) should be blocked off
  2011-09-16 17:10 BUG #6212: PREPARE(pseudotype) should be blocked off Caleb Welton <Caleb.Welton@emc.com>
  2011-09-16 18:11 ` Re: BUG #6212: PREPARE(pseudotype) should be blocked off Tom Lane <tgl@sss.pgh.pa.us>
@ 2011-09-16 19:35   ` Caleb.Welton@emc.com
  2011-09-16 20:48     ` Re: BUG #6212: PREPARE(pseudotype) should be blocked off Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 4+ messages in thread

From: Caleb.Welton@emc.com @ 2011-09-16 19:35 UTC (permalink / raw)
  To: tgl@sss.pgh.pa.us; +Cc: pgsql-bugs


On Sep 16, 2011, at 11:11 AM, Tom Lane wrote:

> "Caleb Welton" <Caleb.Welton@emc.com> writes:
>> statements such as:
>>  PREPARE p1(anyelement) AS SELECT quote_literal($1);
>>  PREPARE p2(internal) AS SELECT int2recv($1);
>> Should not be allowed.
> 
> Hmm.  It would require an extra catalog lookup per parameter to enforce
> that.  Not sure that it's worth it just to prevent "peculiar" errors.
> Can you point to any worse consequences?
> 
> 			regards, tom lane


I haven't found any more severe issues and I'll agree its not a high priority item.  But the fix is simple enough that I don't see a reason to ignore it either.

The easiest fix would be, as you say, adding one extra syscache lookup:

static Query *
transformPrepareStmt(ParseState *pstate, PrepareStmt *stmt)
{
...
		foreach(l, stmt->argtypes)
		{
			TypeName   *tn = lfirst(l);
			Oid			toid = typenameTypeId(pstate, tn);

	>		/* Pseudotypes are not valid parameters to PREPARE */
	>		if (get_typtype(toid) == TYPTYPE_PSEUDO)
	>		{
	>			ereport(ERROR,
	>					(errcode(ERRCODE_INDETERMINATE_DATATYPE),
	>					 errmsg("type \"%s\" is not a valid parameter for PREPARE",
	>							TypeNameToString(tn))));
	>		}

			argtoids[i++] = toid;
		}
...
}


If you really don't like the extra syscache lookup I'd offer two alternative implementations:

1) Creating a new macro IsPseudoType() like the existing IsPolymorphicType() macro given that we already have the oid.
2) TypenameGetTypid already has the whole cache tuple which contains both the pieces of information we want, but it only returns the oid... easy enough to fix, but larger api impact.

Regards,
  Caleb





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

* Re: BUG #6212: PREPARE(pseudotype) should be blocked off
  2011-09-16 17:10 BUG #6212: PREPARE(pseudotype) should be blocked off Caleb Welton <Caleb.Welton@emc.com>
  2011-09-16 18:11 ` Re: BUG #6212: PREPARE(pseudotype) should be blocked off Tom Lane <tgl@sss.pgh.pa.us>
  2011-09-16 19:35   ` Re: BUG #6212: PREPARE(pseudotype) should be blocked off Caleb.Welton@emc.com
@ 2011-09-16 20:48     ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 4+ messages in thread

From: Tom Lane @ 2011-09-16 20:48 UTC (permalink / raw)
  To: Caleb.Welton@emc.com; +Cc: pgsql-bugs

<Caleb.Welton@emc.com> writes:
> On Sep 16, 2011, at 11:11 AM, Tom Lane wrote:
>> Hmm.  It would require an extra catalog lookup per parameter to enforce
>> that.  Not sure that it's worth it just to prevent "peculiar" errors.
>> Can you point to any worse consequences?

> I haven't found any more severe issues and I'll agree its not a high priority item.  But the fix is simple enough that I don't see a reason to ignore it either.

> The easiest fix would be, as you say, adding one extra syscache lookup:

If it were just PREPARE I'd have done it without quibbling; that isn't
something I regard as a critical performance path.  But if we're trying
to lock this out then we logically have to enforce the same restriction
in exec_parse_message, and that *is* a performance-critical path.  Plus
it has no existing catalog lookup that might be kluged to pass back the
extra information.

Maybe we should do it anyway, but I'd really like to see a more
significant reason.

			regards, tom lane



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


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

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-09-16 17:10 BUG #6212: PREPARE(pseudotype) should be blocked off Caleb Welton <Caleb.Welton@emc.com>
2011-09-16 18:11 ` Tom Lane <tgl@sss.pgh.pa.us>
2011-09-16 19:35   ` Caleb.Welton@emc.com
2011-09-16 20: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