protect pg_stat_statements_info() for being used without the library loaded

Started by Jaime Casanovaalmost 5 years ago5 messages
#1Jaime Casanova
jcasanov@systemguards.com.ec
1 attachment(s)

Hi,

Attached is a small patch for ${subject}

--
Jaime Casanova
Director de Servicios Profesionales
SystemGuards - Consultores de PostgreSQL

Attachments:

fix_pg_stat_statements_info.patchtext/x-patch; charset=US-ASCII; name=fix_pg_stat_statements_info.patchDownload
diff --git a/contrib/pg_stat_statements/pg_stat_statements.c b/contrib/pg_stat_statements/pg_stat_statements.c
index 72a117fc19..62cccbfa44 100644
--- a/contrib/pg_stat_statements/pg_stat_statements.c
+++ b/contrib/pg_stat_statements/pg_stat_statements.c
@@ -1898,6 +1898,11 @@ pg_stat_statements_info(PG_FUNCTION_ARGS)
 	Datum		values[PG_STAT_STATEMENTS_INFO_COLS];
 	bool		nulls[PG_STAT_STATEMENTS_INFO_COLS];
 
+	if (!pgss || !pgss_hash)
+		ereport(ERROR,
+				(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
+				 errmsg("pg_stat_statements must be loaded via shared_preload_libraries")));
+
 	/* Build a tuple descriptor for our result type */
 	if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
 		elog(ERROR, "return type must be a row type");
#2Julien Rouhaud
rjuju123@gmail.com
In reply to: Jaime Casanova (#1)
Re: protect pg_stat_statements_info() for being used without the library loaded

On Thu, Jan 28, 2021 at 3:53 AM Jaime Casanova
<jcasanov@systemguards.com.ec> wrote:

Hi,

Attached is a small patch for ${subject}

Good catch, and patch looks good to me.

#3Michael Paquier
michael@paquier.xyz
In reply to: Julien Rouhaud (#2)
Re: protect pg_stat_statements_info() for being used without the library loaded

On Thu, Jan 28, 2021 at 08:49:54AM +0800, Julien Rouhaud wrote:

Good catch, and patch looks good to me.

This crashes the server, cash. Looking at all the other modules in
the tree, I am not seeing any other hole. This is new as of 9fbc3f3,
and I will apply it on HEAD.
--
Michael

#4Fujii Masao
masao.fujii@oss.nttdata.com
In reply to: Michael Paquier (#3)
Re: protect pg_stat_statements_info() for being used without the library loaded

On 2021/01/28 15:42, Michael Paquier wrote:

On Thu, Jan 28, 2021 at 08:49:54AM +0800, Julien Rouhaud wrote:

Good catch, and patch looks good to me.

This crashes the server, cash. Looking at all the other modules in
the tree, I am not seeing any other hole. This is new as of 9fbc3f3,
and I will apply it on HEAD.

Thanks!

Regards,

--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION

#5Michael Paquier
michael@paquier.xyz
In reply to: Fujii Masao (#4)
Re: protect pg_stat_statements_info() for being used without the library loaded

On Thu, Jan 28, 2021 at 03:53:54PM +0900, Fujii Masao wrote:

Thanks!

No problem. Applied as of bca96dd.
--
Michael