From 12ac9f7e068ae6a762edff0e2c9706a6e8528986 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Mon, 15 Oct 2018 15:28:30 +0200 Subject: [PATCH v4 3/4] Fix pg_stat_ssl.clientdn Return null if there is no client certificate. This is how it has always been documented, but in reality it returned an empty string. --- src/backend/utils/adt/pgstatfuncs.c | 5 ++++- src/test/ssl/t/001_ssltests.pl | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c index 053bb73863..20ebcfbcdf 100644 --- a/src/backend/utils/adt/pgstatfuncs.c +++ b/src/backend/utils/adt/pgstatfuncs.c @@ -652,7 +652,10 @@ pg_stat_get_activity(PG_FUNCTION_ARGS) values[20] = CStringGetTextDatum(beentry->st_sslstatus->ssl_cipher); values[21] = Int32GetDatum(beentry->st_sslstatus->ssl_bits); values[22] = BoolGetDatum(beentry->st_sslstatus->ssl_compression); - values[23] = CStringGetTextDatum(beentry->st_sslstatus->ssl_clientdn); + if (beentry->st_sslstatus->ssl_clientdn[0]) + values[23] = CStringGetTextDatum(beentry->st_sslstatus->ssl_clientdn); + else + nulls[23] = true; } else { diff --git a/src/test/ssl/t/001_ssltests.pl b/src/test/ssl/t/001_ssltests.pl index 2bcbb1b42a..ff7a20307f 100644 --- a/src/test/ssl/t/001_ssltests.pl +++ b/src/test/ssl/t/001_ssltests.pl @@ -316,7 +316,7 @@ '-c', "SELECT * FROM pg_stat_ssl WHERE pid = pg_backend_pid()" ], qr{^pid,ssl,version,cipher,bits,compression,clientdn\n - ^\d+,t,TLSv[\d.]+,[\w-]+,\d+,f,$}mx, + ^\d+,t,TLSv[\d.]+,[\w-]+,\d+,f,_null_$}mx, 'pg_stat_ssl view without client certificate'); ### Server-side tests. -- 2.20.1