Skip site navigation (1) Skip section navigation (2)

Re: BUG #6212: PREPARE(pseudotype) should be blocked off

From: <Caleb(dot)Welton(at)emc(dot)com>
To: <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #6212: PREPARE(pseudotype) should be blocked off
Date: 2011-09-16 19:35:05
Message-ID: DDC1B0A8-230C-4BB2-9402-BCF5F8D8940B@emc.com (view raw or flat)
Thread:
Lists: pgsql-bugs
On Sep 16, 2011, at 11:11 AM, Tom Lane wrote:

> "Caleb Welton" <Caleb(dot)Welton(at)emc(dot)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



In response to

Responses

pgsql-bugs by date

Next:From: Tom LaneDate: 2011-09-16 20:48:20
Subject: Re: BUG #6212: PREPARE(pseudotype) should be blocked off
Previous:From: Tom LaneDate: 2011-09-16 18:11:11
Subject: Re: BUG #6212: PREPARE(pseudotype) should be blocked off

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group