Commit 8acc568a authored by Tom Lane's avatar Tom Lane

CommentProc was careless about too many arguments.

parent 421d4f9b
...@@ -101,10 +101,11 @@ void CommentObject(int objtype, char *objname, char *objproperty, ...@@ -101,10 +101,11 @@ void CommentObject(int objtype, char *objname, char *objproperty,
CommentTrigger(objname, objproperty, comment); CommentTrigger(objname, objproperty, comment);
break; break;
default: default:
elog(ERROR, "An attempt was made to comment on a unkown type: %i", elog(ERROR, "An attempt was made to comment on a unknown type: %i",
objtype); objtype);
} }
} }
/*------------------------------------------------------------------ /*------------------------------------------------------------------
...@@ -586,8 +587,8 @@ void CommentAggregate(char *aggregate, char *argument, char *comment) { ...@@ -586,8 +587,8 @@ void CommentAggregate(char *aggregate, char *argument, char *comment) {
*------------------------------------------------------------------ *------------------------------------------------------------------
*/ */
void CommentProc(char *function, List *arguments, char *comment) { void CommentProc(char *function, List *arguments, char *comment)
{
HeapTuple argtuple, functuple; HeapTuple argtuple, functuple;
Oid oid, argoids[FUNC_MAX_ARGS]; Oid oid, argoids[FUNC_MAX_ARGS];
char *user, *argument; char *user, *argument;
...@@ -595,35 +596,38 @@ void CommentProc(char *function, List *arguments, char *comment) { ...@@ -595,35 +596,38 @@ void CommentProc(char *function, List *arguments, char *comment) {
/*** First, initialize function's argument list with their type oids ***/ /*** First, initialize function's argument list with their type oids ***/
argcount = length(arguments);
if (argcount > 0) {
MemSet(argoids, 0, FUNC_MAX_ARGS * sizeof(Oid)); MemSet(argoids, 0, FUNC_MAX_ARGS * sizeof(Oid));
argcount = length(arguments);
if (argcount > FUNC_MAX_ARGS)
elog(ERROR, "functions cannot have more than %d arguments",
FUNC_MAX_ARGS);
for (i = 0; i < argcount; i++) { for (i = 0; i < argcount; i++) {
argument = strVal(lfirst(arguments)); argument = strVal(lfirst(arguments));
arguments = lnext(arguments); arguments = lnext(arguments);
if (strcmp(argument, "opaque") == 0) { if (strcmp(argument, "opaque") == 0)
{
argoids[i] = 0; argoids[i] = 0;
} else { }
argtuple = SearchSysCacheTuple(TYPENAME, PointerGetDatum(argument), else
{
argtuple = SearchSysCacheTuple(TYPENAME,
PointerGetDatum(argument),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(argtuple)) { if (!HeapTupleIsValid(argtuple))
elog(ERROR, "function argument type '%s' does not exist", elog(ERROR, "function argument type '%s' does not exist",
argument); argument);
}
argoids[i] = argtuple->t_data->t_oid; argoids[i] = argtuple->t_data->t_oid;
} }
} }
}
/*** Now, validate the user's ability to comment on this function ***/ /*** Now, validate the user's ability to comment on this function ***/
#ifndef NO_SECURITY #ifndef NO_SECURITY
user = GetPgUserName(); user = GetPgUserName();
if (!pg_func_ownercheck(user, function, argcount, argoids)) { if (!pg_func_ownercheck(user, function, argcount, argoids))
elog(ERROR, "you are not permitted to comment on function '%s'", elog(ERROR, "you are not permitted to comment on function '%s'",
function); function);
} #endif
#endif
/*** Now, find the corresponding oid for this procedure ***/ /*** Now, find the corresponding oid for this procedure ***/
...@@ -631,19 +635,14 @@ void CommentProc(char *function, List *arguments, char *comment) { ...@@ -631,19 +635,14 @@ void CommentProc(char *function, List *arguments, char *comment) {
Int32GetDatum(argcount), Int32GetDatum(argcount),
PointerGetDatum(argoids), 0); PointerGetDatum(argoids), 0);
/*** Deallocate our argument oids and check the function tuple ***/ if (!HeapTupleIsValid(functuple))
if (!HeapTupleIsValid(functuple)) {
elog(ERROR, "function '%s' with the supplied %s does not exist", elog(ERROR, "function '%s' with the supplied %s does not exist",
function, "argument list"); function, "argument list");
}
oid = functuple->t_data->t_oid; oid = functuple->t_data->t_oid;
/*** Call CreateComments() to create/drop the comments ***/ /*** Call CreateComments() to create/drop the comments ***/
CreateComments(oid, comment); CreateComments(oid, comment);
} }
/*------------------------------------------------------------------ /*------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment