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,64 +587,62 @@ void CommentAggregate(char *aggregate, char *argument, char *comment) { ...@@ -586,64 +587,62 @@ 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;
int i, argcount; int i, argcount;
/*** First, initialize function's argument list with their type oids ***/ /*** First, initialize function's argument list with their type oids ***/
argcount = length(arguments); MemSet(argoids, 0, FUNC_MAX_ARGS * sizeof(Oid));
if (argcount > 0) { argcount = length(arguments);
MemSet(argoids, 0, FUNC_MAX_ARGS * sizeof(Oid)); if (argcount > FUNC_MAX_ARGS)
for (i = 0; i < argcount; i++) { elog(ERROR, "functions cannot have more than %d arguments",
argument = strVal(lfirst(arguments)); FUNC_MAX_ARGS);
arguments = lnext(arguments); for (i = 0; i < argcount; i++) {
if (strcmp(argument, "opaque") == 0) { argument = strVal(lfirst(arguments));
argoids[i] = 0; arguments = lnext(arguments);
} else { if (strcmp(argument, "opaque") == 0)
argtuple = SearchSysCacheTuple(TYPENAME, PointerGetDatum(argument), {
0, 0, 0); argoids[i] = 0;
if (!HeapTupleIsValid(argtuple)) { }
elog(ERROR, "function argument type '%s' does not exist", else
argument); {
} argtuple = SearchSysCacheTuple(TYPENAME,
argoids[i] = argtuple->t_data->t_oid; PointerGetDatum(argument),
} 0, 0, 0);
if (!HeapTupleIsValid(argtuple))
elog(ERROR, "function argument type '%s' does not exist",
argument);
argoids[i] = argtuple->t_data->t_oid;
}
} }
}
/*** Now, validate the user's ability to comment on this function ***/
#ifndef NO_SECURITY
user = GetPgUserName();
if (!pg_func_ownercheck(user, function, argcount, argoids)) {
elog(ERROR, "you are not permitted to comment on function '%s'",
function);
}
#endif
/*** Now, find the corresponding oid for this procedure ***/
functuple = SearchSysCacheTuple(PROCNAME, PointerGetDatum(function), /*** Now, validate the user's ability to comment on this function ***/
Int32GetDatum(argcount),
PointerGetDatum(argoids), 0);
/*** Deallocate our argument oids and check the function tuple ***/ #ifndef NO_SECURITY
user = GetPgUserName();
if (!pg_func_ownercheck(user, function, argcount, argoids))
elog(ERROR, "you are not permitted to comment on function '%s'",
function);
#endif
if (!HeapTupleIsValid(functuple)) { /*** Now, find the corresponding oid for this procedure ***/
elog(ERROR, "function '%s' with the supplied %s does not exist",
function, "argument list");
}
oid = functuple->t_data->t_oid; functuple = SearchSysCacheTuple(PROCNAME, PointerGetDatum(function),
Int32GetDatum(argcount),
PointerGetDatum(argoids), 0);
/*** Call CreateComments() to create/drop the comments ***/ if (!HeapTupleIsValid(functuple))
elog(ERROR, "function '%s' with the supplied %s does not exist",
function, "argument list");
oid = functuple->t_data->t_oid;
CreateComments(oid, comment); /*** Call CreateComments() to create/drop the comments ***/
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