From 4543aec689fe0e2e13c592a63b9001ff60353982 Mon Sep 17 00:00:00 2001 From: Mike Palmiotto Date: Thu, 27 Sep 2018 14:26:29 -0400 Subject: [PATCH] Fix static analysis findings --- set_user.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/set_user.c b/set_user.c index 9cae094..f3e2134 100644 --- a/set_user.c +++ b/set_user.c @@ -289,7 +289,21 @@ set_user(PG_FUNCTION_ARGS) procTup = SearchSysCache1(PROCOID, ObjectIdGetDatum(funcOid)); if (!HeapTupleIsValid(procTup)) elog(ERROR, "cache lookup failed for function %u", funcOid); + procStruct = (Form_pg_proc) GETSTRUCT(procTup); + if (!procStruct) + { + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("set_user: function lookup failed for %u", funcOid))); + } + else if (!NameStr(procStruct->proname)) + { + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("set_user: NULL name for function %u", funcOid))); + } + funcname = pstrdup(NameStr(procStruct->proname)); ReleaseSysCache(procTup); @@ -321,7 +335,16 @@ set_user(PG_FUNCTION_ARGS) { /* use session lifetime memory */ oldcontext = MemoryContextSwitchTo(TopMemoryContext); - /* capture the reset token */ + + /* this should never be NULL but just in case */ + if (PG_ARGISNULL(1)) + { + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("set_user: NULL reset_token not valid"))); + } + + /*capture the reset token */ reset_token = text_to_cstring(PG_GETARG_TEXT_PP(1)); MemoryContextSwitchTo(oldcontext); }