From 8acc568a6bac6af04b9c898766e7d852103c7b72 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Wed, 12 Jan 2000 04:59:41 +0000 Subject: [PATCH] CommentProc was careless about too many arguments. --- src/backend/commands/comment.c | 101 ++++++++++++++++----------------- 1 file changed, 50 insertions(+), 51 deletions(-) diff --git a/src/backend/commands/comment.c b/src/backend/commands/comment.c index d560d78621..93feb9e805 100644 --- a/src/backend/commands/comment.c +++ b/src/backend/commands/comment.c @@ -101,10 +101,11 @@ void CommentObject(int objtype, char *objname, char *objproperty, CommentTrigger(objname, objproperty, comment); break; 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); } + } /*------------------------------------------------------------------ @@ -586,64 +587,62 @@ void CommentAggregate(char *aggregate, char *argument, 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; - - /*** First, initialize function's argument list with their type oids ***/ - - argcount = length(arguments); - if (argcount > 0) { - MemSet(argoids, 0, FUNC_MAX_ARGS * sizeof(Oid)); - for (i = 0; i < argcount; i++) { - argument = strVal(lfirst(arguments)); - arguments = lnext(arguments); - if (strcmp(argument, "opaque") == 0) { - argoids[i] = 0; - } else { - argtuple = SearchSysCacheTuple(TYPENAME, 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; - } +void CommentProc(char *function, List *arguments, char *comment) +{ + HeapTuple argtuple, functuple; + 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); + if (argcount > FUNC_MAX_ARGS) + elog(ERROR, "functions cannot have more than %d arguments", + FUNC_MAX_ARGS); + for (i = 0; i < argcount; i++) { + argument = strVal(lfirst(arguments)); + arguments = lnext(arguments); + if (strcmp(argument, "opaque") == 0) + { + argoids[i] = 0; + } + else + { + argtuple = SearchSysCacheTuple(TYPENAME, + 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), - Int32GetDatum(argcount), - PointerGetDatum(argoids), 0); + /*** Now, validate the user's ability to comment on this function ***/ - /*** 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)) { - elog(ERROR, "function '%s' with the supplied %s does not exist", - function, "argument list"); - } + /*** Now, find the corresponding oid for this procedure ***/ - 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); } /*------------------------------------------------------------------ -- 2.40.0