1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-17 06:41:09 +03:00

CommentProc was careless about too many arguments.

This commit is contained in:
Tom Lane
2000-01-12 04:59:41 +00:00
parent 421d4f9bd7
commit 8acc568a6b

View File

@ -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) {
*------------------------------------------------------------------ *------------------------------------------------------------------
*/ */
void CommentProc(char *function, List *arguments, char *comment) { void CommentProc(char *function, List *arguments, char *comment)
{
HeapTuple argtuple, functuple;
Oid oid, argoids[FUNC_MAX_ARGS];
char *user, *argument;
int i, argcount;
HeapTuple argtuple, functuple; /*** First, initialize function's argument list with their type oids ***/
Oid oid, argoids[FUNC_MAX_ARGS];
char *user, *argument;
int i, argcount;
/*** First, initialize function's argument list with their type oids ***/ MemSet(argoids, 0, FUNC_MAX_ARGS * sizeof(Oid));
argcount = length(arguments);
argcount = length(arguments); if (argcount > FUNC_MAX_ARGS)
if (argcount > 0) { elog(ERROR, "functions cannot have more than %d arguments",
MemSet(argoids, 0, FUNC_MAX_ARGS * sizeof(Oid)); 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; {
} else { argoids[i] = 0;
argtuple = SearchSysCacheTuple(TYPENAME, PointerGetDatum(argument), }
0, 0, 0); else
if (!HeapTupleIsValid(argtuple)) { {
elog(ERROR, "function argument type '%s' does not exist", argtuple = SearchSysCacheTuple(TYPENAME,
argument); PointerGetDatum(argument),
} 0, 0, 0);
argoids[i] = argtuple->t_data->t_oid; 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 ***/ /*** 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 ***/
functuple = SearchSysCacheTuple(PROCNAME, PointerGetDatum(function), functuple = SearchSysCacheTuple(PROCNAME, PointerGetDatum(function),
Int32GetDatum(argcount), Int32GetDatum(argcount),
PointerGetDatum(argoids), 0); PointerGetDatum(argoids), 0);
/*** Deallocate our argument oids and check the function tuple ***/ if (!HeapTupleIsValid(functuple))
elog(ERROR, "function '%s' with the supplied %s does not exist",
function, "argument list");
oid = functuple->t_data->t_oid;
if (!HeapTupleIsValid(functuple)) { /*** Call CreateComments() to create/drop the comments ***/
elog(ERROR, "function '%s' with the supplied %s does not exist",
function, "argument list");
}
oid = functuple->t_data->t_oid;
/*** Call CreateComments() to create/drop the comments ***/
CreateComments(oid, comment);
CreateComments(oid, comment);
} }
/*------------------------------------------------------------------ /*------------------------------------------------------------------