Re: Unprivileged user can induce crash by using an SUSET param in PGOPTIONS - Mailing list pgsql-hackers

From Dagfinn Ilmari Mannsåker
Subject Re: Unprivileged user can induce crash by using an SUSET param in PGOPTIONS
Date
Msg-id 87ilnli57b.fsf@wibble.ilmari.org
Whole thread Raw
In response to Re: Unprivileged user can induce crash by using an SUSET param in PGOPTIONS  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Unprivileged user can induce crash by using an SUSET param in PGOPTIONS
List pgsql-hackers
Tom Lane <tgl@sss.pgh.pa.us> writes:

> I wonder if it'd be a good idea to convert
> auto_explain's TAP test to load auto_explain via session_preload_libraries
> instead of shared_preload_libraries, and then pass in the settings for
> each test via PGOPTIONS instead of constantly rewriting postgresql.conf.

That whole config-file rewriting did feel a bit icky when I added more
tests recently, but I completely forgot about PGOPTIONS and -c.
Something like the attached is indeed much nicer.

- ilmari

From c9d6850e89ff95df1034c13ca9c10aaf1cf0f02f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= <ilmari@ilmari.org>
Date: Mon, 25 Jul 2022 16:23:09 +0100
Subject: [PATCH] Use PGOPTIONS and session_preload_libraries in auto_explain
 tests

Instead of constantly rewriting postgresql.conf.  Also change the from
shared_preload_libraries to session_preload_libraries to givesome
coverage of extensions providing custom GUCs.
---
 contrib/auto_explain/t/001_auto_explain.pl | 24 +++-------------------
 1 file changed, 3 insertions(+), 21 deletions(-)

diff --git a/contrib/auto_explain/t/001_auto_explain.pl b/contrib/auto_explain/t/001_auto_explain.pl
index 1d952fb54d..b86761919b 100644
--- a/contrib/auto_explain/t/001_auto_explain.pl
+++ b/contrib/auto_explain/t/001_auto_explain.pl
@@ -16,38 +16,20 @@ sub query_log
     my ($node, $sql, $params) = @_;
     $params ||= {};
 
-    if (keys %$params)
-    {
-        for my $key (keys %$params)
-        {
-            $node->append_conf('postgresql.conf', "$key = $params->{$key}\n");
-        }
-        $node->reload;
-    }
+    local $ENV{PGOPTIONS} = join " ", map { "-c $_=$params->{$_}" } keys %$params;
 
     my $log    = $node->logfile();
     my $offset = -s $log;
 
     $node->safe_psql("postgres", $sql);
 
-    my $log_contents = slurp_file($log, $offset);
-
-    if (keys %$params)
-    {
-        for my $key (keys %$params)
-        {
-            $node->adjust_conf('postgresql.conf', $key, undef);
-        }
-        $node->reload;
-    }
-
-    return $log_contents;
+    return slurp_file($log, $offset);
 }
 
 my $node = PostgreSQL::Test::Cluster->new('main');
 $node->init;
 $node->append_conf('postgresql.conf',
-    "shared_preload_libraries = 'auto_explain'");
+    "session_preload_libraries = 'auto_explain'");
 $node->append_conf('postgresql.conf', "auto_explain.log_min_duration = 0");
 $node->append_conf('postgresql.conf', "auto_explain.log_analyze = on");
 $node->start;
-- 
2.30.2


pgsql-hackers by date:

Previous
From: Thomas Munro
Date:
Subject: Re: fairywren hung in pg_basebackup tests
Next
From: Tom Lane
Date:
Subject: Re: fairywren hung in pg_basebackup tests